Skip to content

Commit 28c4960

Browse files
authored
chore: use github tooling to build release notes (#710)
* chore: use github tooling to build release notes Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com> * add revert message prefix to pr label list with null value Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com> --------- Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com>
1 parent 16dd0af commit 28c4960

3 files changed

Lines changed: 86 additions & 17 deletions

File tree

.github/release.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
changelog:
2+
exclude:
3+
labels:
4+
- duplicate
5+
- invalid
6+
- wontfix
7+
categories:
8+
- title: "New Features"
9+
labels:
10+
- enhancement
11+
- title: "Bug Fixes"
12+
labels:
13+
- bug
14+
- title: "Documentation"
15+
labels:
16+
- documentation
17+
- title: "Other Changes"
18+
labels:
19+
- "*"

.github/scripts/release.sh

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,30 @@ CHGLOG_FILE="${CHGLOG_FILE:-CHANGELOG.md}"
1313
uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version "${TARGET_VERSION}"
1414
UV_FROZEN=0 uv lock --upgrade-package mellea
1515

16-
# collect release notes
16+
# push changes
17+
git config --global user.name 'github-actions[bot]'
18+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
19+
20+
# Configure the remote with the token
21+
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
22+
23+
TARGET_TAG_NAME="v${TARGET_VERSION}"
24+
25+
# Commit and push version bump first so the tag has the right base
26+
git add pyproject.toml uv.lock
27+
COMMIT_MSG="chore: bump version to ${TARGET_VERSION} [skip ci]"
28+
git commit -m "${COMMIT_MSG}"
29+
git push origin main
30+
31+
# create GitHub release (incl. Git tag) with GitHub-native generated notes
32+
gh release create "${TARGET_TAG_NAME}" --generate-notes
33+
34+
# pull the generated notes back locally to update the changelog
1735
REL_NOTES=$(mktemp)
18-
uv run --no-sync semantic-release changelog --unreleased >> "${REL_NOTES}"
36+
gh release view "${TARGET_TAG_NAME}" --json body -q ".body" >> "${REL_NOTES}"
1937

2038
# update changelog
2139
TMP_CHGLOG=$(mktemp)
22-
TARGET_TAG_NAME="v${TARGET_VERSION}"
2340
RELEASE_URL="$(gh repo view --json url -q ".url")/releases/tag/${TARGET_TAG_NAME}"
2441
printf "## [${TARGET_TAG_NAME}](${RELEASE_URL}) - $(date -Idate)\n\n" >> "${TMP_CHGLOG}"
2542
cat "${REL_NOTES}" >> "${TMP_CHGLOG}"
@@ -28,17 +45,6 @@ if [ -f "${CHGLOG_FILE}" ]; then
2845
fi
2946
mv "${TMP_CHGLOG}" "${CHGLOG_FILE}"
3047

31-
# push changes
32-
git config --global user.name 'github-actions[bot]'
33-
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
34-
35-
# Configure the remote with the token
36-
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
37-
38-
git add pyproject.toml uv.lock "${CHGLOG_FILE}"
39-
COMMIT_MSG="chore: bump version to ${TARGET_VERSION} [skip ci]"
40-
git commit -m "${COMMIT_MSG}"
41-
git push origin main
42-
43-
# create GitHub release (incl. Git tag)
44-
gh release create "${TARGET_TAG_NAME}" -F "${REL_NOTES}"
48+
git add "${CHGLOG_FILE}"
49+
git commit -m "docs: update changelog for ${TARGET_TAG_NAME} [skip ci]"
50+
git push origin main

.github/workflows/pr-label.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: "Label PR by conventional commit prefix"
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, synchronize]
6+
7+
jobs:
8+
label:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
pull-requests: write
12+
steps:
13+
- name: Apply label based on PR title prefix
14+
uses: actions/github-script@v7
15+
with:
16+
script: |
17+
const title = context.payload.pull_request.title;
18+
const labelMap = {
19+
'feat': 'enhancement',
20+
'fix': 'bug',
21+
'docs': 'documentation',
22+
'test': 'testing',
23+
'perf': 'enhancement',
24+
'refactor': 'enhancement',
25+
'ci': 'integrations',
26+
'chore': null,
27+
'build': null,
28+
'style': null,
29+
'revert': null,
30+
};
31+
32+
const match = title.match(/^(\w+)[\(!\:]/);
33+
if (!match) return;
34+
35+
const prefix = match[1];
36+
const label = labelMap[prefix];
37+
if (!label) return;
38+
39+
await github.rest.issues.addLabels({
40+
owner: context.repo.owner,
41+
repo: context.repo.repo,
42+
issue_number: context.payload.pull_request.number,
43+
labels: [label],
44+
});

0 commit comments

Comments
 (0)