Skip to content

Commit f69eef9

Browse files
Support OpenCode 1.x and 2.x on version branches (#52)
* 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. * opencode: verify each major in its native hash format Drop the base64->hex conversion for npm's sha512 SRI. 1.x keeps GitHub's sha256 (hex, via sha256sum -c); 2.x compares npm's sha512 SRI directly (openssl dgst -sha512 -binary | base64). Removes the ACTUAL_CMD indirection, format guards, and temp-file handling; adds openssl to build-packages. * Apply batched suggestions from code review Co-authored-by: Jonathan Conder <[email protected]> Signed-off-by: Dmitry Lyfar <[email protected]> --------- Signed-off-by: Dmitry Lyfar <[email protected]> Co-authored-by: Jonathan Conder <[email protected]>
1 parent cfef1eb commit f69eef9

9 files changed

Lines changed: 115 additions & 34 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: ${{ 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: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,49 +36,55 @@ parts:
3636
- curl
3737
- ca-certificates
3838
- jq
39+
- openssl
3940
override-pull: |
4041
VERSION="$(cat "$CRAFT_PROJECT_DIR/VERSION")"
4142
craftctl set version="$VERSION"
42-
RELEASE_API="https://api.github.com/repos/anomalyco/opencode/releases/tags/v${VERSION}"
43+
MAJOR="${VERSION%%.*}"
4344
4445
case "${CRAFT_ARCH_BUILD_FOR}" in
4546
amd64) ARCH=x64 ;;
4647
arm64) ARCH=arm64 ;;
4748
*) echo "Unsupported arch: ${CRAFT_ARCH_BUILD_FOR}" >&2; exit 1 ;;
4849
esac
49-
ASSET="opencode-linux-${ARCH}.tar.gz"
50-
DOWNLOAD_URL="https://github.com/anomalyco/opencode/releases/download/v${VERSION}/${ASSET}"
5150
52-
echo "Fetching release manifest for v${VERSION}..."
53-
MANIFEST="$(mktemp)"
54-
trap 'rm -f "$MANIFEST"' EXIT
55-
curl -fsSL "$RELEASE_API" -o "$MANIFEST"
56-
57-
CHECKSUM="$(jq -r --arg name "$ASSET" \
58-
'.assets[] | select(.name==$name) | .digest | sub("^sha256:"; "")' "$MANIFEST")"
59-
60-
if ! echo "$CHECKSUM" | grep -qE '^[a-f0-9]{64}$'; then
61-
echo "Invalid or missing checksum for ${ASSET}" >&2
51+
# Each major is verified in the hash format its source publishes, so no
52+
# base64<->hex conversion is needed.
53+
if [ "$MAJOR" = "1" ]; then
54+
# 1.x: GitHub release asset, sha256 digest (hex).
55+
ASSET="opencode-linux-${ARCH}.tar.gz"
56+
URL="https://github.com/anomalyco/opencode/releases/download/v${VERSION}/${ASSET}"
57+
SHA256="$(curl -fsSL "https://api.github.com/repos/anomalyco/opencode/releases/tags/v${VERSION}" \
58+
| jq -r --arg a "$ASSET" '.assets[] | select(.name==$a) | .digest | sub("^sha256:"; "")')"
59+
curl -fsSL -o "$CRAFT_PART_SRC/${ASSET}" "$URL"
60+
echo "${SHA256} ${CRAFT_PART_SRC}/${ASSET}" | sha256sum -c --status - || {
61+
echo "sha256 mismatch for ${ASSET} (expected ${SHA256:-<none>})" >&2; exit 1; }
62+
elif [ "$MAJOR" = "2" ]; then
63+
# 2.x: per-platform npm package, sha512 SRI integrity (base64).
64+
META="$(curl -fsSL "https://registry.npmjs.org/@opencode/cli-linux-${ARCH}/${VERSION}")"
65+
ASSET="cli-linux-${ARCH}.tgz"
66+
URL="$(jq -r '.dist.tarball' <<<"$META")"
67+
SRI="$(jq -r '.dist.integrity' <<<"$META")"
68+
curl -fsSL -o "$CRAFT_PART_SRC/${ASSET}" "$URL"
69+
ACTUAL="sha512-$(openssl dgst -sha512 -binary "$CRAFT_PART_SRC/${ASSET}" | base64 -w0)"
70+
[ "$ACTUAL" = "$SRI" ] || {
71+
echo "integrity mismatch for ${ASSET}: expected ${SRI:-<none>}, got ${ACTUAL}" >&2; exit 1; }
72+
else
73+
echo "Unsupported OpenCode major version: ${VERSION}" >&2
6274
exit 1
6375
fi
6476
65-
echo "Downloading ${DOWNLOAD_URL}..."
66-
curl -fsSL -o "$CRAFT_PART_SRC/${ASSET}" "$DOWNLOAD_URL"
67-
68-
ACTUAL="$(sha256sum "$CRAFT_PART_SRC/${ASSET}" | cut -d' ' -f1)"
69-
if [ "$ACTUAL" != "$CHECKSUM" ]; then
70-
echo "Checksum mismatch!" >&2
71-
echo " expected: $CHECKSUM" >&2
72-
echo " actual: $ACTUAL" >&2
73-
rm -f "$CRAFT_PART_SRC/${ASSET}"
74-
exit 1
75-
fi
76-
77-
echo "Checksum OK. Extracting..."
7877
tar -xzf "$CRAFT_PART_SRC/${ASSET}" -C "$CRAFT_PART_SRC"
7978
rm "$CRAFT_PART_SRC/${ASSET}"
79+
# npm tarballs nest the binary under package/bin/.
80+
if [ -f "$CRAFT_PART_SRC/package/bin/opencode" ]; then
81+
mv "$CRAFT_PART_SRC/package/bin/opencode" "$CRAFT_PART_SRC/opencode"
82+
rm -rf "$CRAFT_PART_SRC/package"
83+
fi
8084
override-build: |
8185
install -Dm755 "$CRAFT_PART_SRC/opencode" "$CRAFT_PART_INSTALL/bin/opencode"
86+
# Hooks read this to apply major-version specific setup.
87+
install -Dm644 "$CRAFT_PROJECT_DIR/VERSION" "$CRAFT_PART_INSTALL/version"
8288
8389
workshop-prompt:
8490
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)