Skip to content

Commit 21ccdfe

Browse files
authored
Merge pull request #19 from iHildy/chore/opencode-smoke
chore: add opencode smoke workflow
2 parents 3248bef + 9131ce8 commit 21ccdfe

File tree

2 files changed

+199
-3
lines changed

2 files changed

+199
-3
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: Opencode Smoke
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: 'npm dist-tag to test'
8+
required: true
9+
default: next
10+
timeout:
11+
description: 'seconds to wait before considering opencode stable'
12+
required: false
13+
default: '30'
14+
workflow_call:
15+
inputs:
16+
tag:
17+
type: string
18+
required: true
19+
timeout:
20+
type: number
21+
required: false
22+
default: 30
23+
24+
jobs:
25+
smoke:
26+
runs-on: ${{ matrix.os }}
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
os: [ubuntu-latest, macos-latest]
31+
permissions:
32+
contents: read
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- name: Resolve plugin version
37+
id: version
38+
run: |
39+
VERSION=$(npm view opencode-synced@${{ inputs.tag }} version)
40+
if [ -z "$VERSION" ]; then
41+
echo "No version found for tag: ${{ inputs.tag }}"
42+
exit 1
43+
fi
44+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
45+
46+
- name: Install opencode
47+
env:
48+
OPENCODE_INSTALL_DIR: ${{ runner.temp }}/opencode/bin
49+
run: |
50+
curl -fsSL https://opencode.ai/install | bash
51+
echo "${OPENCODE_INSTALL_DIR}" >> "$GITHUB_PATH"
52+
53+
- name: Configure clean opencode home
54+
env:
55+
OPENCODE_HOME: ${{ runner.temp }}/opencode-home
56+
PLUGIN_VERSION: ${{ steps.version.outputs.version }}
57+
run: |
58+
export HOME="$OPENCODE_HOME"
59+
export XDG_CONFIG_HOME="$HOME/.config"
60+
export XDG_CACHE_HOME="$HOME/.cache"
61+
export XDG_DATA_HOME="$HOME/.local/share"
62+
export XDG_STATE_HOME="$HOME/.local/state"
63+
64+
mkdir -p "$XDG_CONFIG_HOME/opencode"
65+
cat > "$XDG_CONFIG_HOME/opencode/opencode.json" <<EOF
66+
{
67+
"\$schema": "https://opencode.ai/config.json",
68+
"plugin": ["opencode-synced@${PLUGIN_VERSION}"]
69+
}
70+
EOF
71+
72+
rm -rf "$XDG_CACHE_HOME/opencode/node_modules"
73+
74+
- name: Launch opencode (smoke)
75+
env:
76+
OPENCODE_HOME: ${{ runner.temp }}/opencode-home
77+
OPENCODE_SMOKE_TIMEOUT: ${{ inputs.timeout }}
78+
OPENCODE_SMOKE_LOG: ${{ runner.temp }}/opencode-smoke.log
79+
run: |
80+
export HOME="$OPENCODE_HOME"
81+
export XDG_CONFIG_HOME="$HOME/.config"
82+
export XDG_CACHE_HOME="$HOME/.cache"
83+
export XDG_DATA_HOME="$HOME/.local/share"
84+
export XDG_STATE_HOME="$HOME/.local/state"
85+
86+
python - <<'PY'
87+
import os
88+
import threading
89+
import subprocess
90+
import time
91+
import sys
92+
93+
timeout = int(os.environ.get("OPENCODE_SMOKE_TIMEOUT", "20"))
94+
log_path = os.environ.get("OPENCODE_SMOKE_LOG", "opencode-smoke.log")
95+
cmd = ["opencode", "serve", "--port", "4096", "--hostname", "127.0.0.1"]
96+
97+
proc = subprocess.Popen(
98+
cmd,
99+
stdout=subprocess.PIPE,
100+
stderr=subprocess.STDOUT,
101+
text=True,
102+
)
103+
104+
def reader():
105+
if not proc.stdout:
106+
return
107+
with open(log_path, "w") as log_file:
108+
for line in proc.stdout:
109+
log_file.write(line)
110+
111+
thread = threading.Thread(target=reader, daemon=True)
112+
thread.start()
113+
114+
start = time.time()
115+
while time.time() - start < timeout:
116+
if proc.poll() is not None:
117+
break
118+
time.sleep(1)
119+
120+
if proc.poll() is not None:
121+
print("opencode exited early with code", proc.returncode)
122+
try:
123+
with open(log_path, "r") as log_file:
124+
lines = log_file.readlines()
125+
tail = "".join(lines[-200:])
126+
print("--- opencode output (tail) ---")
127+
print(tail)
128+
except FileNotFoundError:
129+
print("No log output captured.")
130+
sys.exit(1)
131+
132+
proc.terminate()
133+
try:
134+
proc.wait(timeout=5)
135+
except subprocess.TimeoutExpired:
136+
proc.kill()
137+
proc.wait()
138+
PY
139+
140+
- name: Upload opencode logs (on failure)
141+
if: failure()
142+
uses: actions/upload-artifact@v4
143+
with:
144+
name: opencode-smoke-logs-${{ matrix.os }}
145+
path: ${{ runner.temp }}/opencode-smoke.log

.github/workflows/publish.yml

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ permissions:
2020
jobs:
2121
publish:
2222
runs-on: ubuntu-latest
23+
outputs:
24+
requested_tag: ${{ steps.publish.outputs.requested_tag }}
25+
version: ${{ steps.version.outputs.version }}
2326
steps:
2427
- uses: actions/checkout@v4
2528

@@ -38,12 +41,60 @@ jobs:
3841
- id: inputs
3942
uses: simenandre/setup-inputs@v1
4043

41-
- name: Publish to npm with OIDC
44+
- name: Publish candidate to npm with OIDC
45+
id: publish
4246
run: |
4347
TAG="${{ steps.inputs.outputs.tag }}"
4448
if [ -z "$TAG" ]; then
4549
TAG="latest"
4650
fi
4751
48-
echo "Publishing with tag: $TAG"
49-
mise run publish --tag "$TAG"
52+
echo "requested_tag=$TAG" >> "$GITHUB_OUTPUT"
53+
54+
CANDIDATE_TAG="next"
55+
echo "Publishing candidate with tag: $CANDIDATE_TAG (requested: $TAG)"
56+
mise run publish --tag "$CANDIDATE_TAG"
57+
58+
- name: Resolve published version
59+
id: version
60+
run: |
61+
VERSION=$(npm view opencode-synced@next version)
62+
if [ -z "$VERSION" ]; then
63+
echo "Failed to resolve version from npm tag: next"
64+
exit 1
65+
fi
66+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
67+
68+
smoke:
69+
needs: publish
70+
uses: ./.github/workflows/opencode-smoke.yml
71+
with:
72+
tag: next
73+
timeout: 20
74+
75+
promote_latest:
76+
needs: [publish, smoke]
77+
if: needs.publish.outputs.requested_tag == 'latest'
78+
runs-on: ubuntu-latest
79+
permissions:
80+
id-token: write
81+
contents: read
82+
steps:
83+
- uses: actions/checkout@v4
84+
85+
- uses: jdx/mise-action@d6e32c1796099e0f1f3ac741c220a8b7eae9e5dd
86+
with:
87+
install: true
88+
cache: true
89+
experimental: true
90+
91+
- name: Promote latest dist-tag
92+
run: |
93+
VERSION="${{ needs.publish.outputs.version }}"
94+
if [ -z "$VERSION" ]; then
95+
echo "Missing published version."
96+
exit 1
97+
fi
98+
99+
echo "Promoting opencode-synced@$VERSION to latest"
100+
npm dist-tag add "opencode-synced@$VERSION" latest

0 commit comments

Comments
 (0)