Skip to content

Commit 7f04222

Browse files
committed
add release drafter
1 parent 1afb7ea commit 7f04222

File tree

5 files changed

+224
-4
lines changed

5 files changed

+224
-4
lines changed

.github/release-drafter.yml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name-template: "v$RESOLVED_VERSION"
2+
tag-template: "v$RESOLVED_VERSION"
3+
categories:
4+
- title: ⚠️ Breaking Changes
5+
labels:
6+
- breaking-change
7+
- title: 🚀 Features
8+
labels:
9+
- enhancement
10+
- title: 💻 Fixed Vulnerabilities
11+
labels:
12+
- security
13+
- title: 🐞 Bug Fixes
14+
labels:
15+
- bug
16+
- title: 🧰 Maintenance
17+
collapse-after: 3
18+
labels:
19+
- chore
20+
- infrastructure
21+
- title: 🤖 Dependency Updates
22+
collapse-after: 3
23+
labels:
24+
- dependencies
25+
change-template: "- $TITLE (#$NUMBER) @$AUTHOR"
26+
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
27+
version-resolver:
28+
major:
29+
labels:
30+
- major
31+
minor:
32+
labels:
33+
- minor
34+
patch:
35+
labels:
36+
- patch
37+
default: patch
38+
autolabeler:
39+
# Pull requests scope.
40+
- label: enhancement
41+
title:
42+
- "/^feat:/i"
43+
- label: chore
44+
title:
45+
- "/^chore:/i"
46+
- label: infrastructure
47+
title:
48+
- "/^infra:/i"
49+
- label: security
50+
title:
51+
- "/^sec:/i"
52+
- label: bug
53+
title:
54+
- "/^fix:/i"
55+
- label: documentation
56+
title:
57+
- "/^doc:/i"
58+
- label: breaking-change
59+
body:
60+
- '/^## Breaking Changes/im'
61+
- label: release-notes
62+
body:
63+
- '/^## Release Notes/im'
64+
# Version labels.
65+
- label: minor
66+
title:
67+
- "/^feat:/i"
68+
- label: patch
69+
title:
70+
- "/^fix:/i"
71+
- "/^sec:/i"
72+
- "/^chore:/i"
73+
branch:
74+
- '/^renovate_/'
75+
# Languages detection.
76+
- label: go
77+
files:
78+
- '*.go'
79+
- 'go.mod'
80+
- 'go.sum'
81+
- label: python
82+
files:
83+
- '*.py'
84+
- label: javascript
85+
files:
86+
- '*.js'
87+
replacers:
88+
# Remove unlabeled or uncategorized PRs.
89+
- search: "/# What's Changed.*?\\n## /s"
90+
replace: "# What's Changed\n\n## "
91+
template: |
92+
# What's Changed
93+
94+
$CHANGES

.github/renovate.json5

-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
"rangeStrategy": "pin",
1717
"branchPrefix": "renovate_",
1818
"commitMessagePrefix": "chore:",
19-
// PR approval is required.
20-
// We're not using any bot to approve Renovate PRs, we're doing it ourselves.
21-
// This effectively works as a convenience that skips pressing merge button manually.
22-
"automerge": true,
2319
// This will run go mod tidy after each go.mod update.
2420
"postUpdateOptions": ["gomodTidy"],
2521
"packageRules": [

.github/scripts/release-notes.sh

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if [ "$#" -ne 1 ]; then
6+
echo "Provide a single argument with a version of the release draft to use." >&2
7+
echo "Usage: $0 <VERSION>"
8+
exit 1
9+
fi
10+
11+
VERSION="$1"
12+
13+
RELEASE_NOTES=$(gh release view "$VERSION" --json body --jq .body)
14+
15+
BREAKING_CHANGES_HEADER="Breaking Changes"
16+
RELEASE_NOTES_HEADER="Release Notes"
17+
18+
commit_message_re="-\s(.*)\s(\(#[0-9]+\)\s@.*)"
19+
rls_header_re="^##.*(Features|$BREAKING_CHANGES_HEADER|Bug Fixes|Fixed Vulnerabilities)"
20+
21+
extract_header() {
22+
local commit="$1"
23+
local header_name="$2"
24+
awk "
25+
/^\s?$/ {next}
26+
/## $header_name/ {rn=1}
27+
rn && !/^##/ {print};
28+
/##/ && !/## $header_name/ {rn=0}" <<<"$commit"
29+
}
30+
31+
indent() {
32+
while IFS= read -r line; do
33+
printf " %s\n" "${line%"${line##*[![:space:]]}"}"
34+
done <<<"$1"
35+
}
36+
37+
new_notes=""
38+
rls_header=""
39+
while IFS= read -r line; do
40+
new_notes+="$line\n"
41+
if [[ $line == \##* ]]; then
42+
if ! [[ $line =~ $rls_header_re ]]; then
43+
rls_header=""
44+
continue
45+
fi
46+
rls_header="${BASH_REMATCH[1]}"
47+
fi
48+
if [[ $rls_header == "" ]]; then
49+
continue
50+
fi
51+
if [[ $line != -* ]]; then
52+
continue
53+
fi
54+
if ! [[ $line =~ $commit_message_re ]]; then
55+
continue
56+
fi
57+
commit_msg="${BASH_REMATCH[1]}"
58+
commit_body=$(git log --grep "$commit_msg" -n1 --pretty="%b")
59+
60+
add_notes() {
61+
local notes="$1"
62+
if [[ $notes != "" ]]; then
63+
new_notes+=$(indent "> $notes")
64+
new_notes+="\n"
65+
fi
66+
}
67+
68+
rn=$(extract_header "$commit_body" "$RELEASE_NOTES_HEADER")
69+
bc=$(extract_header "$commit_body" "$BREAKING_CHANGES_HEADER")
70+
71+
case $rls_header in
72+
"$BREAKING_CHANGES_HEADER") add_notes "$bc" ;;
73+
*) add_notes "$rn" ;;
74+
esac
75+
76+
done <<<"$RELEASE_NOTES"
77+
78+
echo "Uploading release notes for $VERSION"
79+
# shellcheck disable=2059
80+
printf "$new_notes" | gh release edit "$VERSION" --verify-tag -F -

.github/workflows/pr-title.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
on:
2+
pull_request:
3+
types: [opened, reopened, edited]
4+
merge_group:
5+
name: pr-title
6+
jobs:
7+
pr-title-check:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: Slashgear/[email protected]
11+
with:
12+
regexp: "(feat|fix|sec|infra|test|chore|doc): .{5,}"
13+
helpMessage: "Example: 'feat: new pr title check BE-143' <- prefix, colon, space, PR title of at least 5 chars (with ticket number strongly suggested, but not mandatory)"

.github/workflows/release-drafter.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Release Drafter
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
# pull_request event is required only for autolabeler
8+
# 'edited' event is required to account for initial invalid PR names
9+
pull_request:
10+
types: [opened, reopened, synchronize, edited]
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
update_release_draft:
17+
permissions:
18+
# write permission is required to create a github release
19+
contents: write
20+
# write permission is required for autolabeler
21+
# otherwise, read permission is required at least
22+
pull-requests: write
23+
runs-on: ubuntu-latest
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.RELEASE_LABELER_TOKEN }}
26+
steps:
27+
- name: Checkout code
28+
uses: actions/checkout@v4
29+
with:
30+
ref: main
31+
fetch-depth: 0
32+
# Drafts your next Release notes as Pull Requests are merged into "main"
33+
- id: drafter
34+
uses: release-drafter/release-drafter@v5
35+
- name: Add release notes to the draft
36+
if: github.event_name == 'push'
37+
run: .github/scripts/release-notes.sh ${{ steps.drafter.outputs.tag_name }}

0 commit comments

Comments
 (0)