publish.yml 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. name: publish
  2. run-name: "${{ format('release {0}', inputs.bump) }}"
  3. on:
  4. push:
  5. branches:
  6. - ci
  7. - dev
  8. - beta
  9. - v2
  10. - fix/npm-native-binary-install
  11. - snapshot-*
  12. workflow_dispatch:
  13. inputs:
  14. bump:
  15. description: "Bump major, minor, or patch"
  16. required: false
  17. type: choice
  18. options:
  19. - major
  20. - minor
  21. - patch
  22. version:
  23. description: "Override version (optional)"
  24. required: false
  25. type: string
  26. concurrency: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.version || inputs.bump }}
  27. permissions:
  28. id-token: write
  29. contents: write
  30. packages: write
  31. env:
  32. OPENCODE_CHANNEL: ${{ (github.ref_name == 'v2' && 'dev') || '' }}
  33. jobs:
  34. version:
  35. runs-on: blacksmith-4vcpu-ubuntu-2404
  36. if: github.repository == 'anomalyco/opencode'
  37. steps:
  38. - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
  39. with:
  40. fetch-depth: 0
  41. - uses: ./.github/actions/setup-bun
  42. - name: Deploy update service
  43. if: github.ref_name == 'v2' || github.ref_name == 'beta'
  44. working-directory: packages/updates
  45. run: bun run deploy
  46. env:
  47. CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
  48. - name: Setup git committer
  49. id: committer
  50. uses: ./.github/actions/setup-git-committer
  51. with:
  52. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  53. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  54. - name: Install OpenCode
  55. if: inputs.bump || inputs.version
  56. run: bun i -g opencode-ai
  57. - id: version
  58. run: |
  59. ./script/version.ts
  60. env:
  61. GH_TOKEN: ${{ steps.committer.outputs.token }}
  62. OPENCODE_BUMP: ${{ inputs.bump }}
  63. OPENCODE_VERSION: ${{ inputs.version }}
  64. OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
  65. GH_REPO: ${{ (github.ref_name == 'beta' && 'anomalyco/opencode-beta') || github.repository }}
  66. outputs:
  67. version: ${{ steps.version.outputs.version }}
  68. release: ${{ steps.version.outputs.release }}
  69. tag: ${{ steps.version.outputs.tag }}
  70. repo: ${{ steps.version.outputs.repo }}
  71. build-cli:
  72. needs: version
  73. runs-on: blacksmith-4vcpu-ubuntu-2404
  74. if: github.repository == 'anomalyco/opencode'
  75. steps:
  76. - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
  77. with:
  78. fetch-tags: true
  79. - uses: ./.github/actions/setup-bun
  80. with:
  81. bun-version: canary # Bun 1.4 until its stable release is published
  82. - name: Setup git committer
  83. id: committer
  84. uses: ./.github/actions/setup-git-committer
  85. with:
  86. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  87. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  88. - name: Build legacy CLI
  89. if: github.ref_name != 'v2' && github.ref_name != 'beta'
  90. run: ./packages/opencode/script/build.ts ${{ (github.ref_name == 'beta' && '--sourcemaps') || '' }}
  91. env:
  92. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  93. OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
  94. GH_REPO: ${{ needs.version.outputs.repo }}
  95. GH_TOKEN: ${{ steps.committer.outputs.token }}
  96. - name: Build preview CLI
  97. id: build
  98. run: ./packages/cli/script/build.ts ${{ (github.ref_name == 'beta' && '--sourcemaps') || '' }}
  99. env:
  100. BUN_COMPILE_RELEASE: canary
  101. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  102. OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
  103. GH_REPO: ${{ needs.version.outputs.repo }}
  104. GH_TOKEN: ${{ steps.committer.outputs.token }}
  105. - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
  106. if: github.ref_name != 'v2' && github.ref_name != 'beta'
  107. with:
  108. name: opencode-cli
  109. path: |
  110. packages/opencode/dist/opencode-darwin*
  111. packages/opencode/dist/opencode-linux*
  112. - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
  113. if: github.ref_name != 'v2' && github.ref_name != 'beta'
  114. with:
  115. name: opencode-cli-windows
  116. path: packages/opencode/dist/opencode-windows*
  117. - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
  118. with:
  119. name: opencode-preview-cli-unsigned
  120. path: packages/cli/dist/cli-*
  121. outputs:
  122. version: ${{ needs.version.outputs.version }}
  123. sign-cli-macos:
  124. needs: build-cli
  125. runs-on: macos-26
  126. if: github.repository == 'anomalyco/opencode'
  127. steps:
  128. - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
  129. - uses: apple-actions/import-codesign-certs@8f3fb608891dd2244cdab3d69cd68c0d37a7fe93 # v2.0.0
  130. with:
  131. keychain: build
  132. p12-file-base64: ${{ secrets.APPLE_CERTIFICATE }}
  133. p12-password: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  134. - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
  135. with:
  136. name: opencode-preview-cli-unsigned
  137. path: packages/cli/dist
  138. - name: Sign macOS CLI binaries
  139. run: |
  140. identity=$(security find-identity -v -p codesigning build.keychain | sed -n 's/.*"\(Developer ID Application:.*\)"/\1/p' | head -n 1)
  141. if [ -z "$identity" ]; then
  142. echo "Developer ID Application identity not found"
  143. exit 1
  144. fi
  145. found=0
  146. for file in packages/cli/dist/cli-darwin-*/bin/opencode2; do
  147. if [ ! -f "$file" ]; then
  148. continue
  149. fi
  150. found=1
  151. codesign \
  152. --force \
  153. --timestamp \
  154. --options runtime \
  155. --entitlements packages/cli/script/entitlements.plist \
  156. --sign "$identity" \
  157. "$file"
  158. codesign --verify --deep --strict --verbose=4 "$file"
  159. codesign --display --requirements - "$file"
  160. done
  161. if [ "$found" -eq 0 ]; then
  162. echo "No macOS CLI binaries found"
  163. exit 1
  164. fi
  165. - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
  166. with:
  167. name: opencode-preview-cli
  168. path: packages/cli/dist/cli-*
  169. if-no-files-found: error
  170. build-node-cli:
  171. needs: version
  172. if: github.repository == 'anomalyco/opencode'
  173. strategy:
  174. fail-fast: false
  175. matrix:
  176. settings:
  177. - target: linux-arm64
  178. host: blacksmith-4vcpu-ubuntu-2404-arm
  179. - target: linux-x64
  180. host: blacksmith-4vcpu-ubuntu-2404
  181. - target: darwin-arm64
  182. host: macos-26
  183. - target: windows-arm64
  184. host: blacksmith-4vcpu-windows-2025
  185. - target: windows-x64
  186. host: blacksmith-4vcpu-windows-2025
  187. runs-on: ${{ matrix.settings.host }}
  188. defaults:
  189. run:
  190. shell: bash
  191. steps:
  192. - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
  193. - uses: ./.github/actions/setup-bun
  194. with:
  195. install-flags: --os=* --cpu=*
  196. - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
  197. with:
  198. node-version: "26.4.0"
  199. - name: Build
  200. run: bun packages/cli/script/build-node.ts --target=${{ matrix.settings.target }} --skip-install --outdir=dist/node
  201. env:
  202. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  203. OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
  204. - name: Verify service lifecycle
  205. if: matrix.settings.target != 'windows-arm64'
  206. working-directory: packages/cli
  207. run: bun run script/service-smoke.ts --node
  208. - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
  209. with:
  210. name: opencode-node-cli-${{ matrix.settings.target }}
  211. path: packages/cli/dist/node/cli-node-*
  212. if-no-files-found: error
  213. sign-cli-windows:
  214. needs:
  215. - build-cli
  216. - version
  217. runs-on: blacksmith-4vcpu-windows-2025
  218. if: github.repository == 'anomalyco/opencode' && github.ref_name != 'v2' && github.ref_name != 'beta'
  219. env:
  220. AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
  221. AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
  222. AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
  223. AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
  224. AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE }}
  225. AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }}
  226. steps:
  227. - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
  228. - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
  229. with:
  230. name: opencode-cli-windows
  231. path: packages/opencode/dist
  232. - name: Setup git committer
  233. id: committer
  234. uses: ./.github/actions/setup-git-committer
  235. with:
  236. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  237. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  238. - name: Azure login
  239. uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2.3.0
  240. with:
  241. client-id: ${{ env.AZURE_CLIENT_ID }}
  242. tenant-id: ${{ env.AZURE_TENANT_ID }}
  243. subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}
  244. - uses: azure/artifact-signing-action@b443cf8ea4124818d2ea9f043cba29fc3ec47b16 # v1.2.0
  245. with:
  246. endpoint: ${{ env.AZURE_TRUSTED_SIGNING_ENDPOINT }}
  247. signing-account-name: ${{ env.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
  248. certificate-profile-name: ${{ env.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE }}
  249. files: |
  250. ${{ github.workspace }}\packages\opencode\dist\opencode-windows-arm64\bin\opencode.exe
  251. ${{ github.workspace }}\packages\opencode\dist\opencode-windows-x64\bin\opencode.exe
  252. ${{ github.workspace }}\packages\opencode\dist\opencode-windows-x64-baseline\bin\opencode.exe
  253. exclude-environment-credential: true
  254. exclude-workload-identity-credential: true
  255. exclude-managed-identity-credential: true
  256. exclude-shared-token-cache-credential: true
  257. exclude-visual-studio-credential: true
  258. exclude-visual-studio-code-credential: true
  259. exclude-azure-cli-credential: false
  260. exclude-azure-powershell-credential: true
  261. exclude-azure-developer-cli-credential: true
  262. exclude-interactive-browser-credential: true
  263. - name: Verify Windows CLI signatures
  264. shell: pwsh
  265. run: |
  266. $files = @(
  267. "${{ github.workspace }}\packages\opencode\dist\opencode-windows-arm64\bin\opencode.exe",
  268. "${{ github.workspace }}\packages\opencode\dist\opencode-windows-x64\bin\opencode.exe",
  269. "${{ github.workspace }}\packages\opencode\dist\opencode-windows-x64-baseline\bin\opencode.exe"
  270. )
  271. foreach ($file in $files) {
  272. $sig = Get-AuthenticodeSignature $file
  273. if ($sig.Status -ne "Valid") {
  274. throw "Invalid signature for ${file}: $($sig.Status)"
  275. }
  276. }
  277. - name: Repack Windows CLI archives
  278. working-directory: packages/opencode/dist
  279. shell: pwsh
  280. run: |
  281. Compress-Archive -Path "opencode-windows-arm64\bin\*" -DestinationPath "opencode-windows-arm64.zip" -Force
  282. Compress-Archive -Path "opencode-windows-x64\bin\*" -DestinationPath "opencode-windows-x64.zip" -Force
  283. Compress-Archive -Path "opencode-windows-x64-baseline\bin\*" -DestinationPath "opencode-windows-x64-baseline.zip" -Force
  284. - name: Upload signed Windows CLI release assets
  285. if: needs.version.outputs.release != ''
  286. shell: pwsh
  287. env:
  288. GH_TOKEN: ${{ steps.committer.outputs.token }}
  289. run: |
  290. gh release upload "v${{ needs.version.outputs.version }}" `
  291. "${{ github.workspace }}\packages\opencode\dist\opencode-windows-arm64.zip" `
  292. "${{ github.workspace }}\packages\opencode\dist\opencode-windows-x64.zip" `
  293. "${{ github.workspace }}\packages\opencode\dist\opencode-windows-x64-baseline.zip" `
  294. --clobber `
  295. --repo "${{ needs.version.outputs.repo }}"
  296. - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
  297. with:
  298. name: opencode-cli-signed-windows
  299. path: |
  300. packages/opencode/dist/opencode-windows-arm64
  301. packages/opencode/dist/opencode-windows-x64
  302. packages/opencode/dist/opencode-windows-x64-baseline
  303. build-electron:
  304. needs:
  305. - version
  306. - sign-cli-macos
  307. if: github.repository == 'anomalyco/opencode' && github.ref_name != 'v2'
  308. continue-on-error: false
  309. env:
  310. AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
  311. AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
  312. AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
  313. AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
  314. AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE }}
  315. AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }}
  316. strategy:
  317. fail-fast: false
  318. matrix:
  319. settings:
  320. - host: macos-26-intel
  321. target: x86_64-apple-darwin
  322. platform_flag: --mac --x64
  323. bun_install_flags: --os=darwin --cpu=x64
  324. - host: macos-26
  325. target: aarch64-apple-darwin
  326. platform_flag: --mac --arm64
  327. bun_install_flags: --os=darwin --cpu=arm64
  328. # github-hosted: blacksmith lacks ARM64 MSVC cross-compilation toolchain
  329. - host: "windows-2025"
  330. target: aarch64-pc-windows-msvc
  331. platform_flag: --win --arm64
  332. - host: "blacksmith-4vcpu-windows-2025"
  333. target: x86_64-pc-windows-msvc
  334. platform_flag: --win
  335. - host: "blacksmith-4vcpu-ubuntu-2404"
  336. target: x86_64-unknown-linux-gnu
  337. platform_flag: --linux
  338. - host: "blacksmith-4vcpu-ubuntu-2404-arm"
  339. target: aarch64-unknown-linux-gnu
  340. platform_flag: --linux --arm64
  341. runs-on: ${{ matrix.settings.host }}
  342. steps:
  343. - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
  344. - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
  345. if: github.ref_name == 'beta'
  346. with:
  347. name: opencode-preview-cli
  348. path: packages/cli/dist
  349. - uses: apple-actions/import-codesign-certs@8f3fb608891dd2244cdab3d69cd68c0d37a7fe93 # v2.0.0
  350. if: runner.os == 'macOS'
  351. with:
  352. keychain: build
  353. p12-file-base64: ${{ secrets.APPLE_CERTIFICATE }}
  354. p12-password: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  355. - name: Setup Apple API Key
  356. if: runner.os == 'macOS'
  357. run: echo "${{ secrets.APPLE_API_KEY_PATH }}" > $RUNNER_TEMP/apple-api-key.p8
  358. - uses: ./.github/actions/setup-bun
  359. with:
  360. install-flags: ${{ matrix.settings.bun_install_flags }}
  361. - name: Azure login
  362. if: runner.os == 'Windows'
  363. uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5 # v2.3.0
  364. with:
  365. client-id: ${{ env.AZURE_CLIENT_ID }}
  366. tenant-id: ${{ env.AZURE_TENANT_ID }}
  367. subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}
  368. - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
  369. with:
  370. node-version: "24"
  371. - name: Cache apt packages
  372. if: contains(matrix.settings.host, 'ubuntu')
  373. uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
  374. with:
  375. path: ~/apt-cache
  376. key: ${{ runner.os }}-${{ matrix.settings.target }}-apt-electron-${{ hashFiles('.github/workflows/publish.yml') }}
  377. restore-keys: |
  378. ${{ runner.os }}-${{ matrix.settings.target }}-apt-electron-
  379. - name: Install dependencies (ubuntu only)
  380. if: contains(matrix.settings.host, 'ubuntu')
  381. run: |
  382. mkdir -p ~/apt-cache && chmod -R a+rw ~/apt-cache
  383. sudo apt-get update
  384. sudo apt-get install -y --no-install-recommends -o dir::cache::archives="$HOME/apt-cache" rpm
  385. sudo chmod -R a+rw ~/apt-cache
  386. - name: Setup git committer
  387. id: committer
  388. uses: ./.github/actions/setup-git-committer
  389. with:
  390. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  391. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  392. - name: Prepare
  393. run: bun ./scripts/prepare.ts
  394. working-directory: packages/desktop
  395. env:
  396. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  397. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  398. OPENCODE_CLI_TARGET: ${{ matrix.settings.target }}
  399. OPENCODE_CLI_DIST: ${{ (github.ref_name == 'beta' && format('{0}/packages/cli/dist', github.workspace)) || '' }}
  400. - name: Build
  401. run: bun run build
  402. working-directory: packages/desktop
  403. env:
  404. NODE_OPTIONS: --max-old-space-size=4096
  405. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  406. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  407. SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
  408. SENTRY_ORG: ${{ vars.SENTRY_ORG }}
  409. SENTRY_PROJECT: ${{ vars.WEB_SENTRY_PROJECT }}
  410. SENTRY_RELEASE: desktop@${{ needs.version.outputs.version }}
  411. VITE_SENTRY_DSN: ${{ vars.WEB_SENTRY_DSN }}
  412. VITE_SENTRY_ENVIRONMENT: ${{ (github.ref_name == 'beta' && 'beta') || 'production' }}
  413. VITE_SENTRY_RELEASE: desktop@${{ needs.version.outputs.version }}
  414. OPENCODE_CLI_TARGET: ${{ matrix.settings.target }}
  415. - name: Package
  416. if: needs.version.outputs.release
  417. run: npx electron-builder ${{ matrix.settings.platform_flag }} --publish never --config electron-builder.config.ts
  418. working-directory: packages/desktop
  419. timeout-minutes: 60
  420. env:
  421. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  422. GH_TOKEN: ${{ steps.committer.outputs.token }}
  423. CSC_KEYCHAIN: build.keychain
  424. APPLE_API_KEY: ${{ runner.temp }}/apple-api-key.p8
  425. APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY }}
  426. APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
  427. - name: Package (no publish)
  428. if: ${{ !needs.version.outputs.release }}
  429. run: npx electron-builder ${{ matrix.settings.platform_flag }} --publish never --config electron-builder.config.ts
  430. working-directory: packages/desktop
  431. timeout-minutes: 60
  432. env:
  433. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  434. - name: Create macOS .app.tar.gz
  435. if: runner.os == 'macOS' && needs.version.outputs.release
  436. working-directory: packages/desktop/dist
  437. run: |
  438. if [[ "${{ matrix.settings.target }}" == "x86_64-apple-darwin" ]]; then
  439. APP_DIR="mac"
  440. OUT_NAME="opencode-desktop-mac-x64.app.tar.gz"
  441. elif [[ "${{ matrix.settings.target }}" == "aarch64-apple-darwin" ]]; then
  442. APP_DIR="mac-arm64"
  443. OUT_NAME="opencode-desktop-mac-arm64.app.tar.gz"
  444. else
  445. echo "Unknown macOS target: ${{ matrix.settings.target }}"
  446. exit 1
  447. fi
  448. APP_PATH=$(find "$APP_DIR" -maxdepth 1 -name "*.app" -type d | head -1)
  449. if [ -z "$APP_PATH" ]; then
  450. echo "No .app bundle found in $APP_DIR"
  451. exit 1
  452. fi
  453. tar -czf "$OUT_NAME" -C "$(dirname "$APP_PATH")" "$(basename "$APP_PATH")"
  454. - name: Verify signed Windows Electron artifacts
  455. if: runner.os == 'Windows'
  456. shell: pwsh
  457. run: |
  458. $files = @()
  459. $files += Get-ChildItem "${{ github.workspace }}\packages\desktop\dist\*.exe" | Select-Object -ExpandProperty FullName
  460. $files += Get-ChildItem "${{ github.workspace }}\packages\desktop\dist\*unpacked\*.exe" | Select-Object -ExpandProperty FullName
  461. $files += Get-ChildItem "${{ github.workspace }}\packages\desktop\dist\*unpacked\resources\opencode-cli.exe" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
  462. foreach ($file in $files | Select-Object -Unique) {
  463. $sig = Get-AuthenticodeSignature $file
  464. if ($sig.Status -ne "Valid") {
  465. throw "Invalid signature for ${file}: $($sig.Status)"
  466. }
  467. }
  468. - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
  469. with:
  470. name: opencode-desktop-${{ matrix.settings.target }}
  471. path: packages/desktop/dist/*
  472. - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
  473. if: needs.version.outputs.release
  474. with:
  475. name: latest-yml-${{ matrix.settings.target }}
  476. path: packages/desktop/dist/latest*.yml
  477. publish:
  478. needs:
  479. - version
  480. - build-cli
  481. - sign-cli-macos
  482. - build-node-cli
  483. - sign-cli-windows
  484. - build-electron
  485. if: always() && !failure() && !cancelled()
  486. runs-on: blacksmith-4vcpu-ubuntu-2404
  487. steps:
  488. - uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
  489. - uses: ./.github/actions/setup-bun
  490. - name: Login to GitHub Container Registry
  491. uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
  492. with:
  493. registry: ghcr.io
  494. username: ${{ github.repository_owner }}
  495. password: ${{ secrets.GITHUB_TOKEN }}
  496. - name: Set up QEMU
  497. uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
  498. - name: Set up Docker Buildx
  499. uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
  500. - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
  501. with:
  502. node-version: "24"
  503. registry-url: "https://registry.npmjs.org"
  504. - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
  505. if: github.ref_name != 'v2' && github.ref_name != 'beta'
  506. with:
  507. name: opencode-cli
  508. path: packages/opencode/dist
  509. - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
  510. if: github.ref_name != 'v2' && github.ref_name != 'beta'
  511. with:
  512. name: opencode-cli-windows
  513. path: packages/opencode/dist
  514. - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
  515. if: github.ref_name != 'v2' && github.ref_name != 'beta'
  516. with:
  517. name: opencode-cli-signed-windows
  518. path: packages/opencode/dist
  519. - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
  520. with:
  521. name: opencode-preview-cli
  522. path: packages/cli/dist
  523. - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
  524. with:
  525. pattern: opencode-node-cli-*
  526. path: packages/cli/dist/node
  527. merge-multiple: true
  528. - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
  529. if: needs.version.outputs.release
  530. with:
  531. pattern: latest-yml-*
  532. path: /tmp/latest-yml
  533. - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
  534. if: needs.version.outputs.release
  535. with:
  536. pattern: opencode-desktop-*
  537. path: /tmp/desktop
  538. merge-multiple: true
  539. - name: Setup git committer
  540. id: committer
  541. uses: ./.github/actions/setup-git-committer
  542. with:
  543. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  544. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  545. - name: Cache apt packages (AUR)
  546. uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
  547. with:
  548. path: /var/cache/apt/archives
  549. key: ${{ runner.os }}-apt-aur-${{ hashFiles('.github/workflows/publish.yml') }}
  550. restore-keys: |
  551. ${{ runner.os }}-apt-aur-
  552. - name: Setup SSH for AUR
  553. run: |
  554. sudo apt-get update
  555. sudo apt-get install -y pacman-package-manager
  556. mkdir -p ~/.ssh
  557. echo "${{ secrets.AUR_KEY }}" > ~/.ssh/id_rsa
  558. chmod 600 ~/.ssh/id_rsa
  559. git config --global user.email "opencode@sst.dev"
  560. git config --global user.name "opencode"
  561. ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts || true
  562. - name: Upload desktop release assets
  563. if: needs.version.outputs.release
  564. env:
  565. GH_TOKEN: ${{ steps.committer.outputs.token }}
  566. run: |
  567. shopt -s nullglob
  568. files=(/tmp/desktop/*.{exe,blockmap,dmg,zip,AppImage,deb,rpm} /tmp/desktop/*.app.tar.gz)
  569. if (( ${#files[@]} == 0 )); then
  570. echo "No desktop release assets found"
  571. exit 1
  572. fi
  573. gh release upload "v${{ needs.version.outputs.version }}" "${files[@]}" --clobber --repo "${{ needs.version.outputs.repo }}"
  574. - run: ./script/publish.ts
  575. env:
  576. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  577. OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
  578. AUR_KEY: ${{ secrets.AUR_KEY }}
  579. GITHUB_TOKEN: ${{ steps.committer.outputs.token }}
  580. GH_REPO: ${{ needs.version.outputs.repo }}
  581. NPM_CONFIG_PROVENANCE: false
  582. LATEST_YML_DIR: /tmp/latest-yml
  583. TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
  584. TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}