Last active
October 27, 2022 06:55
-
-
Save mpdude/ca93a185bcbf56eb7e341632ad4f8263 to your computer and use it in GitHub Desktop.
GitHub Actions workflow to open PRs for php-cs-fixer changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Update this by running | |
# curl https://gist.githubusercontent.com/mpdude/ca93a185bcbf56eb7e341632ad4f8263/raw/fix-cs-php.yml > .github/workflows/fix-cs-php.yml | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
name: Coding Standards | |
jobs: | |
open-pr-for-cs-violations: | |
name: PHP-CS-Fixer | |
runs-on: ubuntu-18.04 | |
if: github.actor != 'dependabot[bot]' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.head_ref }} | |
- name: Run PHP-CS-Fixer | |
uses: docker://oskarstark/php-cs-fixer-ga:2.16.7 | |
- name: Create PR for CS fixups | |
uses: peter-evans/create-pull-request@9825ae65b1cb54b543b938503728b432a0176d29 | |
id: create-pull-request | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
title: Fix coding standards in ${{ github.ref }} | |
branch: php-cs-fixer/${{ github.ref }} | |
assignees: ${{ github.actor }} | |
labels: php-cs-fixer | |
body: Please merge these changes into the ${{ github.ref }} branch to fix coding standard violations. | |
commit-message: Apply php-cs-fixer changes as of ${{ github.sha }} | |
- name: Leave a notice in the discussion when fixing code in a Pull Request | |
uses: docker://mpdude/comment-on-pr:v1.2.0 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
if: steps.create-pull-request.outputs.pr_number # only if PR was created in the previous step | |
continue-on-error: true # continue on failure - necessary when the current branch does not have a pending PR | |
with: | |
msg: | | |
@${{ github.actor }} please apply the coding standard fixes from #${{ steps.create-pull-request.outputs.pr_number }} | |
- name: Fail the workflow when necessary CS fixes were detected | |
run: echo "Failing workflow run because CS violations were detected." && exit 1 | |
if: steps.create-pull-request.outputs.pr_number |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Drop the above file into
.github/workflows
; and of course, make sure you have.php_cs.dist
checked in and.php_cs.cache
in your.gitignore
.This action will then run
php-cs-fixer
for all pushed commits. If changes need to be made, a PR will be opened so you can review and merge them. If the offending commit was already part of a PR, a comment will also be left in the discussion of that PR.