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