|
| 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 |
0 commit comments