Skip to content

Commit f113891

Browse files
authored
Merge pull request #42 from attogram/refactor-prettier-workflows
Refactor Prettier Workflows
2 parents 1b87246 + ea5493d commit f113891

6 files changed

Lines changed: 26 additions & 30 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,5 @@ jobs:
1919
with:
2020
node-version: "20"
2121

22-
- name: Install Prettier
23-
run: npm install --global prettier
24-
25-
- name: Run Prettier
26-
run: prettier --check .
22+
- name: Check Formatting with Prettier
23+
run: npx prettier --check .

.github/workflows/prettier.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
# .github/workflows/prettier.yml
22

3-
name: Format Code with Prettier
3+
name: Manual Format with Prettier
44

5-
# This workflow is triggered on pushes to the `main` branch and on pull
6-
# requests.
5+
# This workflow is manually triggered from the Actions tab.
76
on:
8-
push:
9-
branches:
10-
- main
11-
pull_request:
7+
workflow_dispatch:
128

139
jobs:
1410
format:

docs/development.prettier.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@
22

33
# Prettier for Code Formatting
44

5-
[Prettier](https://prettier.io/) is an opinionated code formatter that enforces a consistent code style across the entire project. This repository is configured to use Prettier in two ways: automatically via a GitHub workflow and manually for local development.
5+
[Prettier](https://prettier.io/) is an opinionated code formatter that enforces a consistent code style across the entire project. This repository uses Prettier in two ways:
66

7-
## Automated Formatting with GitHub Actions
7+
- A **linting check** that runs automatically on pull requests to verify formatting.
8+
- A **manual workflow** that can be run to format the entire repository.
89

9-
This repository includes a [GitHub Actions workflow](./workflows.prettier.md) that automatically formats all code.
10+
## Linting with GitHub Actions
1011

11-
- **How it works**: The workflow runs on every push to the `main` branch and on every pull request. It runs `prettier --write .` to format all files and commits any changes with the message "style: Format code with Prettier".
12-
- **What you need to do**: Nothing! The workflow handles everything automatically. If you push code that isn't formatted, the workflow will create a new commit with the required formatting changes.
12+
This repository includes a [CI workflow](./workflows.ci.md) that automatically checks for formatting issues on every pull request.
1313

14-
This ensures that all code merged into the `main` branch is consistently formatted.
14+
- **How it works**: The workflow runs `prettier --check .`. If it finds any files that are not correctly formatted, the workflow will fail. This prevents code with incorrect formatting from being merged.
15+
- **What you need to do**: Make sure to run Prettier on your code before pushing it. If the check fails, you will need to format your code and push the changes.
16+
17+
## Manual Formatting Workflow
18+
19+
For convenience, this repository also includes a [manual formatting workflow](./workflows.prettier.md) that you can trigger from the Actions tab in GitHub.
20+
21+
- **How it works**: This workflow runs `prettier --write .` on all files and commits any changes back to your branch.
22+
- **When to use it**: You can use this if you forget to format your code locally, or if you want to format a large number of files at once.
1523

1624
## Manual Formatting
1725

@@ -39,6 +47,5 @@ You can run Prettier from the command line to format your files.
3947
```bash
4048
npx prettier . --check
4149
```
42-
The [CI workflow](./workflows.ci.md) uses this command to validate formatting on pull requests.
4350

4451
For more detailed information on using Prettier, refer to the [official Prettier documentation](https://prettier.io/docs/en/).

docs/workflows.ci.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ This job, named "Lint Code Base", runs on the latest version of Ubuntu. It perfo
1919

2020
1. **Checkout Code**: Checks out the repository's code.
2121
2. **Setup Node.js**: Sets up Node.js version 20.
22-
3. **Install Prettier**: Installs the Prettier code formatter globally.
23-
4. **Run Prettier**: Runs `prettier --check .` to verify that all files in the repository are formatted correctly according to the Prettier configuration.
22+
3. **Check Formatting with Prettier**: Runs `npx prettier --check .` to verify that all files in the repository are formatted correctly according to the Prettier configuration.
2423

2524
The purpose of this workflow is to ensure that all code pushed to the `main` branch or included in a pull request to `main` adheres to the project's coding style, as defined by Prettier. This helps maintain code consistency and quality.

docs/workflows.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Below is an overview of the available workflows. For more detailed information a
1010

1111
- [**CI Workflow**](./workflows.ci.md) (`ci.yml`) - Ensures code quality by running linting checks on every push and pull request to the `main` branch.
1212
- [**GitHub Pages Deployment**](./workflows.pages.md) (`pages.yml`) - Builds and deploys the repository's content as a GitHub Pages website.
13-
- [**Prettier Workflow**](./workflows.prettier.md) (`prettier.yml`) - Automatically formats the code in the repository using Prettier and commits the changes.
13+
- [**Manual Prettier Workflow**](./workflows.prettier.md) (`prettier.yml`) - Manually formats the code in the repository using Prettier and commits the changes.
1414
- [**Release on Tag**](./workflows.release-on-tag.md) (`release-on-tag.yml`) - Automates the creation of GitHub Releases when a new version tag is pushed.
1515
- [**Secrets Management**](./workflows.secrets-management.md) - Best practices for managing secrets in GitHub Actions.
1616
- [**Workflow Scheduling**](./workflows.scheduling.md) - Automating recurring tasks with cron.

docs/workflows.prettier.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
[base](../README.md) > [docs](./README.md) > [workflows](./workflows.md) > Prettier Workflow
1+
[base](../README.md) > [docs](./README.md) > [workflows](./workflows.md) > Manual Prettier Workflow
22

3-
# Prettier Workflow
3+
# Manual Prettier Workflow
44

5-
The Prettier workflow, defined in `.github/workflows/prettier.yml`, automates code formatting for the entire repository.
5+
The Manual Prettier workflow, defined in `.github/workflows/prettier.yml`, provides a way to format the entire repository on demand.
66

77
## Triggers
88

9-
This workflow is triggered on:
10-
11-
- `push` to the `main` branch
12-
- Any `pull_request`
9+
This workflow is triggered manually using the `workflow_dispatch` event. You can run it from the "Actions" tab in the GitHub repository.
1310

1411
## Jobs
1512

@@ -23,4 +20,4 @@ This job runs on `ubuntu-latest` and performs the following steps:
2320
4. **Run Prettier**: Executes `npx prettier --write .` to format all files in the repository in-place.
2421
5. **Commit Changes**: Uses the `stefanzweifel/git-auto-commit-action` to check if Prettier made any changes. If there are changes, it commits them back to the current branch with the commit message "style: Format code with Prettier". This action is configured to check all files.
2522

26-
The purpose of this workflow is to ensure that all code in the repository is consistently formatted according to the Prettier rules, without requiring developers to run Prettier manually before committing.
23+
The purpose of this workflow is to provide a convenient way for developers to format the entire repository without needing to run Prettier locally. It is especially useful for large-scale formatting changes or for ensuring consistency after pulling in changes from multiple sources.

0 commit comments

Comments
 (0)