Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

name: Format Code with Prettier

# This workflow is triggered manually from the Actions tab.
# This workflow is triggered on pushes to the `main` branch and on pull
# requests.
on:
workflow_dispatch:
push:
branches:
- main
pull_request:

jobs:
format:
Expand Down Expand Up @@ -42,7 +46,6 @@ jobs:
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "style: Format code with Prettier"
branch: ${{ github.ref }}
# The file_pattern is set to all files, ensuring any change made by
# Prettier is committed.
file_pattern: "**/*.*"
23 changes: 10 additions & 13 deletions docs/development.prettier-workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@ This repository includes a GitHub Actions workflow that automatically formats al
## Workflow Details

- **Workflow File:** [`.github/workflows/prettier.yml`](../.github/workflows/prettier.yml)
- **Trigger:** This workflow is **not** run automatically. It must be triggered manually.
- **Action:** When run, the workflow will:
1. Check out the code from the branch it was run on.
- **Trigger:** This workflow is triggered automatically on:
- Pushes to the `main` branch.
- Any pull request.
- **Action:** When triggered, the workflow will:
1. Check out the code from the relevant branch or pull request.
2. Install the necessary dependencies (`npm install`).
3. Run `npx prettier --write .` to format all files.
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`.
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`.

## How to Use
## How it Works

To run the formatting workflow:
The workflow runs automatically, so there are no manual steps required.

1. Navigate to the **Actions** tab of the repository on GitHub.
2. In the left sidebar, click on **"Format Code with Prettier"**.
3. Above the list of previous runs, you will see a message: "This workflow has a `workflow_dispatch` event trigger."
4. Click the **"Run workflow"** button.
5. Choose the branch you want to format and click the **"Run workflow"** button again.

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.
- **On the `main` branch:** When code is pushed to `main`, the workflow will run and commit any formatting changes directly to `main`.
- **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`.