Skip to content

Commit 9746f88

Browse files
authored
Merge pull request #34 from attogram/prettier-workflow-updates
feat(github-actions): Automate Prettier workflow
2 parents 4381857 + 43e3223 commit 9746f88

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

.github/workflows/prettier.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
name: Format Code with Prettier
44

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

913
jobs:
1014
format:
@@ -42,7 +46,6 @@ jobs:
4246
uses: stefanzweifel/git-auto-commit-action@v5
4347
with:
4448
commit_message: "style: Format code with Prettier"
45-
branch: ${{ github.ref }}
4649
# The file_pattern is set to all files, ensuring any change made by
4750
# Prettier is committed.
4851
file_pattern: "**/*.*"

docs/development.prettier-workflow.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,18 @@ This repository includes a GitHub Actions workflow that automatically formats al
55
## Workflow Details
66

77
- **Workflow File:** [`.github/workflows/prettier.yml`](../.github/workflows/prettier.yml)
8-
- **Trigger:** This workflow is **not** run automatically. It must be triggered manually.
9-
- **Action:** When run, the workflow will:
10-
1. Check out the code from the branch it was run on.
8+
- **Trigger:** This workflow is triggered automatically on:
9+
- Pushes to the `main` branch.
10+
- Any pull request.
11+
- **Action:** When triggered, the workflow will:
12+
1. Check out the code from the relevant branch or pull request.
1113
2. Install the necessary dependencies (`npm install`).
1214
3. Run `npx prettier --write .` to format all files.
13-
4. If any files were changed by Prettier, the workflow will automatically commit the changes back to the same branch with the commit message `style: Format code with Prettier`.
15+
4. If any files were changed by Prettier, the workflow will automatically commit the changes back to the same branch (for pushes) or the pull request's head branch with the commit message `style: Format code with Prettier`.
1416

15-
## How to Use
17+
## How it Works
1618

17-
To run the formatting workflow:
19+
The workflow runs automatically, so there are no manual steps required.
1820

19-
1. Navigate to the **Actions** tab of the repository on GitHub.
20-
2. In the left sidebar, click on **"Format Code with Prettier"**.
21-
3. Above the list of previous runs, you will see a message: "This workflow has a `workflow_dispatch` event trigger."
22-
4. Click the **"Run workflow"** button.
23-
5. Choose the branch you want to format and click the **"Run workflow"** button again.
24-
25-
The workflow will then execute, and any formatting changes will be pushed to your chosen branch. This is useful for cleaning up a feature branch before creating a pull request.
21+
- **On the `main` branch:** When code is pushed to `main`, the workflow will run and commit any formatting changes directly to `main`.
22+
- **On Pull Requests:** When you open a pull request, the workflow will run on the code in your branch. If it finds any formatting issues, it will push a new commit to your branch with the fixes. This helps ensure that all code is properly formatted before it gets merged into `main`.

0 commit comments

Comments
 (0)