Stefan Zweifel shares his GitHub Actions Workflows to run prettier
and php-cs-fixer
on his repos:
Over the past few weeks I’ve added a handful of workflows to my projects.
One workflow is really like, is to run
prettier
andphp-cs-fixer
to automatically format my code and commit the fixed files back to the repository.
Here’s the contents of the prettier
workflow for example (.github/workflows/format_prettier
):
name: Format (prettier)
on:
pull_request:
paths:
- '**.css'
- '**.js'
- '**.vue'
jobs:
prettier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install
run: yarn install
env:
CI: true
- name: Run prettier
run: yarn run prettier --write 'src/**/*.{css,js,vue}'
- uses: stefanzweifel/git-auto-commit-action@v2.1.0
with:
commit_message: Apply prettier changes
branch: ${{ github.head_ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Upon each PR the workflow spins up an ubuntu machine which:
- Checks out the code
- Installs the dependencies (given that
prettier
is listed as a dev dependency inpackage.json
) - Runs the linter on certain files, with autofix enabled
- Commits all changes made by the linter
The php-cs-fixer
works in a similar way.
Run prettier or php-cs-fixer with GitHub Actions →
🤩 There’s more cool things you can do with GitHub Actions. Automatically compressing (image) assets for example is a really neat workflow. You can even use GitHub Actions to schedule deploys of your site.
🤔 Looking to set up prettier
and/or php-cs-fixer
? Look no further.
Freek on Twitter