-
Notifications
You must be signed in to change notification settings - Fork 107
81 lines (68 loc) · 2.37 KB
/
check-generated-artifacts.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
name: Check Generated Artifacts
on:
pull_request:
types:
- opened
- reopened
- synchronize
jobs:
generated-artifacts:
name: Check Generated Artifacts
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: "${{ github.event.pull_request.head.sha }}"
persist-credentials: false
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Run the automatic generation
working-directory: ./
run: |
make generate
- name: Gather the differences
id: git-diff
run: |
# Ensure new files are also considered in the diff
git add --intent-to-add .
output=$(git diff | head -n 100)
exit_code=$([ "${output}" ] && echo 1 || echo 0)
# Required to correctly manage multi-line outputs
output="${output//'%'/'%25'}"
output="${output//$'\n'/'%0A'}"
output="${output//$'\r'/'%0D'}"
# Store the different as step output
echo "diff=${output}" >> $GITHUB_OUTPUT
# Trigger a failure in case the diff is not empty
exit ${exit_code}
- name: Log the error if the diff is not empty (in case the comment cannot be generated)
run: |
echo "The generated artifacts appear to be out-of-date."
echo
echo "Here it is an excerpt of the diff:"
echo "${{ steps.git-diff.outputs.diff }}"
if: failure()
- name: Issue a comment in case the diff is not empty
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.CI_TOKEN }}
issue-number: ${{ github.event.pull_request.number }}
body: |
The generated artifacts appear to be out-of-date.
Please, ensure you are using the correct version of the generators (eg. `controller-gen`) and re-run:
```
make generate
```
<details>
<summary>Here it is an excerpt of the diff:</summary>
```diff
${{ steps.git-diff.outputs.diff }}
```
</details>
reactions: confused
if: |
github.event_name != 'push' && failure() &&
github.event.pull_request.head.repo.full_name == github.repository