publish.yml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. name: publish
  2. run-name: "${{ format('release {0}', inputs.bump) }}"
  3. on:
  4. push:
  5. branches:
  6. - ci
  7. - dev
  8. - beta
  9. - snapshot-*
  10. workflow_dispatch:
  11. inputs:
  12. bump:
  13. description: "Bump major, minor, or patch"
  14. required: false
  15. type: choice
  16. options:
  17. - major
  18. - minor
  19. - patch
  20. version:
  21. description: "Override version (optional)"
  22. required: false
  23. type: string
  24. concurrency: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.version || inputs.bump }}
  25. permissions:
  26. id-token: write
  27. contents: write
  28. packages: write
  29. jobs:
  30. version:
  31. runs-on: blacksmith-4vcpu-ubuntu-2404
  32. if: github.repository == 'anomalyco/opencode'
  33. steps:
  34. - uses: actions/checkout@v3
  35. with:
  36. fetch-depth: 0
  37. - uses: ./.github/actions/setup-bun
  38. - name: Setup git committer
  39. id: committer
  40. uses: ./.github/actions/setup-git-committer
  41. with:
  42. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  43. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  44. - name: Install OpenCode
  45. if: inputs.bump || inputs.version
  46. run: bun i -g opencode-ai
  47. - id: version
  48. run: |
  49. ./script/version.ts
  50. env:
  51. GH_TOKEN: ${{ steps.committer.outputs.token }}
  52. OPENCODE_BUMP: ${{ inputs.bump }}
  53. OPENCODE_VERSION: ${{ inputs.version }}
  54. OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
  55. GH_REPO: ${{ (github.ref_name == 'beta' && 'anomalyco/opencode-beta') || github.repository }}
  56. outputs:
  57. version: ${{ steps.version.outputs.version }}
  58. release: ${{ steps.version.outputs.release }}
  59. tag: ${{ steps.version.outputs.tag }}
  60. repo: ${{ steps.version.outputs.repo }}
  61. build-cli:
  62. needs: version
  63. runs-on: blacksmith-4vcpu-ubuntu-2404
  64. if: github.repository == 'anomalyco/opencode'
  65. steps:
  66. - uses: actions/checkout@v3
  67. with:
  68. fetch-tags: true
  69. - uses: ./.github/actions/setup-bun
  70. - name: Setup git committer
  71. id: committer
  72. uses: ./.github/actions/setup-git-committer
  73. with:
  74. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  75. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  76. - name: Build
  77. id: build
  78. run: |
  79. ./packages/opencode/script/build.ts ${{ (github.ref_name == 'beta' && '--sourcemaps') || '' }}
  80. env:
  81. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  82. OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
  83. GH_REPO: ${{ needs.version.outputs.repo }}
  84. GH_TOKEN: ${{ steps.committer.outputs.token }}
  85. - uses: actions/upload-artifact@v4
  86. with:
  87. name: opencode-cli
  88. path: |
  89. packages/opencode/dist/opencode-darwin*
  90. packages/opencode/dist/opencode-linux*
  91. - uses: actions/upload-artifact@v4
  92. with:
  93. name: opencode-cli-windows
  94. path: packages/opencode/dist/opencode-windows*
  95. outputs:
  96. version: ${{ needs.version.outputs.version }}
  97. sign-cli-windows:
  98. needs:
  99. - build-cli
  100. - version
  101. runs-on: blacksmith-4vcpu-windows-2025
  102. if: github.repository == 'anomalyco/opencode'
  103. env:
  104. AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
  105. AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
  106. AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
  107. AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
  108. AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE }}
  109. AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }}
  110. steps:
  111. - uses: actions/checkout@v3
  112. - uses: actions/download-artifact@v4
  113. with:
  114. name: opencode-cli-windows
  115. path: packages/opencode/dist
  116. - name: Setup git committer
  117. id: committer
  118. uses: ./.github/actions/setup-git-committer
  119. with:
  120. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  121. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  122. - name: Azure login
  123. uses: azure/login@v2
  124. with:
  125. client-id: ${{ env.AZURE_CLIENT_ID }}
  126. tenant-id: ${{ env.AZURE_TENANT_ID }}
  127. subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}
  128. - uses: azure/artifact-signing-action@v1
  129. with:
  130. endpoint: ${{ env.AZURE_TRUSTED_SIGNING_ENDPOINT }}
  131. signing-account-name: ${{ env.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
  132. certificate-profile-name: ${{ env.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE }}
  133. files: |
  134. ${{ github.workspace }}\packages\opencode\dist\opencode-windows-arm64\bin\opencode.exe
  135. ${{ github.workspace }}\packages\opencode\dist\opencode-windows-x64\bin\opencode.exe
  136. ${{ github.workspace }}\packages\opencode\dist\opencode-windows-x64-baseline\bin\opencode.exe
  137. exclude-environment-credential: true
  138. exclude-workload-identity-credential: true
  139. exclude-managed-identity-credential: true
  140. exclude-shared-token-cache-credential: true
  141. exclude-visual-studio-credential: true
  142. exclude-visual-studio-code-credential: true
  143. exclude-azure-cli-credential: false
  144. exclude-azure-powershell-credential: true
  145. exclude-azure-developer-cli-credential: true
  146. exclude-interactive-browser-credential: true
  147. - name: Verify Windows CLI signatures
  148. shell: pwsh
  149. run: |
  150. $files = @(
  151. "${{ github.workspace }}\packages\opencode\dist\opencode-windows-arm64\bin\opencode.exe",
  152. "${{ github.workspace }}\packages\opencode\dist\opencode-windows-x64\bin\opencode.exe",
  153. "${{ github.workspace }}\packages\opencode\dist\opencode-windows-x64-baseline\bin\opencode.exe"
  154. )
  155. foreach ($file in $files) {
  156. $sig = Get-AuthenticodeSignature $file
  157. if ($sig.Status -ne "Valid") {
  158. throw "Invalid signature for ${file}: $($sig.Status)"
  159. }
  160. }
  161. - name: Repack Windows CLI archives
  162. working-directory: packages/opencode/dist
  163. shell: pwsh
  164. run: |
  165. Compress-Archive -Path "opencode-windows-arm64\bin\*" -DestinationPath "opencode-windows-arm64.zip" -Force
  166. Compress-Archive -Path "opencode-windows-x64\bin\*" -DestinationPath "opencode-windows-x64.zip" -Force
  167. Compress-Archive -Path "opencode-windows-x64-baseline\bin\*" -DestinationPath "opencode-windows-x64-baseline.zip" -Force
  168. - name: Upload signed Windows CLI release assets
  169. if: needs.version.outputs.release != ''
  170. shell: pwsh
  171. env:
  172. GH_TOKEN: ${{ steps.committer.outputs.token }}
  173. run: |
  174. gh release upload "v${{ needs.version.outputs.version }}" `
  175. "${{ github.workspace }}\packages\opencode\dist\opencode-windows-arm64.zip" `
  176. "${{ github.workspace }}\packages\opencode\dist\opencode-windows-x64.zip" `
  177. "${{ github.workspace }}\packages\opencode\dist\opencode-windows-x64-baseline.zip" `
  178. --clobber `
  179. --repo "${{ needs.version.outputs.repo }}"
  180. - uses: actions/upload-artifact@v4
  181. with:
  182. name: opencode-cli-signed-windows
  183. path: |
  184. packages/opencode/dist/opencode-windows-arm64
  185. packages/opencode/dist/opencode-windows-x64
  186. packages/opencode/dist/opencode-windows-x64-baseline
  187. build-electron:
  188. needs:
  189. - build-cli
  190. - version
  191. if: github.repository == 'anomalyco/opencode'
  192. continue-on-error: false
  193. env:
  194. AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
  195. AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
  196. AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
  197. AZURE_TRUSTED_SIGNING_ACCOUNT_NAME: ${{ secrets.AZURE_TRUSTED_SIGNING_ACCOUNT_NAME }}
  198. AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE: ${{ secrets.AZURE_TRUSTED_SIGNING_CERTIFICATE_PROFILE }}
  199. AZURE_TRUSTED_SIGNING_ENDPOINT: ${{ secrets.AZURE_TRUSTED_SIGNING_ENDPOINT }}
  200. strategy:
  201. fail-fast: false
  202. matrix:
  203. settings:
  204. - host: macos-26-intel
  205. target: x86_64-apple-darwin
  206. platform_flag: --mac --x64
  207. bun_install_flags: --os=darwin --cpu=x64
  208. - host: macos-26
  209. target: aarch64-apple-darwin
  210. platform_flag: --mac --arm64
  211. bun_install_flags: --os=darwin --cpu=arm64
  212. # github-hosted: blacksmith lacks ARM64 MSVC cross-compilation toolchain
  213. - host: "windows-2025"
  214. target: aarch64-pc-windows-msvc
  215. platform_flag: --win --arm64
  216. - host: "blacksmith-4vcpu-windows-2025"
  217. target: x86_64-pc-windows-msvc
  218. platform_flag: --win
  219. - host: "blacksmith-4vcpu-ubuntu-2404"
  220. target: x86_64-unknown-linux-gnu
  221. platform_flag: --linux
  222. - host: "blacksmith-4vcpu-ubuntu-2404"
  223. target: aarch64-unknown-linux-gnu
  224. platform_flag: --linux
  225. runs-on: ${{ matrix.settings.host }}
  226. steps:
  227. - uses: actions/checkout@v3
  228. - uses: apple-actions/import-codesign-certs@v2
  229. if: runner.os == 'macOS'
  230. with:
  231. keychain: build
  232. p12-file-base64: ${{ secrets.APPLE_CERTIFICATE }}
  233. p12-password: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  234. - name: Setup Apple API Key
  235. if: runner.os == 'macOS'
  236. run: echo "${{ secrets.APPLE_API_KEY_PATH }}" > $RUNNER_TEMP/apple-api-key.p8
  237. - uses: ./.github/actions/setup-bun
  238. with:
  239. install-flags: ${{ matrix.settings.bun_install_flags }}
  240. - name: Azure login
  241. if: runner.os == 'Windows'
  242. uses: azure/login@v2
  243. with:
  244. client-id: ${{ env.AZURE_CLIENT_ID }}
  245. tenant-id: ${{ env.AZURE_TENANT_ID }}
  246. subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}
  247. - uses: actions/setup-node@v4
  248. with:
  249. node-version: "24"
  250. - name: Cache apt packages
  251. if: contains(matrix.settings.host, 'ubuntu')
  252. uses: actions/cache@v4
  253. with:
  254. path: ~/apt-cache
  255. key: ${{ runner.os }}-${{ matrix.settings.target }}-apt-electron-${{ hashFiles('.github/workflows/publish.yml') }}
  256. restore-keys: |
  257. ${{ runner.os }}-${{ matrix.settings.target }}-apt-electron-
  258. - name: Install dependencies (ubuntu only)
  259. if: contains(matrix.settings.host, 'ubuntu')
  260. run: |
  261. mkdir -p ~/apt-cache && chmod -R a+rw ~/apt-cache
  262. sudo apt-get update
  263. sudo apt-get install -y --no-install-recommends -o dir::cache::archives="$HOME/apt-cache" rpm
  264. sudo chmod -R a+rw ~/apt-cache
  265. - name: Setup git committer
  266. id: committer
  267. uses: ./.github/actions/setup-git-committer
  268. with:
  269. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  270. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  271. - name: Prepare
  272. run: bun ./scripts/prepare.ts
  273. working-directory: packages/desktop-electron
  274. env:
  275. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  276. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  277. OPENCODE_CLI_ARTIFACT: ${{ (runner.os == 'Windows' && 'opencode-cli-windows') || 'opencode-cli' }}
  278. RUST_TARGET: ${{ matrix.settings.target }}
  279. GH_TOKEN: ${{ github.token }}
  280. GITHUB_RUN_ID: ${{ github.run_id }}
  281. - name: Build
  282. run: bun run build
  283. working-directory: packages/desktop-electron
  284. env:
  285. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  286. SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
  287. SENTRY_ORG: ${{ vars.SENTRY_ORG }}
  288. SENTRY_PROJECT: ${{ vars.WEB_SENTRY_PROJECT }}
  289. SENTRY_RELEASE: desktop@${{ needs.version.outputs.version }}
  290. VITE_SENTRY_DSN: ${{ vars.WEB_SENTRY_DSN }}
  291. VITE_SENTRY_ENVIRONMENT: ${{ (github.ref_name == 'beta' && 'beta') || 'production' }}
  292. VITE_SENTRY_RELEASE: desktop@${{ needs.version.outputs.version }}
  293. - name: Package and publish
  294. if: needs.version.outputs.release
  295. run: npx electron-builder ${{ matrix.settings.platform_flag }} --publish always --config electron-builder.config.ts
  296. working-directory: packages/desktop-electron
  297. timeout-minutes: 60
  298. env:
  299. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  300. GH_TOKEN: ${{ steps.committer.outputs.token }}
  301. CSC_LINK: ${{ secrets.APPLE_CERTIFICATE }}
  302. CSC_KEY_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  303. APPLE_API_KEY: ${{ runner.temp }}/apple-api-key.p8
  304. APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY }}
  305. APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
  306. - name: Package (no publish)
  307. if: ${{ !needs.version.outputs.release }}
  308. run: npx electron-builder ${{ matrix.settings.platform_flag }} --publish never --config electron-builder.config.ts
  309. working-directory: packages/desktop-electron
  310. timeout-minutes: 60
  311. env:
  312. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  313. - name: Create and upload macOS .app.tar.gz
  314. if: runner.os == 'macOS' && needs.version.outputs.release
  315. working-directory: packages/desktop-electron/dist
  316. env:
  317. GH_TOKEN: ${{ steps.committer.outputs.token }}
  318. run: |
  319. if [[ "${{ matrix.settings.target }}" == "x86_64-apple-darwin" ]]; then
  320. APP_DIR="mac"
  321. OUT_NAME="opencode-desktop-mac-x64.app.tar.gz"
  322. elif [[ "${{ matrix.settings.target }}" == "aarch64-apple-darwin" ]]; then
  323. APP_DIR="mac-arm64"
  324. OUT_NAME="opencode-desktop-mac-arm64.app.tar.gz"
  325. else
  326. echo "Unknown macOS target: ${{ matrix.settings.target }}"
  327. exit 1
  328. fi
  329. APP_PATH=$(find "$APP_DIR" -maxdepth 1 -name "*.app" -type d | head -1)
  330. if [ -z "$APP_PATH" ]; then
  331. echo "No .app bundle found in $APP_DIR"
  332. exit 1
  333. fi
  334. tar -czf "$OUT_NAME" -C "$(dirname "$APP_PATH")" "$(basename "$APP_PATH")"
  335. gh release upload "v${{ needs.version.outputs.version }}" "$OUT_NAME" --clobber --repo "${{ needs.version.outputs.repo }}"
  336. - name: Verify signed Windows Electron artifacts
  337. if: runner.os == 'Windows'
  338. shell: pwsh
  339. run: |
  340. $files = @()
  341. $files += Get-ChildItem "${{ github.workspace }}\packages\desktop-electron\dist\*.exe" | Select-Object -ExpandProperty FullName
  342. $files += Get-ChildItem "${{ github.workspace }}\packages\desktop-electron\dist\*unpacked\*.exe" | Select-Object -ExpandProperty FullName
  343. $files += Get-ChildItem "${{ github.workspace }}\packages\desktop-electron\dist\*unpacked\resources\opencode-cli.exe" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
  344. foreach ($file in $files | Select-Object -Unique) {
  345. $sig = Get-AuthenticodeSignature $file
  346. if ($sig.Status -ne "Valid") {
  347. throw "Invalid signature for ${file}: $($sig.Status)"
  348. }
  349. }
  350. - uses: actions/upload-artifact@v4
  351. with:
  352. name: opencode-desktop-${{ matrix.settings.target }}
  353. path: packages/desktop-electron/dist/*
  354. - uses: actions/upload-artifact@v4
  355. if: needs.version.outputs.release
  356. with:
  357. name: latest-yml-${{ matrix.settings.target }}
  358. path: packages/desktop-electron/dist/latest*.yml
  359. publish:
  360. needs:
  361. - version
  362. - build-cli
  363. - sign-cli-windows
  364. - build-electron
  365. if: always() && !failure() && !cancelled()
  366. runs-on: blacksmith-4vcpu-ubuntu-2404
  367. steps:
  368. - uses: actions/checkout@v3
  369. - uses: ./.github/actions/setup-bun
  370. - name: Login to GitHub Container Registry
  371. uses: docker/login-action@v3
  372. with:
  373. registry: ghcr.io
  374. username: ${{ github.repository_owner }}
  375. password: ${{ secrets.GITHUB_TOKEN }}
  376. - name: Set up QEMU
  377. uses: docker/setup-qemu-action@v3
  378. - name: Set up Docker Buildx
  379. uses: docker/setup-buildx-action@v3
  380. - uses: actions/setup-node@v4
  381. with:
  382. node-version: "24"
  383. registry-url: "https://registry.npmjs.org"
  384. - uses: actions/download-artifact@v4
  385. with:
  386. name: opencode-cli
  387. path: packages/opencode/dist
  388. - uses: actions/download-artifact@v4
  389. with:
  390. name: opencode-cli-windows
  391. path: packages/opencode/dist
  392. - uses: actions/download-artifact@v4
  393. with:
  394. name: opencode-cli-signed-windows
  395. path: packages/opencode/dist
  396. - uses: actions/download-artifact@v4
  397. if: needs.version.outputs.release
  398. with:
  399. pattern: latest-yml-*
  400. path: /tmp/latest-yml
  401. - name: Setup git committer
  402. id: committer
  403. uses: ./.github/actions/setup-git-committer
  404. with:
  405. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  406. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  407. - name: Cache apt packages (AUR)
  408. uses: actions/cache@v4
  409. with:
  410. path: /var/cache/apt/archives
  411. key: ${{ runner.os }}-apt-aur-${{ hashFiles('.github/workflows/publish.yml') }}
  412. restore-keys: |
  413. ${{ runner.os }}-apt-aur-
  414. - name: Setup SSH for AUR
  415. run: |
  416. sudo apt-get update
  417. sudo apt-get install -y pacman-package-manager
  418. mkdir -p ~/.ssh
  419. echo "${{ secrets.AUR_KEY }}" > ~/.ssh/id_rsa
  420. chmod 600 ~/.ssh/id_rsa
  421. git config --global user.email "opencode@sst.dev"
  422. git config --global user.name "opencode"
  423. ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts || true
  424. - run: ./script/publish.ts
  425. env:
  426. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  427. OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
  428. AUR_KEY: ${{ secrets.AUR_KEY }}
  429. GITHUB_TOKEN: ${{ steps.committer.outputs.token }}
  430. GH_REPO: ${{ needs.version.outputs.repo }}
  431. NPM_CONFIG_PROVENANCE: false
  432. LATEST_YML_DIR: /tmp/latest-yml
  433. TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
  434. TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}