-
Notifications
You must be signed in to change notification settings - Fork 354
103 lines (88 loc) · 3.9 KB
/
template-check.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Test if the committed files match templates.
# This checks each commit sequentially, so each commit must be correct.
name: Template check
on:
pull_request
permissions:
contents: read
pull-requests: write
jobs:
infra-reload-check:
runs-on: ubuntu-22.04
name: Templates match results
steps:
- name: Clone Anaconda repository
uses: actions/checkout@v4
with:
# TODO: Are we able to remove ref, fetch-depth and Rebase task? Seems that the checkout
# without ref is doing the rebase for us.
# otherwise we are testing target branch instead of the PR branch (see pull_request_target trigger)
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Rebase to current
run: |
git config user.name github-actions
git config user.email [email protected]
git log --oneline -1 origin/${{ github.event.pull_request.base.ref }}
git rebase origin/${{ github.event.pull_request.base.ref }}
- name: Determine commits to check
id: get_commits
run: |
COMMITS=$(git rev-list origin/${{ github.event.pull_request.base.ref }}..HEAD | tac)
# rev-list provides one hash per line, starting at HEAD, adding backwards.
# Why `tac` - commits are listed from HEAD backwards, which is reversed order, and need
# re-applying in the correct order.
echo -e "Commits found:\n$COMMITS"
COMMITS_ONELINE=$(echo $COMMITS | tr '\n' ' ')
# GH actions truncates plain multiline variables to first line when passing as output/input,
# so make it one line on our end and save the trouble.
echo "commits=$COMMITS_ONELINE" >> $GITHUB_OUTPUT
- name: Check all commits
run: |
git checkout -b temp origin/${{ github.event.pull_request.base.ref }}
for COMMIT in ${{ steps.get_commits.outputs.commits }} ; do
echo "Checking $COMMIT"
git cherry-pick "$COMMIT"
make -f Makefile.am reload-infra
CHANGES=$(git status -s)
if [[ -n $CHANGES ]] ; then
echo "Templates out of sync after commit $COMMIT:"
git log -1 "$COMMIT"
git status
exit 1
fi
done
infra-template-master-match-check:
runs-on: ubuntu-22.04
name: Compare templates files with master branch
if: github.event.pull_request.base.ref != 'master'
steps:
- name: Clone Anaconda repository
uses: actions/checkout@v3
with:
# TODO: Are we able to remove ref, fetch-depth and Rebase task? Seems that the checkout
# without ref is doing the rebase for us.
# otherwise we are testing target branch instead of the PR branch (see pull_request_target trigger)
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Rebase to current
run: |
git config user.name github-actions
git config user.email [email protected]
git log --oneline -1 origin/${{ github.event.pull_request.base.ref }}
git rebase origin/${{ github.event.pull_request.base.ref }}
- name: Check if all changed template files are matching master branch
run: |
changed_template_files_in_pr=$(git diff --diff-filter=M --name-only origin/${{ github.event.pull_request.base.ref }} "*.j2")
if [ -z "$changed_template_files_in_pr" ]; then
echo "----- No template files changed -----"
exit 0
fi
changed_files=$(git diff --diff-filter=M --name-only origin/master "*.j2")
if [ -n "$changed_files" ]; then
# print for debugging
echo "----- Template files differ with master branch -----"
echo "$changed_files"
echo "-------------------------"
exit 1
fi