Skip to content

Commit dbb51d7

Browse files
authored
PR must fail when generated code is not committed (#1472)
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.
1 parent 64733ee commit dbb51d7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

.github/workflows/generate-code.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: Generate code and open pull request
22

33
on:
44
workflow_dispatch:
5+
pull_request:
56
push:
67
branches:
78
- master
@@ -30,7 +31,13 @@ jobs:
3031
diff=$(git --no-pager diff --name-only HEAD)
3132
echo "DIFF_IS_EMPTY=$([[ -z "$diff" ]] && echo 'true' || echo 'false')" >> $GITHUB_ENV
3233
echo "CURRENT_DATETIME=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
33-
- if: ${{ env.DIFF_IS_EMPTY != 'true' }}
34+
## Run if diff exists and pull request, and make CI status failure
35+
- if: ${{ github.event_name == 'pull_request' && env.DIFF_IS_EMPTY != 'true' }}
36+
run: |
37+
echo "There are changes in the generated codes. Please run 'generate-code.py' and commit the changes." >&2
38+
exit 1
39+
## Run if diff exists and event is not pull request, and make PR
40+
- if: ${{ github.event_name != 'pull_request' && env.DIFF_IS_EMPTY != 'true' }}
3441
run: |
3542
git config user.name github-actions
3643
git config user.email [email protected]

0 commit comments

Comments
 (0)