Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 17 additions & 21 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
name: publish
run-name: "${{ inputs.dry_run && 'dry-run ' || '' }}release ${{ inputs.version || inputs.bump }}"
run-name: "${{ inputs.dry_run && 'dry-run ' || '' }}release"

on:
workflow_dispatch:
inputs:
bump:
description: "auto = derive from conventional commits since last tag"
type: choice
default: auto
options: [auto, patch, minor, major]
version:
description: "Override version, e.g. 0.2.0 (required for the first release)"
required: false
type: string
dry_run:
description: "Compute version + notes only; create nothing"
type: boolean
Expand Down Expand Up @@ -43,11 +34,11 @@ jobs:
with:
fetch-depth: 0
- uses: ./.github/actions/setup-bun
- name: Check package metadata

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Version job restricted to main repo only (nearby)

The condition github.repository == 'mdev34-lab/alphacode' (line 26 in the full file) prevents the workflow from running in forks. This blocks contributors from testing the release pipeline in their own forks. Consider using a different mechanism (e.g., environment protection rules, required approvals) if the concern is preventing unauthorized releases.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

run: ./script/release-check.ts
- id: version
run: ./script/version.ts
env:
OPENCODE_BUMP: ${{ inputs.bump }}
OPENCODE_VERSION: ${{ inputs.version }}
DRY_RUN: ${{ inputs.dry_run && '1' || '' }}
outputs:
version: ${{ steps.version.outputs.version }}
Expand All @@ -60,13 +51,19 @@ jobs:
if: ${{ !inputs.dry_run }}
runs-on: ubuntu-latest
steps:
# Build the exact tag, not the moving branch, so the artifacts are reproducible.
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
with:
ref: ${{ needs.version.outputs.tag }}
fetch-depth: 0
- uses: ./.github/actions/setup-bun
- name: Check tag against package metadata
run: ./script/release-check.ts --tag "${{ needs.version.outputs.tag }}"
- name: Build all targets and upload archives to the draft release
run: ./packages/opencode/script/build.ts
env:
OPENCODE_VERSION: ${{ needs.version.outputs.version }}
OPENCODE_RELEASE_ID: ${{ needs.version.outputs.release_id }}
ALPHACODE_VERSION: ${{ needs.version.outputs.version }}
ALPHACODE_RELEASE: "1"
- name: Attach install script
run: gh release upload "${{ needs.version.outputs.tag }}" ./install --clobber

Expand All @@ -84,10 +81,9 @@ jobs:
if: ${{ always() && failure() && !inputs.dry_run && needs.version.outputs.tag != '' }}
runs-on: ubuntu-latest
steps:
- name: Delete leftover draft (never a published release)
env:
TAG: ${{ needs.version.outputs.tag }}
run: |
if [ "$(gh release view "$TAG" --json isDraft --jq .isDraft)" = "true" ]; then
gh release delete "$TAG" --yes
fi
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- uses: ./.github/actions/setup-bun
# Removes a leftover draft release and its tag, or an orphan tag pushed
# before the draft existed. Never touches a published release.
- name: Delete leftover draft and orphan tag (never a published release)
run: ./script/release-cleanup.ts "${{ needs.version.outputs.tag }}"
158 changes: 149 additions & 9 deletions docs/releasing.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,75 @@
# Releasing AlphaCode

Releases are GitHub Releases built from tags. No package version file is edited and no bot commits back to `dev`.
Releases are GitHub Releases built from tags. The release version is committed to the
repository before the release is cut: no release step rewrites history and nothing
commits back to `dev` on your behalf.

## The version source

Root `package.json` holds the one authoritative version. Everything else derives from it
and is checked against it:

| Surface | Example | Enforced by |
| --- | --- | --- |
| `package.json` (root) | `0.1.0` | `./script/bump.ts` is the only writer |
| `packages/opencode/package.json` (executable) | `0.1.0` | `./script/bump.ts`, `./script/release-check.ts` |
| Build / runtime (`alphacode --version`) | `0.1.0` | release guard in `@opencode-ai/script`, `--version` smoke test in `script/build.ts` |
| Git tag | `v0.1.0` | `./script/release-check.ts --tag v0.1.0` (runs in the publish workflow) |

A release build is always built from the exact tag, so a clean checkout of `vX.Y.Z`
reports `X.Y.Z` both from package metadata and from `alphacode --version`.

`0.1.0` is the inherited baseline. Local-only builds that were never committed, tagged
or released stay that way - no historical releases are manufactured for them.

## Cut a release

Use **Actions → publish → Run workflow** and select `dev`. Normally run `script/release` (auto bump), or choose an explicit `patch`, `minor`, or `major` bump. To preview first, run `script/release minor --dry-run`; dry runs are allowed from any ref and create no release. You can also set `VERSION=1.2.3` to override the version.
From a clean `dev` checkout, in this exact order:

```bash
# 1. Bump the authoritative version (deterministic SemVer; rewrites both package.json files)
./script/bump.ts patch # or minor / major / auto / X.Y.Z

# 2. Commit and push - the release tag is created at this commit
git add package.json packages/opencode/package.json
git commit -m "chore(release): v<version>"
git push origin dev

# 3. Preview the release notes (allowed from any ref; creates nothing)
./script/release --dry-run

# 4. Cut the release (dev only): pushes the tag, creates the draft release, builds
# every target from that tag, attaches the archives, then publishes
./script/release
```

Step 4 is a `gh workflow run publish.yml --ref dev` dispatch. The workflow lifecycle is:

1. **version job** (`./script/version.ts`): validates the metadata, **pushes the tag to
origin**, then creates the draft release bound to that tag. The tag comes first on
purpose: a draft release creates no git ref until it is published, so without the
explicit push the build job would have no tag to check out. The job is idempotent -
a rerun adopts a tag it already pushed and a draft it already created, and rolls its
own tag back if the draft creation fails.
2. **build job** (`./packages/opencode/script/build.ts`): checks out the pushed tag and
builds from it, then uploads exactly the archives the build produced (a single-target
build uploads its own archive; nothing is globbed).
3. **finalize job**: publishes the draft and marks it latest.

A tag that already points at a different commit, and a release that is already
published, are both hard errors - bump the version instead. The workflow never moves or
reuses someone else's tag.

### Choosing the bump

- `patch` / `minor` / `major`: explicit SemVer bump of the committed version.
- `auto`: derives the bump from conventional commits on the first-parent history since
the last `vX.Y.Z` tag.
- `X.Y.Z`: explicit target version.

Auto bump examines conventional commits on the first-parent history since the last `vX.Y.Z` tag:
`auto` needs a previous tag, so the first AlphaCode release must be an explicit
`patch`, `minor`, `major`, or `X.Y.Z`. `./script/bump.ts` refuses to move the version
backwards, to bump to a prerelease, or to reuse a version that already has a tag.

| Commit | Bump |
| --- | --- |
Expand All @@ -15,18 +78,95 @@ Auto bump examines conventional commits on the first-parent history since the la
| `type!:` or a `BREAKING CHANGE:` footer | minor while the current major is 0; major once it is at least 1 |
| Other types | no bump |

`auto` fails when there are no releasable commits. Auto bump never moves version 0 to 1; use an explicit `version=1.0.0` when making that transition.
`auto` fails when there are no releasable commits. It never moves version 0 to 1; use an
explicit version for that transition.

## First tracked release
## Version checks

The first release establishes the tag baseline. On `dev`, run the workflow once with `version=0.2.0` and `dry_run=true`; verify the summary, then repeat with `dry_run=false`. Do not create a tag or edit a `package.json` by hand.
```bash
./script/release-check.ts # package metadata (and the tag at HEAD, when there is one)
./script/release-check.ts --tag v0.1.1 # strict: HEAD must really be tagged v0.1.1, on a clean tree
./script/bump.ts patch --dry-run # print the bump, write nothing
```

The check exits non-zero and lists every disagreement (root vs executable package,
package vs tag, package vs runtime). It runs in both publish jobs, so a release whose
tag, package metadata and embedded version disagree cannot be built.

A clean checkout of a release tag is a release build on its own: `Script.channel` is
`latest` and the runtime reports the committed package version - but only when the tag
actually matches root `package.json`. A tag that disagrees with the package metadata
fails the build instead of silently lending it release semantics, and a checkout of a
tag with uncommitted changes reports `X.Y.Z+<sha>.dirty` (never the exact release
version), so a modified tree can never pass as the published artifact. Explicit
configuration (`ALPHACODE_CHANNEL`, `ALPHACODE_VERSION`, `ALPHACODE_BUMP`) keeps its own
semantics; the release guard still gates any actual publish.

`--tag` declares which release is being built; it never stands in for a missing one.
The strict form asks git directly (`git tag --points-at HEAD`) and refuses when HEAD is
untagged, when HEAD carries a different tag, or when tracked files have uncommitted
changes. `GITHUB_REF_NAME` and friends are never accepted as a substitute. The
metadata-only form is what the `version` job runs before any tag exists.

Unknown flags are errors, not fallbacks: `./script/bump.ts patch --dry-rnu` and
`./script/release-check.ts --tagg v0.1.1` both fail instead of quietly doing something
less strict - or, worse, a real write.

A development build can never publish a release: the build only uploads artifacts when
`ALPHACODE_RELEASE` is set, and `@opencode-ai/script` refuses to start a release build
whose version is not the exact, stable, committed package version, whose HEAD is not the
matching release tag, or whose tree is dirty. `./script/bump.ts` validates and rewrites
root `package.json` and `packages/opencode/package.json` together: both are read and
checked before either is written, so a half-bumped tree is impossible.

## Environment variables

| Variable | Meaning |
| --- | --- |
| `ALPHACODE_VERSION` | Version to build/embed; in a release build it must equal `package.json`. Implies the `latest` channel: combining it with an explicit non-`latest` channel is an error |
| `ALPHACODE_BUMP` | `auto`, `patch`, `minor` or `major`; forces the release channel |
| `ALPHACODE_CHANNEL` | `latest` for release builds; anything else is a development build |
| `ALPHACODE_RELEASE` | Truthy to attach build artifacts to the release |
| `ALPHACODE_RELEASE_ID` | Release database id; treated as a release signal |

The inherited `OPENCODE_VERSION`, `OPENCODE_BUMP`, `OPENCODE_CHANNEL` and
`OPENCODE_RELEASE_ID` names are still accepted as compatibility aliases (the nix
derivation uses them), but setting an alias and its `ALPHACODE_*` name to different
values is an error, not a silent choice. That includes release signals that contradict
each other: a new `ALPHACODE_RELEASE=false` beside an inherited `OPENCODE_RELEASE_ID`
fails the build instead of publishing on the strength of the inherited variable. Clear
one of them.

A release version is exactly `X.Y.Z`: no prerelease and no build metadata. `X.Y.Z+<sha>`
is a build artifact, never a release, and is rejected everywhere a release is expected.

## Reproduce a release

```bash
git checkout v<version> # detached HEAD: the exact tagged commit, clean tree
./script/release-check.ts --tag v<version>
cd packages/opencode && bun run script/build.ts --single
./dist/alphacode-linux-x64/bin/alphacode --version # prints <version>
```

The first two commands are the same ones the `build` job runs, so a release that cannot
be reproduced locally by this sequence cannot be published either.

## Builds and updates

Non-release builds are versioned `X.Y.(Z+1)-dev.N+<sha7>[.dirty]` (`0.0.1-dev.N+<sha7>` before the first tag). Preview/local builds do not check for or install updates.
Non-release builds are versioned `X.Y.(Z+1)-dev.N+<sha7>[.dirty]` (`0.0.1-dev.N+<sha7>`
before the first tag). Preview/local builds do not check for or install updates.

Release builds check this repository's latest GitHub Release. Patch updates install automatically by default; major and minor updates notify instead. Set `autoupdate: "notify"` in the user config to notify for patch updates too.
Release builds check this repository's latest GitHub Release. Patch updates install
automatically by default; major and minor updates notify instead. Set
`autoupdate: "notify"` in the user config to notify for patch updates too.

## Failures and hotfixes

A failed build leaves no published release: the `cleanup` job deletes a leftover draft. A hotfix is an ordinary release from `dev`: merge or cherry-pick the fix into `dev`, then cut a normal patch release.
A failed build leaves no published release: the `cleanup` job (`./script/release-cleanup.ts`)
deletes a leftover draft release together with its tag, or an orphan tag pushed before the
draft existed. A published release and its tag are never touched. Once cleanup has run, the
same version can be released again by re-running the workflow.

A hotfix is an ordinary release from `dev`: merge or cherry-pick the fix into `dev`,
then cut a normal patch release.
2 changes: 2 additions & 0 deletions packages/cli/script/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ for (const item of targets) {
windows: {},
},
define: {
ALPHACODE_VERSION: `'${Script.version}'`,
ALPHACODE_CHANNEL: `'${Script.channel}'`,
OPENCODE_VERSION: `'${Script.version}'`,
OPENCODE_CLI_NAME: `'${binary}'`,
OPENCODE_MODELS_DEV: modelsData,
Expand Down
18 changes: 16 additions & 2 deletions packages/core/src/installation/version.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
declare global {
const ALPHACODE_VERSION: string
const ALPHACODE_CHANNEL: string
const OPENCODE_VERSION: string
const OPENCODE_CHANNEL: string
}

export const InstallationVersion = typeof OPENCODE_VERSION === "string" ? OPENCODE_VERSION : "local"
export const InstallationChannel = typeof OPENCODE_CHANNEL === "string" ? OPENCODE_CHANNEL : "local"
// The AlphaCode build injects ALPHACODE_*; OPENCODE_* is the inherited alias and
// stays as a fallback so unchanged OpenCode code keeps resolving its globals.
export const InstallationVersion =
typeof ALPHACODE_VERSION === "string"
? ALPHACODE_VERSION
: typeof OPENCODE_VERSION === "string"
? OPENCODE_VERSION
: "local"
export const InstallationChannel =
typeof ALPHACODE_CHANNEL === "string"
? ALPHACODE_CHANNEL
: typeof OPENCODE_CHANNEL === "string"
? OPENCODE_CHANNEL
: "local"
export const InstallationLocal = InstallationChannel === "local"
2 changes: 2 additions & 0 deletions packages/opencode/script/build-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ await Bun.build({
external: ["jsonc-parser", "@lydell/node-pty"],
define: {
OPENCODE_MODELS_DEV: generated.modelsData,
ALPHACODE_VERSION: `'${Script.version}'`,
ALPHACODE_CHANNEL: `'${Script.channel}'`,
OPENCODE_VERSION: `'${Script.version}'`,
OPENCODE_CHANNEL: `'${Script.channel}'`,
},
Expand Down
48 changes: 39 additions & 9 deletions packages/opencode/script/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,28 @@ const dir = path.resolve(__dirname, "..")

process.chdir(dir)

const generated = await import("./generate.ts")

import { Script } from "@opencode-ai/script"
import { archiveName, assertReleaseGate, assertReleaseVersions, Script, tagForVersion, uploadReleaseArchives } from "@opencode-ai/script"
import pkg from "../package.json"

// A published build must be an exact, stable, committed version built from the
// release tag on a clean tree - never a dev build and never an untagged tree.
if (Script.release) {
if (Script.preview) {
throw new Error(
`Refusing to publish a preview build (channel "${Script.channel}"). Build from the release tag or set ALPHACODE_CHANNEL=latest.`,
)
}
const packageVersion = Script.packageVersion
assertReleaseVersions({ packageVersion, runtimeVersion: Script.version })
assertReleaseGate({
expectedTag: tagForVersion(packageVersion),
tagAtHead: await Script.tagAtHead,
dirty: await Script.dirty,
})
}

const generated = await import("./generate.ts")

const singleFlag = process.argv.includes("--single")
const baselineFlag = process.argv.includes("--baseline")
const skipInstall = process.argv.includes("--skip-install")
Expand Down Expand Up @@ -111,6 +128,7 @@ const targets = singleFlag
await $`rm -rf dist`

const binaries: Record<string, string> = {}
const releaseTargets: { name: string; os: string }[] = []
if (!skipInstall) {
await $`bun install --os="*" --cpu="*" @opentui/core@${pkg.dependencies["@opentui/core"]}`
await $`bun install --os="*" --cpu="*" @parcel/watcher@${pkg.dependencies["@parcel/watcher"]}`
Expand Down Expand Up @@ -159,12 +177,17 @@ for (const item of targets) {
entrypoints: ["./src/index.ts", workerPath, treeSitterWorkerPath],
define: {
FFF_LIBC: JSON.stringify(item.abi === "musl" ? "musl" : "gnu"),
// ALPHACODE_* is the AlphaCode runtime version; OPENCODE_* stays as the
// inherited alias so unchanged OpenCode code keeps resolving its globals.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: OPENCODE_LIBC set to empty string for non-Linux (nearby)

The define block sets OPENCODE_LIBC: item.os === "linux" ? '${item.abi ?? "glibc"}' : "" (changed from "undefined"). An empty string may cause issues if downstream code checks if (process.env.OPENCODE_LIBC) or expects undefined. Consider using undefined or omitting the define entirely for non-Linux targets.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

ALPHACODE_VERSION: `'${Script.version}'`,
ALPHACODE_CHANNEL: `'${Script.channel}'`,
OPENCODE_VERSION: `'${Script.version}'`,
OPENCODE_MODELS_DEV: generated.modelsData,
OTUI_TREE_SITTER_WORKER_PATH: bunfsRoot + treeSitterWorkerPath,
OPENCODE_WORKER_PATH: workerPath,
OPENCODE_CHANNEL: `'${Script.channel}'`,
OPENCODE_LIBC: item.os === "linux" ? `'${item.abi ?? "glibc"}'` : "",
// "undefined" (not "") so the watcher fallback reads it as unset.
OPENCODE_LIBC: item.os === "linux" ? `'${item.abi ?? "glibc"}'` : "undefined",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: OPENCODE_LIBC set to string "undefined" could be confusing

Setting OPENCODE_LIBC to the string "undefined" (rather than omitting the variable or using undefined) is a workaround so the watcher fallback "reads it as unset." This is confusing because the string "undefined" is semantically different from an unset variable. Consider using a clearer sentinel like "unset" or "auto", or omit the define entirely for non-Linux targets.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

...(item.os === "linux" ? { "process.env.OPENTUI_LIBC": JSON.stringify(item.abi ?? "glibc") } : {}),
},
})
Expand Down Expand Up @@ -201,17 +224,24 @@ for (const item of targets) {
),
)
binaries[name] = Script.version
releaseTargets.push({ name, os: item.os })
}

if (Script.release) {
for (const key of Object.keys(binaries)) {
if (key.includes("linux")) {
await $`tar -czf ../../${key}.tar.gz *`.cwd(`dist/${key}/bin`)
// Upload exactly the archives this build produced. Globbing both extensions
// breaks a single-target build: one of the two globs matches nothing and the
// shell fails with "no matches".
const archives: string[] = []
for (const target of releaseTargets) {
const archive = archiveName(target)
if (target.os === "linux") {
await $`tar -czf ../../${archive} *`.cwd(`dist/${target.name}/bin`)
} else {
await $`zip -r ../../${key}.zip *`.cwd(`dist/${key}/bin`)
await $`zip -r ../../${archive} *`.cwd(`dist/${target.name}/bin`)
}
archives.push(`./dist/${archive}`)
}
await $`gh release upload v${Script.version} ./dist/*.zip ./dist/*.tar.gz --clobber --repo ${process.env.GH_REPO}`
await uploadReleaseArchives(tagForVersion(Script.version), archives)
}

export { binaries }
Loading
Loading