-
Notifications
You must be signed in to change notification settings - Fork 231
184 lines (154 loc) · 6.3 KB
/
Copy pathcommit-format.yml
File metadata and controls
184 lines (154 loc) · 6.3 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
name: GNU Commit Format Checker
on:
pull_request:
branches:
- master
- gcc-patch-dev
merge_group:
jobs:
check-commit-changelogs:
runs-on: ubuntu-latest
name: check-changelogs
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Install Deps
run: |
sudo apt-get update;
sudo apt-get install -y \
python3 \
python3-git
- name: GCC check PR Commits
run: |
if ${{ github.event_name == 'pull_request' }}; then
python3 contrib/gcc-changelog/git_check_commit.py origin/${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.sha }}
fi
check-commit-prefixes:
runs-on: ubuntu-latest
name: check-gccrs-prefix
if: ${{ github.base_ref == 'gcc-patch-dev' }} # master commits don't need the gccrs prefix
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Check for `gccrs` prefix
run: |
retval=0
for commit in $(git rev-list origin/${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.sha }});
do
echo -n "Checking gccrs prefix for $commit: " >> results
if [[ $(git log -1 --format="%s" $commit) = gccrs:* ]]; then
echo "OK" >> results
else
retval=1
echo "KO" >> results
fi
done
exit $retval
check-commit-signoff:
runs-on: ubuntu-latest
name: check-commit-signoff
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Check for DCO Sign-Off line/possible FSF Copyright Assignment
run: |
retval=0;
rev_list="origin/${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.sha }}"
for commit in $(git rev-list --reverse "$rev_list"); do
echo -n "Checking for DCO Sign-Off for commit $commit... ";
if [[ $(git log "$commit" -1 --format="%B" | tail -n 2) = Signed-off-by:* ]]; then
echo "OK";
continue;
fi
author=$(git log -1 --format=%an "$commit");
if [[ "$(( $(git log --author="$author"|wc -l) - $(git log --author="$author" --grep='Signed-off-by'|wc -l )))" -ne 0 ]]; then
echo "OK"
echo "$author probably has FSF Copyright Assignment. Check manually that the lack of DCO Sign-Off is allowed."
else
echo "KO"
retval=1;
fi
done;
## check no Signed-off-by in the middle.
while read -r f; do
echo -n "$f : "
if awk 'BEGIN { in_footer = 0; error = 0;}
{ DEFAULT = 1; }
/^(Signed-off|Co-authored|Reviewed|Tested)-by/ { in_footer = 1; DEFAULT = 0;}
/^\s*$/ { DEFAULT = 0; }
DEFAULT { if (in_footer == 1) { printf $0 " appears after some Signed-off-by/Co-authored-by/Tested-by/Reviewed-by line "; error = 1; exit (1);} }';
then
echo OK
else
echo KO
retval=1
fi < <(git log "$f" -1 --format="%B")
done < <(git rev-list --reverse "$rev_list" )
exit $retval;
check-valid-email:
runs-on: ubuntu-latest
name: check-valid-email
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Check author's email looks correct
run: |
retval=0;
rev_list="origin/${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.sha }}"
for commit in $(git rev-list --reverse "$rev_list"); do
if M=$(git show -s "$commit" | grep "noreply.github.com"); then
echo "$commit: KO => an invalid email was found: $M" | tee -a $GITHUB_STEP_SUMMARY
retval=1
else
echo "$commit: email looks OK"
fi
done
if [ "$retval" -ne 0 ]; then
echo "Some invalid emails were found." | tee -a $GITHUB_STEP_SUMMARY
else
echo "All emails look OK" | tee $GITHUB_STEP_SUMMARY
fi
exit $retval;
check-issue-reference:
runs-on: ubuntu-latest
continue-on-error: true # We do not want to block merge if it is a legitimate GCC bugzilla reference.
name: check-issue-reference
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Check for issue number reference in commit messages
run: |
retval=0;
rev_list="origin/${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.sha }}"
for commit in $(git rev-list --reverse "$rev_list"); do
git log --format=%B -n 1 "$commit" > /tmp/commit_log
python -c 'import re,sys; p=re.compile(r"(?<!/)\b\w+#\d+|\B#\d+"); [print(l,end="") for l in sys.stdin if p.search(l)]' < /tmp/commit_log > /tmp/found
if [ -s /tmp/found ] ; then
echo "$commit: KO because it has one or more bad references" | tee -a $GITHUB_STEP_SUMMARY
tee -a $GITHUB_STEP_SUMMARY < /tmp/found
retval=1
else
echo "$commit: OK"
fi
done;
if [ "$retval" -ne 0 ]; then
echo "Some bad issue references were found (eg. #4242, Rust-GCC#7777)." | tee -a $GITHUB_STEP_SUMMARY
echo "You shall rewrite the faulty commit message with this format: Rust-GCC/gccrs#4242" | \
tee -a $GITHUB_STEP_SUMMARY
echo "You may ignore this CI step if it represents a valid GCC bugzilla or external repository reference instead." | \
tee -a $GITHUB_STEP_SUMMARY
else
echo "No unadorned (#1234) or incorrect (foo#1234) references found" | \
tee $GITHUB_STEP_SUMMARY
fi
exit $retval;