From ace0d79486e963aa252f9446770e414adc727d3f Mon Sep 17 00:00:00 2001 From: zhanghui Date: Wed, 5 Aug 2026 13:44:12 +0800 Subject: [PATCH] ci: draft the GitHub Release page from the CHANGELOG on tag (#389) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ci: draft the GitHub Release page from the CHANGELOG on tag release.yml only published to PyPI; creating the Release page was an undocumented manual step, and v1.2.2 shipped to PyPI without one. A second job, gated on a successful upload, now drafts the page: title "EverOS X.Y.Z", body lifted from the matching CHANGELOG section with the group headings demoted to h2, `--prerelease` for PEP 440 suffixed tags. It stays a draft because the lead summary that opens every EverOS release page is prose CI cannot write. The job runs separately from the publish job so that one keeps `contents: read` alongside its OIDC token. A stable tag with no CHANGELOG section fails the job rather than publishing an empty page; pre-releases fall back to a placeholder. Existing releases are detected through the list endpoint, since the by-tag endpoint cannot see drafts (cli/cli#3037) and a re-run would 422 — a stale draft is replaced, a published release left alone. Co-Authored-By: Claude Opus 5 (1M context) * ci: prefill the Upgrade section on the drafted release page Every EverOS release page since 1.1.3 closes with an Upgrade section — the pip line, any migration notes, and a compare link to the previous tag. The first draft dropped it, so a published page would have lost the one section readers act on. The pip line and the compare link are prefilled; the previous tag comes from `git tag --sort=-v:refname`, which needs the full tag list, hence fetch-depth: 0. Migration notes stay hand-written next to the lead summary, since only a human knows whether a release needs them. Co-Authored-By: Claude Opus 5 (1M context) * docs(release): warn that API publishing drops the tag Flipping `draft` through the API without `tag_name` rebinds the release to the `untagged-` placeholder and creates a git tag by that name against the default branch. Hit while publishing 1.2.2; the web UI button is unaffected. Co-Authored-By: Claude Opus 5 (1M context) --------- Co-authored-by: zhanghui Co-authored-by: Claude Opus 5 (1M context) --- .claude/skills/release/SKILL.md | 59 +++++++++++++- .github/workflows/release.yml | 135 +++++++++++++++++++++++++++++++- 2 files changed, 191 insertions(+), 3 deletions(-) diff --git a/.claude/skills/release/SKILL.md b/.claude/skills/release/SKILL.md index 2c39733..9022604 100644 --- a/.claude/skills/release/SKILL.md +++ b/.claude/skills/release/SKILL.md @@ -8,7 +8,12 @@ description: Cut a versioned release and publish everos to PyPI via the tag-trig Publish a new version of `everos` to PyPI. Publishing is automated: pushing a `vX.Y.Z` tag triggers [.github/workflows/release.yml](../../../.github/workflows/release.yml), which builds, smoke-tests, and uploads via PyPI **Trusted Publishing** (OIDC — -no stored token) behind the `release` environment's manual-approval gate. +no stored token) behind the `release` environment's manual-approval gate, then +drafts the GitHub Release page from the CHANGELOG. + +A release is not finished when PyPI accepts the upload: the GitHub Release page +is drafted, never auto-published, and someone has to write its lead summary and +click **Publish**. ## Preconditions @@ -29,10 +34,56 @@ no stored token) behind the `release` environment's manual-approval gate. 6. Approve → the release.yml run pauses on the `release` environment; a reviewer approves in the Actions run 7. Verify → https://pypi.org/project/everos/X.Y.Z/ +8. Publish the page → the run leaves a DRAFT GitHub Release titled + "EverOS X.Y.Z", body prefilled from the CHANGELOG section. Write the lead + summary at the top, then click Publish. ``` The tag must equal the `pyproject.toml` version — the workflow refuses to -publish on a mismatch. +publish on a mismatch. A stable tag with no matching `## [X.Y.Z]` CHANGELOG +section fails the release job for the same reason. + +## The release page + +Every page has the same shape: + +``` + prose — CI cannot write this +## Added / ## Changed / ## Fixed / ... from the CHANGELOG section, verbatim +## Upgrade pip line + compare link prefilled; migration notes by hand +``` + +Two parts are yours to write in the draft: + +- **The lead summary** — the two or three sentences above the first heading + saying what this release is for. +- **Migration notes in `## Upgrade`**, when the release has any: what happens on + the first startup after upgrading, which command recovers a bad state, which + pins moved. Skip when a plain `pip install --upgrade` is genuinely all there + is; do not invent filler. + +See [1.2.1](https://github.com/EverMind-AI/EverOS/releases/tag/v1.2.1) for the +shape of both. + +> While it is a draft, GitHub serves the release at +> `releases/tag/untagged-`, and that URL keeps serving a stale page after +> publication with no redirect. Never share it — a reader who opens it later +> concludes the release never went out. Link `releases/tag/vX.Y.Z` instead; the +> job prints both URLs in its step summary. + +Publish with the **Publish release** button in the web UI. Publishing through +the API by flipping `draft` alone drops the tag: GitHub rebinds the release to +the `untagged-` placeholder and creates a git tag by that name against the +default branch (observed on 1.2.2). Pass `tag_name` if you must do it from the +CLI: + +```bash +gh api -X PATCH "repos/EverMind-AI/EverOS/releases/" \ + -F draft=false -f tag_name=vX.Y.Z -f make_latest=true +``` + +Re-running the release job replaces its own draft and leaves an already-published +release untouched, so a re-run is always safe. ## Pre-releases @@ -40,6 +91,10 @@ PEP 440 pre-release tags publish too (PyPI accepts them; `pip install everos` ignores them unless `--pre`): `vX.Y.ZrcN`, `vX.Y.ZaN`, `vX.Y.ZbN`. Set the same suffix in `pyproject.toml` version before tagging. +Their release page is drafted as a **pre-release** and never becomes +`/releases/latest`. A pre-release does not need its own CHANGELOG section — the +draft falls back to a one-line placeholder body when there is none. + ## One-time setup (project owner, not doable from CI) 1. **PyPI trusted publisher** — PyPI → project `everos` → Settings → diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 798595e..f912f36 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,5 @@ -# Publishes to PyPI via Trusted Publishing (OIDC) — no stored token. +# Publishes to PyPI via Trusted Publishing (OIDC) — no stored token — and then +# drafts the matching GitHub Release page from CHANGELOG.md. # Fires on a version tag (vX.Y.Z, plus PEP 440 pre-releases vX.Y.ZrcN / aN / bN). # The `release` environment gates the upload behind manual approval; configure # required reviewers under Settings → Environments → release. @@ -54,3 +55,135 @@ jobs: - name: Publish to PyPI (Trusted Publishing) uses: pypa/gh-action-pypi-publish@release/v1 + + # The notes page is a separate job so the publish job above keeps + # `contents: read` next to its OIDC token. It runs only after PyPI accepted + # the upload — a release page for a version nobody can install is worse than + # no page. The release is left as a DRAFT: the CHANGELOG section gives the + # body, but the lead summary that opens every EverOS release page is written + # by a human, who then clicks Publish. + github-release: + name: draft the GitHub Release + needs: publish + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 # the whole tag list, to name the previous release + + - name: Build the notes from CHANGELOG.md + env: + TAG: ${{ github.ref_name }} + REPO: ${{ github.repository }} + run: | + python3 - <<'PY' + import os, pathlib, re, subprocess, sys + + tag = os.environ["TAG"] + version = tag[1:] + # vX.Y.Z is stable; anything with a PEP 440 suffix (rc1 / a1 / b1 / + # .dev1) is a pre-release and must never become /releases/latest. + prerelease = re.fullmatch(r"\d+\.\d+\.\d+", version) is None + + src = pathlib.Path("CHANGELOG.md").read_text(encoding="utf-8") + match = re.search( + # Stops at the next version heading, at the link-reference block + # that closes the file, or at EOF. + rf"^## \[{re.escape(version)}\][^\n]*\n(.*?)(?=^## \[|^\[[^\]]+\]: |\Z)", + src, + re.S | re.M, + ) + if match is None and not prerelease: + # A stable release with no CHANGELOG entry is a mistake in the + # release PR, not something to paper over with an empty page. + print(f"::error::CHANGELOG.md has no '## [{version}]' section") + sys.exit(1) + + if match is None: + body = f"Pre-release build of `{version}`. See CHANGELOG.md on the tag.\n" + else: + # Demote the Keep-a-Changelog `### Added` group headings to `##`, + # matching how every earlier EverOS release page is structured. + body = re.sub(r"^### ", "## ", match.group(1).strip(), flags=re.M) + "\n" + + # Every EverOS release page since 1.1.3 closes with an Upgrade + # section. Only its boilerplate is prefilled here — a release that + # needs migration notes gets them written into the draft by hand. + tags = subprocess.run( + ["git", "tag", "--list", "v*", "--sort=-v:refname"], + capture_output=True, text=True, check=True, + ).stdout.split() + previous = None + if tag in tags: + previous = next( + (t for t in tags[tags.index(tag) + 1:] if re.fullmatch(r"v\d+\.\d+\.\d+", t)), + None, + ) + + body += "\n## Upgrade\n\n```bash\npip install --upgrade everos # or: uv sync\n```\n" + if previous is not None: + compare = f"https://github.com/{os.environ['REPO']}/compare/{previous}...{tag}" + body += f"\n**Full changelog:** [{previous}...{tag}]({compare})\n" + + notes = pathlib.Path(os.environ["RUNNER_TEMP"]) / "notes.md" + notes.write_text(body, encoding="utf-8") + + with open(os.environ["GITHUB_ENV"], "a", encoding="utf-8") as env: + env.write(f"RELEASE_VERSION={version}\n") + env.write(f"RELEASE_NOTES={notes}\n") + env.write(f"RELEASE_PRERELEASE={'true' if prerelease else 'false'}\n") + PY + + - name: Create the draft release + env: + GH_TOKEN: ${{ github.token }} + TAG: ${{ github.ref_name }} + REPO: ${{ github.repository }} + run: | + # Find an existing release through the LIST endpoint: the by-tag + # endpoint is published-only, so the Actions token cannot see a draft + # through it (cli/cli#3037) and a re-run would 422 on create. Replace + # a stale draft (deleting a draft keeps the git tag); never touch a + # release someone already published. + rel="$(gh api "repos/$REPO/releases?per_page=100" \ + --jq "map(select(.tag_name == \"$TAG\"))[0] // {}")" + id="$(printf '%s' "$rel" | jq -r '.id // empty')" + draft="$(printf '%s' "$rel" | jq -r '.draft // false')" + + if [ -n "$id" ] && [ "$draft" != "true" ]; then + echo "Release $TAG is already published; leaving it alone." + echo "Release $TAG already published: https://github.com/$REPO/releases/tag/$TAG" \ + >> "$GITHUB_STEP_SUMMARY" + exit 0 + fi + if [ -n "$id" ]; then + gh api -X DELETE "repos/$REPO/releases/$id" + fi + + # Written as `if`, not `cond && assign`: the runner's shell is + # `bash -e`, where a false test at the head of an AND-OR list fails + # the whole step. + if [ "$RELEASE_PRERELEASE" = "true" ]; then + flags="--prerelease --latest=false" + else + flags="--latest" + fi + # $flags is deliberately unquoted — it carries two words. + draft_url="$(gh release create "$TAG" \ + --draft $flags \ + --title "EverOS $RELEASE_VERSION" \ + --notes-file "$RELEASE_NOTES")" + + # A draft lives at releases/tag/untagged- and keeps serving that + # stale page after publication, with no redirect to the real tag. Print + # both URLs so nobody shares the draft one by copying the address bar. + { + echo "### Release $TAG (draft)" + echo "" + echo "Write the lead summary in the draft, then click **Publish**." + echo "" + echo "- Draft (temporary, do not share): $draft_url" + echo "- Public URL once published: https://github.com/$REPO/releases/tag/$TAG" + } >> "$GITHUB_STEP_SUMMARY"