-
Notifications
You must be signed in to change notification settings - Fork 86
73 lines (69 loc) · 2.55 KB
/
changelog-label.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
name: Check needs-changelog label freshness
on:
workflow_dispatch: {}
schedule:
- cron: '55 20 * * *'
jobs:
check_labels:
name: Check Labels
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Switch to Changelog ref
run: |
git fetch origin +refs/notes/changelog:refs/notes/changelog
git checkout refs/notes/changelog
- name: Check for unresolved changelog labels
# For all merged PRs with the `needs-changelog` label, check if a note exists on the merge commit.
# If it does, remove the label.
# If not, print a summary of all PRs that need a changelog entry.
env:
GH_TOKEN: ${{ github.token }}
run: |
summary=$(mktemp)
remove=$(mktemp)
trap 'rm -rf "$summary" "$remove"' EXIT
gh api graphql -f query='
{
repository(owner: "quay", name: "claircore") {
pullRequests(first: 100, labels: ["needs-changelog"], states: [MERGED]) {
nodes {
id
title
number
url
mergeCommit {
oid
}
}
}
}
}
' -q '.data.repository.pullRequests.nodes[]' |
jq --arg remove "$remove" --arg summary "$summary" \
'@sh "if test -f \(.mergeCommit.oid); then echo \(.id) >> \($remove); else echo \(@text "- [#\(.number)](\(.url)): \(.title)") >> \($summary); fi"' |
xargs -t -n1 -r sh -c
if test -s "$remove"; then
l=$(gh api graphql -f query='{repository(owner: "quay", name: "claircore") {label(name: "needs-changelog") {id}}}'|
jq -r '.data.repository.label.id')
cat "$remove" | while read id; do
gh api graphql -F "id=${id}" -F "l=${l}" -f query='
mutation rm($id: ID!, $l: ID!) {
removeLabelsFromLabelable(input: {
labelableId: $id,
labelIds: [$l],
}){clientMutationId}
}
'
done
fi
test -s "$summary" || exit 0
cat <<'.' >> "$GITHUB_STEP_SUMMARY"
### Changlog notes missing:
.
cat "$summary" >> "$GITHUB_STEP_SUMMARY"
cat <<'.' >> "$GITHUB_STEP_SUMMARY"
* * *
If the changelog message is on another commit, the label needs to be removed manually. 🫥
.