-
Notifications
You must be signed in to change notification settings - Fork 44
82 lines (70 loc) · 2.85 KB
/
changelog-verify.yml
File metadata and controls
82 lines (70 loc) · 2.85 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
name: Changelog verification
on:
pull_request:
branches: [master]
push:
branches: [master]
permissions:
contents: read
jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: Check for entry in changelog.d changes in the PR
run: |
set -x
# Set BASE_SHA and HEAD_SHA based on event type
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE_SHA=${{ github.event.pull_request.base.sha }}
HEAD_SHA=${{ github.event.pull_request.head.sha }}
# Use 3-dot syntax so we only see changes introduced by this PR
CHANGED_FILES=$(git diff --name-only "$BASE_SHA...$HEAD_SHA" -- changelog.d/ | grep -vE "^$" || true)
else
# For push events, compare with the previous commit
HEAD_SHA=${{ github.sha }}
BASE_SHA=$(git rev-parse HEAD~1)
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- changelog.d/ | grep -vE "^$" || true)
fi
echo "BASE_SHA: $BASE_SHA"
echo "HEAD_SHA: $HEAD_SHA"
echo "CHANGED_FILES:"
echo "$CHANGED_FILES"
# Check if commit is by zebot with wire-build update message
COMMIT_AUTHOR=$(git log --format="%an" -1 $HEAD_SHA)
COMMIT_MESSAGE=$(git log --format="%s" -1 $HEAD_SHA)
if [[ "$COMMIT_AUTHOR" == "Zebot" && "$COMMIT_MESSAGE" == "Update wire-build to version"* ]]; then
echo "Skipping changelog check for zebot wire-build update commit"
echo "Author: $COMMIT_AUTHOR"
echo "Message: $COMMIT_MESSAGE"
exit 0
fi
if [ -z "$CHANGED_FILES" ]; then
echo "No files changed in changelog.d/ for this ${GITHUB_EVENT_NAME:-event}."
echo "Every PR must add or modify at least one changelog.d/ entry."
exit 1
fi
PATTERN='^(Added|Changed|Deprecated|Removed|Fixed|Security): .+'
LINE_FOUND=false
for file in $CHANGED_FILES; do
while IFS= read -r line; do
if [[ -z "$line" ]]; then
continue
fi
if echo "$line" | grep -qE "$PATTERN"; then
LINE_FOUND=true
echo "Valid pattern found in file $file: '$line'"
else
echo "Invalid format in file $file: '$line'"
exit 1
fi
done < "$file"
done
if [ "$LINE_FOUND" = false ]; then
echo "No valid lines found in changelog.d/ files. Ensure there is a newline at the end of files."
echo "Please read more policies about changelog at https://keepachangelog.com/en/1.1.0"
exit 1
fi