diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml index 4eb1dc3..730d50f 100644 --- a/.github/workflows/prettier.yml +++ b/.github/workflows/prettier.yml @@ -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: @@ -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: "**/*.*" diff --git a/docs/development.prettier-workflow.md b/docs/development.prettier-workflow.md index dcef195..cf85aec 100644 --- a/docs/development.prettier-workflow.md +++ b/docs/development.prettier-workflow.md @@ -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`.