Skip to content

Commit 38e3a1c

Browse files
committed
Support OpenCode 1.x and 2.x on version branches
Move from the single `latest` branch to major-version branches `1` and `2`, published to the `1` and `2` Store tracks. Track `1` is also promoted to `latest/stable`, so existing consumers keep getting OpenCode 1.x. - Download OpenCode 2.x from the `@opencode/cli-linux-*` npm packages, verified against the registry's sha512 integrity; 2.x is not published as GitHub release assets. 1.x keeps the GitHub release download. - Stage the version in the SDK so hooks can apply major-specific setup. - OpenCode 2.x no longer reads /etc/opencode, so export OPENCODE_CONFIG pointing at the SDK config. The workshop prompt is still not applied on 2.x because of anomalyco/opencode#51341; it takes effect once a fixed release is picked up. - Renovate: one regex manager per major (github-releases for 1.x, npm @opencode/cli for 2.x), each pinned to its branch. - Workflows: build/upload on `[0-9]+` branches, track from the branch name. - Spread: add a 2.x config test, skipped on 1.x.
1 parent cfef1eb commit 38e3a1c

9 files changed

Lines changed: 131 additions & 20 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Build SDK
33
on:
44
pull_request:
55
branches:
6-
- latest
6+
- "[0-9]+"
77

88
concurrency:
99
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}

‎.github/workflows/upload.yml‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ name: Build and Upload SDK
33
on:
44
push:
55
branches:
6-
- latest
6+
- "[0-9]+"
77
workflow_dispatch:
88
inputs:
99
branch:
10-
description: "Branch name (e.g., 1.3)"
10+
description: "Branch name (e.g., 2)"
1111
required: true
1212
type: string
1313

@@ -21,8 +21,10 @@ jobs:
2121
with:
2222
platforms: '["amd64"]'
2323
platform-flag: "--build-for"
24-
track: "latest"
24+
ref: ${{ github.event.inputs.branch || github.ref }}
2525
risk: "stable"
26+
# Track 1 is also released to latest/stable until 2.x becomes the default.
27+
promote-to-latest: ${{ (github.event.inputs.branch || github.ref_name) == '1' }}
2628
secrets:
2729
SDKCRAFT_STORE_CREDENTIALS: ${{ secrets.SDKCRAFT_STORE_CREDENTIALS_PROD }}
2830
build-and-upload-arm64:
@@ -31,7 +33,9 @@ jobs:
3133
platforms: '["arm64"]'
3234
platform-flag: "--build-for"
3335
runs-on: '["self-hosted-linux-arm64-noble-xlarge"]'
34-
track: "latest"
36+
ref: ${{ github.event.inputs.branch || github.ref }}
3537
risk: "stable"
38+
# Track 1 is also released to latest/stable until 2.x becomes the default.
39+
promote-to-latest: ${{ (github.event.inputs.branch || github.ref_name) == '1' }}
3640
secrets:
3741
SDKCRAFT_STORE_CREDENTIALS: ${{ secrets.SDKCRAFT_STORE_CREDENTIALS_PROD }}

‎README.md‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ actions:
2424
2525
This creates a basic OpenCode environment with an interactive action.
2626
27+
### Tracks
28+
29+
| Channel | OpenCode |
30+
|---|---|
31+
| `1/stable` | 1.x |
32+
| `2/stable` | 2.x |
33+
| `latest/stable` | 1.x (same revisions as `1/stable`) |
34+
35+
On `2/stable`, the SDK's workshop instructions are not yet applied: OpenCode
36+
2.x ignores the `instructions` config key
37+
([anomalyco/opencode#51341](https://github.com/anomalyco/opencode/issues/51341)).
38+
They take effect once a fixed OpenCode release lands on the track.
39+
2740
---
2841

2942
## Using the SDK

‎hooks/setup-base‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,18 @@ else
2121
_merged=$(jq -s '.[0] * .[1]' "${_config}" "${SDK}/opencode.json")
2222
echo "${_merged}" > "${_config}"
2323
fi
24+
25+
# OpenCode 2.x no longer reads the system-managed /etc/opencode directory, so
26+
# point it at the same config explicitly. This file is read by the OpenCode
27+
# background server, which inherits the environment of the shell that starts it.
28+
#
29+
# NOTE: as of 2.0.21 OpenCode 2.x parses the "instructions" key but never loads
30+
# the files it lists, so the workshop prompt is not applied on 2.x until the
31+
# upstream fix lands (https://github.com/anomalyco/opencode/issues/51341, fix
32+
# in https://github.com/anomalyco/opencode/pull/51422). No SDK change is needed
33+
# once a fixed release is picked up by Renovate.
34+
if [[ "$(cut -d. -f1 "${SDK}/version")" == "2" ]]; then
35+
cat <<EOF2 >>/etc/profile.d/opencode.sh
36+
export OPENCODE_CONFIG="${_config}"
37+
EOF2
38+
fi

‎renovate.json‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,40 @@
1111
"customType": "regex",
1212
"managerFilePatterns": ["/^VERSION$/"],
1313
"matchStrings": [
14-
"(?<currentValue>[0-9.]+)"
14+
"(?<currentValue>1\\.[0-9.]+)"
1515
],
1616
"depNameTemplate": "anomalyco/opencode",
1717
"datasourceTemplate": "github-releases",
1818
"extractVersionTemplate": "^v?(?<version>.+)$",
1919
"versioningTemplate": "semver"
20+
},
21+
{
22+
"customType": "regex",
23+
"managerFilePatterns": ["/^VERSION$/"],
24+
"matchStrings": [
25+
"(?<currentValue>2\\.[0-9.]+)"
26+
],
27+
"depNameTemplate": "@opencode/cli",
28+
"datasourceTemplate": "npm",
29+
"versioningTemplate": "semver"
2030
}
2131
],
2232
"automerge": true,
2333
"platformAutomerge": true,
2434
"baseBranchPatterns": [
25-
"latest"
35+
"1",
36+
"2"
2637
],
2738
"packageRules": [
2839
{
2940
"matchPackageNames": ["anomalyco/opencode"],
30-
"matchBaseBranches": ["latest"]
41+
"matchBaseBranches": ["1"],
42+
"allowedVersions": "/^1\\./"
43+
},
44+
{
45+
"matchPackageNames": ["@opencode/cli"],
46+
"matchBaseBranches": ["2"],
47+
"allowedVersions": "/^2\\./"
3148
}
3249
]
3350
}

‎sdkcraft.yaml‎

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,62 @@ parts:
3939
override-pull: |
4040
VERSION="$(cat "$CRAFT_PROJECT_DIR/VERSION")"
4141
craftctl set version="$VERSION"
42-
RELEASE_API="https://api.github.com/repos/anomalyco/opencode/releases/tags/v${VERSION}"
42+
MAJOR="${VERSION%%.*}"
4343
4444
case "${CRAFT_ARCH_BUILD_FOR}" in
4545
amd64) ARCH=x64 ;;
4646
arm64) ARCH=arm64 ;;
4747
*) echo "Unsupported arch: ${CRAFT_ARCH_BUILD_FOR}" >&2; exit 1 ;;
4848
esac
49-
ASSET="opencode-linux-${ARCH}.tar.gz"
50-
DOWNLOAD_URL="https://github.com/anomalyco/opencode/releases/download/v${VERSION}/${ASSET}"
5149
52-
echo "Fetching release manifest for v${VERSION}..."
53-
MANIFEST="$(mktemp)"
54-
trap 'rm -f "$MANIFEST"' EXIT
55-
curl -fsSL "$RELEASE_API" -o "$MANIFEST"
50+
if [ "$MAJOR" = "1" ]; then
51+
# OpenCode 1.x ships as GitHub release assets with a sha256 digest.
52+
RELEASE_API="https://api.github.com/repos/anomalyco/opencode/releases/tags/v${VERSION}"
53+
ASSET="opencode-linux-${ARCH}.tar.gz"
54+
DOWNLOAD_URL="https://github.com/anomalyco/opencode/releases/download/v${VERSION}/${ASSET}"
5655
57-
CHECKSUM="$(jq -r --arg name "$ASSET" \
58-
'.assets[] | select(.name==$name) | .digest | sub("^sha256:"; "")' "$MANIFEST")"
56+
echo "Fetching release manifest for v${VERSION}..."
57+
MANIFEST="$(mktemp)"
58+
trap 'rm -f "$MANIFEST"' EXIT
59+
curl -fsSL "$RELEASE_API" -o "$MANIFEST"
5960
60-
if ! echo "$CHECKSUM" | grep -qE '^[a-f0-9]{64}$'; then
61-
echo "Invalid or missing checksum for ${ASSET}" >&2
61+
CHECKSUM="$(jq -r --arg name "$ASSET" \
62+
'.assets[] | select(.name==$name) | .digest | sub("^sha256:"; "")' "$MANIFEST")"
63+
64+
if ! echo "$CHECKSUM" | grep -qE '^[a-f0-9]{64}$'; then
65+
echo "Invalid or missing checksum for ${ASSET}" >&2
66+
exit 1
67+
fi
68+
ACTUAL_CMD=sha256sum
69+
elif [ "$MAJOR" = "2" ]; then
70+
# OpenCode 2.x is not published as GitHub release assets; it ships as
71+
# per-platform npm packages verified by the registry's sha512 integrity.
72+
PACKAGE="@opencode/cli-linux-${ARCH}"
73+
ASSET="cli-linux-${ARCH}.tgz"
74+
75+
echo "Fetching npm metadata for ${PACKAGE}@${VERSION}..."
76+
MANIFEST="$(mktemp)"
77+
trap 'rm -f "$MANIFEST"' EXIT
78+
curl -fsSL "https://registry.npmjs.org/${PACKAGE}/${VERSION}" -o "$MANIFEST"
79+
80+
DOWNLOAD_URL="$(jq -r '.dist.tarball' "$MANIFEST")"
81+
CHECKSUM="$(jq -r '.dist.integrity | select(startswith("sha512-")) | sub("^sha512-"; "")' "$MANIFEST" \
82+
| base64 -d | od -An -vtx1 | tr -d ' \n')"
83+
84+
if ! echo "$CHECKSUM" | grep -qE '^[a-f0-9]{128}$'; then
85+
echo "Invalid or missing sha512 integrity for ${PACKAGE}@${VERSION}" >&2
86+
exit 1
87+
fi
88+
ACTUAL_CMD=sha512sum
89+
else
90+
echo "Unsupported OpenCode major version: ${VERSION}" >&2
6291
exit 1
6392
fi
6493
6594
echo "Downloading ${DOWNLOAD_URL}..."
6695
curl -fsSL -o "$CRAFT_PART_SRC/${ASSET}" "$DOWNLOAD_URL"
6796
68-
ACTUAL="$(sha256sum "$CRAFT_PART_SRC/${ASSET}" | cut -d' ' -f1)"
97+
ACTUAL="$($ACTUAL_CMD "$CRAFT_PART_SRC/${ASSET}" | cut -d' ' -f1)"
6998
if [ "$ACTUAL" != "$CHECKSUM" ]; then
7099
echo "Checksum mismatch!" >&2
71100
echo " expected: $CHECKSUM" >&2
@@ -77,8 +106,15 @@ parts:
77106
echo "Checksum OK. Extracting..."
78107
tar -xzf "$CRAFT_PART_SRC/${ASSET}" -C "$CRAFT_PART_SRC"
79108
rm "$CRAFT_PART_SRC/${ASSET}"
109+
# npm tarballs nest the binary under package/bin/.
110+
if [ -f "$CRAFT_PART_SRC/package/bin/opencode" ]; then
111+
mv "$CRAFT_PART_SRC/package/bin/opencode" "$CRAFT_PART_SRC/opencode"
112+
rm -rf "$CRAFT_PART_SRC/package"
113+
fi
80114
override-build: |
81115
install -Dm755 "$CRAFT_PART_SRC/opencode" "$CRAFT_PART_INSTALL/bin/opencode"
116+
# Hooks read this to apply major-version specific setup.
117+
install -Dm644 "$CRAFT_PROJECT_DIR/VERSION" "$CRAFT_PART_INSTALL/version"
82118
83119
workshop-prompt:
84120
plugin: dump

‎tests/main/v2-config/task.yaml‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
summary: OpenCode 2.x loads the SDK config from /etc/opencode via OPENCODE_CONFIG
2+
3+
prepare: |
4+
# OpenCode 1.x reads /etc/opencode natively; this only applies to 2.x.
5+
[ "$MAJOR" = "2" ] || exit 0
6+
envsubst '${BASE}' <workshop.yaml.in >workshop.yaml
7+
workshop launch
8+
9+
restore: |
10+
workshop remove || true
11+
12+
execute: |
13+
[ "$MAJOR" = "2" ] || exit 0
14+
workshop exec -- printenv OPENCODE_CONFIG | MATCH "^/etc/opencode/opencode.json$"
15+
# `debug config` lists every config source the background server loaded.
16+
workshop exec -- opencode debug config | MATCH '"path": "/etc/opencode/opencode.json"'
17+
workshop exec -- opencode service stop || true
18+
19+
debug: |
20+
workshop exec -- cat /etc/profile.d/opencode.sh || true
21+
workshop exec -- opencode debug config || true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
name: test-opencode
2+
base: ${BASE}
3+
sdks:
4+
- name: try-opencode

‎tests/spread.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ suites:
1717
BASE/noble: [email protected]
1818
BASE/resolute: [email protected]
1919
EXPECTED_VERSION: '$(HOST: cat "`git rev-parse --show-toplevel`/VERSION")'
20+
MAJOR: '$(HOST: cut -d. -f1 "`git rev-parse --show-toplevel`/VERSION")'

0 commit comments

Comments
 (0)