Repository navigation
64 lines (58 loc) · 2.39 KB
/
Copy pathrelease-notes.yml
File metadata and controls
64 lines (58 loc) · 2.39 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
name: Release notes from CHANGELOG
# When a release is PUBLISHED from the GitHub UI (which shows GitHub's default
# commit-diff notes), replace its body with that version's curated section from
# this repo's own CHANGELOG.md. The founder's UI flow is unchanged; this just
# guarantees the body is always the curated changelog, never the commit diff.
#
# Trigger is `published` ONLY. Our own `gh release edit` below emits a
# `release: edited` event, which we deliberately do NOT listen to — so no loop.
# Self-contained: the extractor is inline, so it needs nothing from the private
# repo's scripts/ (which are not all mirrored here).
on:
release:
types: [published]
# A repo editing its OWN releases uses the built-in GITHUB_TOKEN — no PAT/secret.
permissions:
contents: write
concurrency:
group: release-notes-${{ github.event.release.tag_name }}
cancel-in-progress: false
jobs:
set-notes:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Extract this version's CHANGELOG section
env:
TAG: ${{ github.event.release.tag_name }}
run: |
set -euo pipefail
VERSION="${TAG#v}"
python3 - "$VERSION" > release_notes.md <<'PY'
import re, sys, pathlib
version = sys.argv[1]
text = pathlib.Path("CHANGELOG.md").read_text(encoding="utf-8")
ver = re.escape(version)
m = re.search(
r"^## \[" + ver + r"\][^\n]*\n(.*?)(?=^## \[|^\[Unreleased\]:|\Z)",
text, re.S | re.M,
)
body = m.group(1).strip("\n") if m else ""
out, blocks = [], re.split(r"(?m)^(### .+)$", body)
it = iter(blocks[1:])
for header, content in zip(it, it):
if content.strip():
out.append(header.strip() + "\n" + content.strip("\n"))
result = "\n\n".join(out).strip()
if not result:
sys.stderr.write(f"No CHANGELOG section for {version}; leaving body unchanged.\n")
sys.exit(1)
sys.stdout.write(result)
PY
echo "Extracted $(wc -l < release_notes.md) lines for ${VERSION}."
- name: Overwrite the release body with the curated notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ github.event.release.tag_name }}
run: gh release edit "$TAG" --notes-file release_notes.md