forked from libbpf/bpftool
-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (71 loc) · 2.68 KB
/
lint-commits.yaml
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
name: lint-commits
on:
pull_request:
jobs:
checkCommits:
name: check commits
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # v2.4.0
with:
fetch-depth: 0
- name: Get list of commits
run: |
COMMITS_JSON=$(curl -L \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
${{ github.event.pull_request.commits_url }})
PR_FIRST=$(echo "${COMMITS_JSON}" | jq -r ".[0].sha")
PR_TIP=$(echo "${COMMITS_JSON}" | jq -r ".[-1].sha")
PR_BASE=$(git rev-parse "${PR_FIRST}^")
echo "PR_TIP=${PR_TIP}" >> "${GITHUB_ENV}"
echo "PR_BASE=${PR_BASE}" >> "${GITHUB_ENV}"
- name: Check commit prefixes
run: |
START_MARKER='sync: Update libbpf submodule'
END_MARKER='sync: Pull latest bpftool changes from kernel'
declare -a PREFIXES=(
"ci"
"mirror"
)
misformed=0
syncing=0
while read commit ; do
valid=1
sha="${commit%% *}"
object="${commit#* }"
case "${object}" in
"${START_MARKER}")
syncing=1
;;
"${END_MARKER}")
syncing=0
;;
*)
if [[ "${syncing}" == 0 ]]; then
valid=0
for prefix in "${PREFIXES[@]}"; do
if [[ "${object}" =~ ^"${prefix}: " ]]; then
valid=1
break
fi
done
fi
;;
esac
if [[ "${valid}" = 1 ]]; then
echo "::notice title=valid prefix::${sha} (\"${object}\") has a valid prefix"
else
echo "::error title=invalid prefix::${sha} (\"${object}\") does not have a valid prefix"
misformed=$((misformed+1))
fi
done < <(git log --format='%h %s' --reverse ${{ env.PR_BASE }}..${{ env.PR_TIP }})
echo "::notice ::Found ${misformed} invalid commit object(s)"
if [[ "${misformed}" != 0 ]]; then
echo "Please ensure all commits not part of kernel sync are prefixed with one of:"
echo " ${PREFIXES[@]/%/:}"
# Fail workflow
false
fi