-
Notifications
You must be signed in to change notification settings - Fork 2
76 lines (65 loc) · 2.33 KB
/
check-template-consistency.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
name: Check template consistency
description: Check template consistency
on:
workflow_call:
inputs:
generate-command:
description: 'Command for generating code from OpenAPI schema'
required: true
type: string
jobs:
check-template-consistency:
name: Check template consistency
runs-on: ubuntu-latest
outputs:
has_diff: ${{ steps.diff.outputs.has_diff }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate code
run: |
${{ inputs.generate-command }}
- name: Get diff
id: diff
run: |
local_diff=$(git diff --name-only HEAD)
if [[ -z "$local_diff" ]]; then
echo "has_diff=0" >> "$GITHUB_OUTPUT"
else
echo "diff<<EOF" >> "$GITHUB_OUTPUT"
echo "$local_diff" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
echo "has_diff=1" >> "$GITHUB_OUTPUT"
fi
- name: Print diff details
run: |
echo "${{ steps.diff.outputs.diff }}"
echo "${{ steps.diff.outputs.has_diff }}"
- name: Add comment
if: steps.diff.outputs.has_diff == '1'
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31
with:
header: 'template-consistency'
message: |
⚠️ Template files and generated files are not in-sync.
Following files do not match corresponding templates:
`${{ steps.diff.outputs.diff }}`
To fix this warning, make sure template files are up-to-date, and generate files by running the following command:
```bash
${{ inputs.generate-command }}
```
- name: Remove comment
if: steps.diff.outputs.has_diff != '1'
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31
with:
header: 'template-consistency'
delete: true
# We need to fail in a separate job, otherwise the comment from the previous job will be removed
fail-on-diff:
name: Fail on diff
runs-on: ubuntu-latest
needs: check-template-consistency
steps:
- name: Fail the job
if: ${{ needs.check-template-consistency.outputs.has_diff == '1' }}
run: exit 1