@@ -38,23 +38,32 @@ jobs:
3838 shell : bash
3939 env :
4040 GITHUB_TOKEN : ${{ github.token }}
41+ OPENCODE_GITHUB_REPO : ${{ vars.OPENCODE_GITHUB_REPO || 'anomalyco/opencode' }}
42+ OPENCODE_VERSION : ${{ vars.OPENCODE_VERSION || '' }}
4143 run : |
4244 set -euo pipefail
4345
46+ repo="${OPENCODE_GITHUB_REPO:-anomalyco/opencode}"
4447 version="${OPENCODE_VERSION:-}"
4548
49+ if [ -z "$version" ]; then
50+ version="$(node -p "require('./packages/desktop/package.json').opencodeVersion || ''" 2>/dev/null || true)"
51+ fi
52+
53+ version="$(echo "$version" | tr -d '\r\n' | sed 's/^v//')"
54+
4655 if [ -z "$version" ] || [ "$version" = "latest" ]; then
4756 latest=""
4857 if [ -n "${GITHUB_TOKEN:-}" ]; then
4958 latest=$(curl -fsSL \
5059 -H "Authorization: Bearer ${GITHUB_TOKEN}" \
5160 -H "X-GitHub-Api-Version: 2022-11-28" \
52- https://api.github.com/repos/anomalyco/opencode/ releases/latest \
61+ " https://api.github.com/repos/${repo}/ releases/latest" \
5362 | sed -n 's/.*"tag_name": *"v\([^"]*\)".*/\1/p')
5463 else
5564 latest=$(curl -fsSL \
5665 -H "X-GitHub-Api-Version: 2022-11-28" \
57- https://api.github.com/repos/anomalyco/opencode/ releases/latest \
66+ " https://api.github.com/repos/${repo}/ releases/latest" \
5867 | sed -n 's/.*"tag_name": *"v\([^"]*\)".*/\1/p')
5968 fi
6069 if [ -n "$latest" ]; then
6776 exit 1
6877 fi
6978
70- curl -fsSL https://opencode.ai/install | bash -s -- --version "$version"
71- echo "$HOME/.opencode/bin" >> "$GITHUB_PATH"
79+ arch="$(uname -m)"
80+ case "${RUNNER_OS}" in
81+ Linux)
82+ if [ "$arch" = "aarch64" ] || [ "$arch" = "arm64" ]; then
83+ opencode_asset="opencode-linux-arm64.tar.gz"
84+ else
85+ opencode_asset="opencode-linux-x64-baseline.tar.gz"
86+ fi
87+ ;;
88+ macOS)
89+ if [ "$arch" = "arm64" ]; then
90+ opencode_asset="opencode-darwin-arm64.zip"
91+ else
92+ opencode_asset="opencode-darwin-x64-baseline.zip"
93+ fi
94+ ;;
95+ *)
96+ echo "Unsupported OS: ${RUNNER_OS}" >&2
97+ exit 1
98+ ;;
99+ esac
100+
101+ url="https://github.com/${repo}/releases/download/v${version}/${opencode_asset}"
102+ tmp_dir="$RUNNER_TEMP/opencode"
103+ extract_dir="$tmp_dir/extracted"
104+ rm -rf "$tmp_dir"
105+ mkdir -p "$extract_dir"
106+
107+ curl_headers=()
108+ if [ -n "${GITHUB_TOKEN:-}" ]; then
109+ curl_headers+=( -H "Authorization: Bearer ${GITHUB_TOKEN}" )
110+ fi
111+
112+ curl -fsSL --retry 5 --retry-all-errors --retry-delay 2 "${curl_headers[@]}" -o "$tmp_dir/$opencode_asset" "$url"
113+
114+ if [[ "$opencode_asset" == *.tar.gz ]]; then
115+ tar -xzf "$tmp_dir/$opencode_asset" -C "$extract_dir"
116+ else
117+ unzip -q "$tmp_dir/$opencode_asset" -d "$extract_dir"
118+ fi
119+
120+ if [ -f "$extract_dir/opencode" ]; then
121+ bin_path="$extract_dir/opencode"
122+ elif [ -f "$extract_dir/opencode.exe" ]; then
123+ bin_path="$extract_dir/opencode.exe"
124+ else
125+ echo "OpenCode binary not found in archive" >&2
126+ ls -la "$extract_dir"
127+ exit 1
128+ fi
129+
130+ install_dir="$HOME/.opencode/bin"
131+ mkdir -p "$install_dir"
132+ cp "$bin_path" "$install_dir/opencode"
133+ chmod 755 "$install_dir/opencode"
134+ echo "$install_dir" >> "$GITHUB_PATH"
72135
73136 - name : Verify OpenCode
74137 run : opencode --version
0 commit comments