Skip to content

Commit 9f75ca5

Browse files
committed
Publish through release branch and promote to protected main by PR
1 parent 261e539 commit 9f75ca5

14 files changed

Lines changed: 801 additions & 286 deletions

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ name: CI
22

33
on:
44
pull_request:
5-
push:
6-
branches: [main, master]
7-
workflow_dispatch:
5+
branches: [release]
6+
types: [opened, synchronize, reopened, ready_for_review, edited]
87

98
permissions:
109
contents: read
@@ -34,6 +33,8 @@ jobs:
3433
cache: npm
3534
- name: Install dependencies
3635
run: npm ci
36+
- name: Verify release notes and manifests
37+
run: node scripts/release-pipeline.mjs verify-feature
3738
- name: Lint, typecheck, test, and build
3839
run: npm run check
3940
- name: Verify package installation

‎.github/workflows/promotion.yml‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Release promotion
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
types: [opened, synchronize, reopened, ready_for_review, edited]
7+
8+
permissions:
9+
contents: read
10+
11+
concurrency:
12+
group: promotion-${{ github.event.pull_request.number }}
13+
cancel-in-progress: true
14+
15+
jobs:
16+
ready:
17+
name: Release ready
18+
runs-on: ubuntu-latest
19+
timeout-minutes: 5
20+
steps:
21+
- name: Check out the proposed release head
22+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
23+
with:
24+
ref: ${{ github.event.pull_request.head.sha }}
25+
fetch-depth: 0
26+
persist-credentials: false
27+
- name: Set up Node.js
28+
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
29+
with:
30+
node-version: 22
31+
cache: npm
32+
- name: Install validation dependencies
33+
run: npm ci --ignore-scripts
34+
- name: Verify published version and README without building a package
35+
env:
36+
GH_TOKEN: ${{ github.token }}
37+
run: node scripts/release-pipeline.mjs verify-promotion

‎.github/workflows/release.yml‎

Lines changed: 24 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,51 @@
11
name: Release
22

33
on:
4+
pull_request:
5+
branches: [release]
6+
types: [closed]
47
push:
58
tags: ['v[0-9]*', '[0-9]*']
69

710
permissions:
811
contents: read
912

13+
# Automatic and manual releases share one publisher. Never cancel an active publication.
1014
concurrency:
11-
group: release-${{ github.ref }}
15+
group: release-publication
1216
cancel-in-progress: false
1317

1418
jobs:
15-
package:
16-
name: Build and verify release package
19+
release:
20+
name: Publish from release and open promotion PR
21+
if: github.event_name == 'push' || github.event.pull_request.merged == true
1722
runs-on: ubuntu-latest
18-
timeout-minutes: 15
19-
outputs:
20-
prerelease: ${{ steps.version.outputs.prerelease }}
21-
filename: ${{ steps.package.outputs.filename }}
23+
timeout-minutes: 25
24+
permissions:
25+
contents: write
26+
pull-requests: write
2227
steps:
23-
- name: Check out the tag
28+
- name: Check out release
2429
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2530
with:
26-
persist-credentials: false
31+
ref: release
32+
fetch-depth: 0
2733
- name: Set up Node.js
2834
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
2935
with:
3036
node-version: 22
3137
cache: npm
32-
- name: Install dependencies
33-
run: npm ci
34-
- name: Verify package version matches tag
35-
id: version
38+
- name: Install pipeline dependencies
39+
run: npm ci --ignore-scripts
40+
- name: Prepare version, publish package, and promote through a PR
3641
env:
37-
RELEASE_TAG: ${{ github.ref_name }}
38-
run: node scripts/release-version.mjs "$RELEASE_TAG"
39-
- name: Prepare notes for this version
40-
env:
41-
RELEASE_TAG: ${{ github.ref_name }}
42-
run: node scripts/release-notes.mjs "$RELEASE_TAG" "$RUNNER_TEMP/release/release-notes.md"
43-
- name: Lint, typecheck, test, and build
44-
run: npm run check
45-
- name: Pack and verify installation
46-
id: package
47-
run: npm run package:check -- "$RUNNER_TEMP/release"
48-
- name: Upload verified release files
42+
GH_TOKEN: ${{ github.token }}
43+
run: node scripts/release-pipeline.mjs
44+
- name: Preserve built release files for diagnostics
45+
if: always()
4946
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
5047
with:
5148
name: release-package
52-
path: |
53-
${{ runner.temp }}/release/*.tgz
54-
${{ runner.temp }}/release/*.sha256
55-
${{ runner.temp }}/release/release-notes.md
56-
if-no-files-found: error
49+
path: ${{ runner.temp }}/release/*
50+
if-no-files-found: ignore
5751
retention-days: 7
58-
59-
publish:
60-
name: Publish GitHub Release
61-
needs: package
62-
runs-on: ubuntu-latest
63-
timeout-minutes: 5
64-
permissions:
65-
contents: write
66-
steps:
67-
- name: Download verified release files
68-
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
69-
with:
70-
name: release-package
71-
path: release
72-
- name: Create release with package and checksum
73-
working-directory: release
74-
env:
75-
GH_TOKEN: ${{ github.token }}
76-
RELEASE_TAG: ${{ github.ref_name }}
77-
PRERELEASE: ${{ needs.package.outputs.prerelease }}
78-
PACKAGE_FILE: ${{ needs.package.outputs.filename }}
79-
run: |
80-
sha256sum --check "$PACKAGE_FILE.sha256"
81-
args=(--repo "$GITHUB_REPOSITORY" --verify-tag --title "$RELEASE_TAG" --notes-file release-notes.md)
82-
if [[ "$PRERELEASE" == "true" ]]; then
83-
args+=(--prerelease --latest=false)
84-
fi
85-
gh release create "$RELEASE_TAG" "$PACKAGE_FILE" "$PACKAGE_FILE.sha256" "${args[@]}"
86-
87-
update-readme:
88-
name: Update the stable package download
89-
needs: [package, publish]
90-
if: needs.package.outputs.prerelease == 'false'
91-
permissions:
92-
contents: write
93-
uses: ./.github/workflows/update-release-readme.yml

‎.github/workflows/update-release-readme.yml‎

Lines changed: 0 additions & 34 deletions
This file was deleted.

‎AGENTS.md‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
Use English for all user-facing prompts, UI labels, errors, generated bot messages, examples, and documentation. Do not hard-code a personal account in defaults.
44

5+
Never push commits directly to `main` or modify its files through GitHub APIs.
6+
All changes reach `main` by merging a PR from `release`. Feature PRs target
7+
`release`; version and post-publication README commits belong on `release`.
8+
59
## Project context
610

711
This repository implements issue-to-PR automation for OpenCode **2**: a scheduler,
@@ -24,6 +28,7 @@ steps, project setup, headless operation, and removal.
2428
| [docs/runtime.md](docs/runtime.md) | User-visible behavior while the bot runs: GitHub questions and permission replies, branch selection, media inputs, prompt loading, follow-up comments, session tabs, and routine management commands. | Use when changing issue conversations, session continuation, runtime tools, or TUI behavior. |
2529
| [docs/advanced.md](docs/advanced.md) | Separate scheduler/dispatcher setup, multiple repositories, custom RPC jobs, full options, timeouts, management and retry commands, persistence, reconciliation, locks, and known limits. | Use for low-level configuration, operational troubleshooting, recovery, or ownership/concurrency changes. |
2630
| [docs/installation.md](docs/installation.md) | Loader registration, config-directory precedence, prerequisites, source installation, project-local installation, upgrade conflicts, testing on another machine, and migration limits. | Use when working on packaging, installers, registration, upgrades, or deployment troubleshooting. |
31+
| [docs/releases.md](docs/releases.md) | Feature-to-release PR checks, automatic patch versions, manual npm version/tag releases, exact changelog notes, publication recovery, README commits on release, and promotion PRs into protected main. | Use for CI triggers, versioning, packaging, GitHub Release publication, branch permissions, or recovery after a failed release. |
2732

2833
For common investigations:
2934

@@ -38,11 +43,11 @@ For common investigations:
3843
- **Why is polling inactive or duplicated?** Read architecture ownership,
3944
workflow section 1, and installation registration details.
4045

41-
For release changes, read the README's **GitHub Actions and releases** section,
42-
`CHANGELOG.md`, and `.github/workflows/release.yml`. Every release tag must have
43-
an exact version section in the changelog. `scripts/release-notes.mjs` extracts
44-
that section; `scripts/update-release-readme.mjs` maintains the marked installation
45-
block on the default branch after stable publication. Keep its markers intact.
46+
For release changes, read `docs/releases.md`, `CHANGELOG.md`, and the workflows
47+
under `.github/workflows/`. `scripts/release-pipeline.mjs` handles automatic and
48+
manual releases, retry state, and promotion. `scripts/release-notes.mjs` extracts
49+
the exact tagged changelog section; `scripts/update-release-readme.mjs` renders
50+
the installation block without making remote writes. Keep its markers intact.
4651

4752
## From documentation to source
4853

‎CHANGELOG.md‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Changelog
22

33
Release descriptions come from the exact version section committed with the tag.
4-
Keep unreleased changes here, then move them into a `## MAJOR.MINOR.PATCH` section
5-
before creating the release tag. Prerelease headings include the full version,
6-
for example `## 0.7.0-beta.1`.
4+
Add feature changes under `Unreleased`; after a PR merges into `release`, automation
5+
moves them into the new patch version's section. For a manual release, prepare
6+
and commit the exact version section before creating its tag. Prerelease headings
7+
include the full version, for example `## 0.7.0-beta.1`.
78

89
## Unreleased
910

@@ -12,7 +13,18 @@ for example `## 0.7.0-beta.1`.
1213
- Generate release descriptions from the matching changelog section, so publishing
1314
a tag before its PR merges no longer produces notes about an earlier release.
1415
- Show the latest published stable package's versioned download URL in the README
15-
and update it automatically after successful stable releases.
16+
on `release` after successful publication, then promote it to `main` through a PR.
17+
18+
### Release process
19+
20+
- Run full CI when feature PRs target `release`, including new commits to open PRs.
21+
Ordinary feature pushes no longer run CI or build packages.
22+
- Publish an automatic patch after a PR merges into `release`, and support manual
23+
version tags on that branch without a second version bump.
24+
- Recover interrupted publication without moving tags or republishing completed
25+
packages. Commit README on `release` before opening or updating its PR to `main`.
26+
- Keep `main` changes behind PR merges and verify that promotion contains the
27+
published package's code and updated download links.
1628

1729
## 0.6.2
1830

‎README.md‎

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ A reboot-only task does not handle later `opencode2 service restart` calls.
131131
Wait for active bot work to finish, then:
132132

133133
1. Run the versioned command in [Install from a .tgz package](#install-from-a-tgz-package)
134-
using the **same prefix** as before. The README on the default branch links to
135-
the latest published stable package.
134+
using the **same prefix** as before. After publication, the README on `release`
135+
links to the new stable package; `main` receives that link through the promotion PR.
136136

137137
`postinstall` refreshes registration;
138138
project settings and queues are preserved. Do not run `init` again.
@@ -291,40 +291,41 @@ copy it to another machine and follow the `.tgz` instructions above.
291291

292292
## GitHub Actions and releases
293293

294-
- **Pull requests:** CI runs ESLint, type checking, unit tests, a build, and a
295-
package installation check on Node 22 and 24. Pushes to `main`/`master` also run CI.
296-
- **Releases:** push a SemVer tag to build and publish a GitHub Release with the
297-
`.tgz` and SHA-256 checksum. CI verifies that the tag matches the committed
298-
version in `package.json` and `package-lock.json`. Tests and package installation must pass.
299-
Release notes come from the exact version section in [CHANGELOG.md](CHANGELOG.md)
300-
at that tag, independently of PR merge timing. Missing, duplicate, or empty
301-
version sections stop the release before publication.
302-
303-
For a stable release, prepare a changelog section such as `## 0.6.3` with the
304-
changes for that version, merge the PR, then update your local `main` branch.
305-
With a clean working tree, run (replace `0.6.3` with your next unused version,
306-
matching the changelog heading):
294+
1. Work on a feature branch and add release notes under `Unreleased` in
295+
[CHANGELOG.md](CHANGELOG.md). Ordinary branch pushes do not run CI or publish packages.
296+
2. Open a PR into the long-lived `release` branch. CI runs lint, type checking,
297+
tests, a build, and an installation check on Node 22 and 24. New commits to
298+
the open PR rerun these checks. Review and merge after they pass.
299+
3. The merge starts **Release**. It increments the patch version on `release`,
300+
moves the unreleased notes into that version's changelog section, and pushes
301+
the version commit and tag atomically. It builds and verifies the tagged
302+
package, then publishes the GitHub Release with `.tgz`, SHA-256, and exact
303+
version notes. No package is published to npm.
304+
4. Only after publication succeeds, automation commits the versioned README link
305+
on `release` and opens or updates a PR from `release` into `main`.
306+
5. Review and merge that PR with a **merge commit**. All code, version metadata,
307+
release notes, and README changes reach protected `main` through this PR.
308+
The automation never pushes to `main` or writes its files through the API.
309+
310+
To choose a version manually, prepare and commit its exact changelog section on
311+
`release`, then use `npm version`, for example:
307312

308313
```bash
309-
npm version 0.6.3
310-
git push --atomic origin HEAD v0.6.3
314+
git switch release
315+
git pull --ff-only origin release
316+
# Prepare and commit the CHANGELOG.md section for 1.0.0 first.
317+
npm version 1.0.0
318+
git push --atomic origin release v1.0.0
311319
```
312320

313-
`npm version` updates both manifests, creates a commit, and tags it automatically.
314-
The push sends the current branch and tag together. For testing, use a version
315-
such as `0.7.0-beta.1` on a feature branch; CI marks it as a prerelease.
316-
CI does not rewrite versions or publish to npm. Releases use the built-in
317-
`GITHUB_TOKEN`; no npm token or extra secret is needed.
318-
319-
After successful stable publication, the **Update release download in README**
320-
workflow reads GitHub's latest stable release and checks that its archive and
321-
checksum are uploaded. It commits the versioned installation block to the current
322-
default branch. Prereleases do not trigger this update. A tag's README and the
323-
README inside an existing archive remain snapshots from their build.
324-
325-
The updater needs `contents: write` and branch rules that permit its README commit.
326-
It preserves content outside the marked block and retries conflicting edits using
327-
the current file. If this step fails, the release remains published; resolve the
328-
reported permission or content problem, then run **Update release download in README**
329-
manually from Actions. The rerun selects the latest stable release again and does
330-
nothing if the README is already current. Do not rerun publication to repair a link.
321+
The pushed tag publishes exactly `1.0.0`, without another version bump. Both
322+
`v1.0.0` and `1.0.0` tag names are accepted. The next automatic patch is `1.0.1`.
323+
Version tags must point to code on `release`; ordinary pushes to that branch
324+
never start publication. Finish the active release before merging another feature.
325+
326+
The README on `release` is updated after publication; the README on `main` changes
327+
when the promotion PR is merged. The tag and packaged README remain snapshots
328+
from before the later README commit.
329+
330+
See [Release process](docs/releases.md) for required repository permissions,
331+
branch protection, CI approval for bot PRs, concurrency, and safe retry procedures.

‎docs/installation.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ project configuration, headless startup, and removal. This page covers details
55
and troubleshooting.
66

77
The README's package installation command contains the versioned GitHub asset URL
8-
for the latest published stable release. Its default-branch copy is updated after
9-
successful stable publication; prereleases do not replace that link. For upgrades,
10-
use the current default-branch README rather than a copy from an older archive or
11-
tag, and keep the same installation prefix. Maintainer setup and retry instructions
12-
are in [GitHub Actions and releases](../README.md#github-actions-and-releases).
8+
for the stable release promoted into that branch. After publication, automation
9+
updates README on `release`; its PR carries the update into `main` when merged.
10+
While that PR awaits review, `release` contains the newer download link. For
11+
upgrades, use that branch's current README rather than a copy from an old archive
12+
or tag, and keep the same installation prefix. Prereleases do not replace the
13+
stable link. Maintainer setup and retries are in [Release process](releases.md).
1314

1415
## Package registration
1516

0 commit comments

Comments
 (0)