Skip to content

Commit 47a8ef3

Browse files
authored
feat(github): detect mutations in build workflow (#34)
1 parent 833ad85 commit 47a8ef3

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
actions: read
2626
contents: read
2727
runs-on: ubuntu-latest
28+
outputs:
29+
self_mutation_happened: ${{ steps.self_mutation.outputs.self_mutation_happened }}
2830
steps:
2931
- name: Checkout
3032
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -38,3 +40,26 @@ jobs:
3840

3941
- name: Build
4042
run: mise run build
43+
44+
- name: Find mutations
45+
id: self_mutation
46+
run: |-
47+
git add .
48+
git diff --staged --patch --exit-code > repo.patch || echo "self_mutation_happened=true" >> $GITHUB_OUTPUT
49+
shell: bash
50+
working-directory: ./
51+
52+
- name: Upload patch
53+
if: steps.self_mutation.outputs.self_mutation_happened
54+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.4.0
55+
with:
56+
name: repo.patch
57+
path: repo.patch
58+
overwrite: true
59+
60+
- name: Fail build on mutation
61+
if: steps.self_mutation.outputs.self_mutation_happened
62+
run: |-
63+
echo "::error::Files were changed during build (see build log). Please run the build locally and commit the changes."
64+
cat repo.patch
65+
exit 1

0 commit comments

Comments
 (0)