Skip to content

Commit

Permalink
PR must fail when generated code is not committed (#704)
Browse files Browse the repository at this point in the history
When some code are changed by modifying code generator or templates,
forgetting to commit the expected changes can lead to mistakes. I want
to enforce that the PR author commits the generated code, by causing the
CI to fail if the generated code is not committed. This PR achieves
that.
  • Loading branch information
Yang-33 authored Nov 7, 2024
1 parent cd97fa7 commit 6387cb7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion .github/workflows/generated-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Generate code and open pull request

on:
workflow_dispatch:
pull_request:
push:
branches:
- master
Expand All @@ -27,7 +28,13 @@ jobs:
diff=$(git --no-pager diff --name-only HEAD)
echo "DIFF_IS_EMPTY=$([[ -z "$diff" ]] && echo 'true' || echo 'false')" >> $GITHUB_ENV
echo "CURRENT_DATETIME=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
- if: ${{ env.DIFF_IS_EMPTY != 'true' }}
## Run if diff exists and pull request, and make CI status failure
- if: ${{ github.event_name == 'pull_request' && env.DIFF_IS_EMPTY != 'true' }}
run: |
echo "There are changes in the generated codes. Please run 'generate-code.py' and commit the changes." >&2
exit 1
## Run if diff exists and event is not pull request, and make PR
- if: ${{ github.event_name != 'pull_request' && env.DIFF_IS_EMPTY != 'true' }}
run: |
git config user.name github-actions
git config user.email github-actions@github.com
Expand Down

0 comments on commit 6387cb7

Please sign in to comment.