Skip to content

Commit 6a9daa4

Browse files
committed
ci: seed changelog entry on regen version bump
1 parent c8ad74a commit 6a9daa4

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

.github/workflows/regenerate.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,39 @@ jobs:
7575
| jq -r '.packages[] | select(.name=="hotdata") | .version')
7676
echo "version=$version" >> "$GITHUB_OUTPUT"
7777
78+
# check-release.yml gates merges on a `## [x.y.z]` CHANGELOG section
79+
# matching the bumped version, so without a seeded entry every regen PR
80+
# fails that check. Insert a stub (the spec-change title under ### Changed)
81+
# right after `## [Unreleased]`; the PR author refines the wording before
82+
# merge. Idempotent: skips if a section for this version already exists.
83+
- name: Seed changelog entry
84+
env:
85+
VERSION: ${{ steps.pkg.outputs.version }}
86+
TITLE: ${{ inputs.title }}
87+
run: |
88+
export CHANGELOG_DATE=$(date -u +%Y-%m-%d)
89+
python3 - <<'PY'
90+
import os, pathlib, re
91+
version = os.environ["VERSION"]
92+
date = os.environ["CHANGELOG_DATE"]
93+
title = (os.environ.get("TITLE") or "").strip() \
94+
or "Regenerate the client from the updated Hotdata OpenAPI spec"
95+
path = pathlib.Path("CHANGELOG.md")
96+
text = path.read_text()
97+
if re.search(rf"^## \[{re.escape(version)}\]", text, re.M):
98+
print(f"CHANGELOG already has a [{version}] section; leaving it untouched.")
99+
raise SystemExit(0)
100+
marker = "## [Unreleased]\n"
101+
idx = text.find(marker)
102+
if idx == -1:
103+
raise SystemExit("CHANGELOG.md has no '## [Unreleased]' section to anchor the new entry")
104+
insert_at = idx + len(marker)
105+
entry = f"## [{version}] - {date}\n\n### Changed\n\n- {title}\n"
106+
text = text[:insert_at] + "\n" + entry + "\n" + text[insert_at:].lstrip("\n")
107+
path.write_text(text)
108+
print(f"Inserted CHANGELOG [{version}] section.")
109+
PY
110+
78111
- name: Generate client
79112
env:
80113
PACKAGE_VERSION: ${{ steps.pkg.outputs.version }}

0 commit comments

Comments
 (0)