publish.yml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. with:
  71. cross-compile: "true"
  72. - name: Setup git committer
  73. id: committer
  74. uses: ./.github/actions/setup-git-committer
  75. with:
  76. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  77. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  78. - name: Build
  79. id: build
  80. run: |
  81. ./packages/opencode/script/build.ts --all
  82. env:
  83. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  84. OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
  85. GH_REPO: ${{ needs.version.outputs.repo }}
  86. GH_TOKEN: ${{ steps.committer.outputs.token }}
  87. - uses: actions/upload-artifact@v4
  88. with:
  89. name: opencode-cli
  90. path: packages/opencode/dist
  91. outputs:
  92. version: ${{ needs.version.outputs.version }}
  93. build-tauri:
  94. needs:
  95. - build-cli
  96. - version
  97. continue-on-error: false
  98. strategy:
  99. fail-fast: false
  100. matrix:
  101. settings:
  102. - host: macos-latest
  103. target: x86_64-apple-darwin
  104. - host: macos-latest
  105. target: aarch64-apple-darwin
  106. - host: blacksmith-4vcpu-windows-2025
  107. target: x86_64-pc-windows-msvc
  108. - host: blacksmith-4vcpu-ubuntu-2404
  109. target: x86_64-unknown-linux-gnu
  110. - host: blacksmith-8vcpu-ubuntu-2404-arm
  111. target: aarch64-unknown-linux-gnu
  112. runs-on: ${{ matrix.settings.host }}
  113. steps:
  114. - uses: actions/checkout@v3
  115. with:
  116. fetch-tags: true
  117. - uses: apple-actions/import-codesign-certs@v2
  118. if: ${{ runner.os == 'macOS' }}
  119. with:
  120. keychain: build
  121. p12-file-base64: ${{ secrets.APPLE_CERTIFICATE }}
  122. p12-password: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  123. - name: Verify Certificate
  124. if: ${{ runner.os == 'macOS' }}
  125. run: |
  126. CERT_INFO=$(security find-identity -v -p codesigning build.keychain | grep "Developer ID Application")
  127. CERT_ID=$(echo "$CERT_INFO" | awk -F'"' '{print $2}')
  128. echo "CERT_ID=$CERT_ID" >> $GITHUB_ENV
  129. echo "Certificate imported."
  130. - name: Setup Apple API Key
  131. if: ${{ runner.os == 'macOS' }}
  132. run: |
  133. echo "${{ secrets.APPLE_API_KEY_PATH }}" > $RUNNER_TEMP/apple-api-key.p8
  134. - uses: ./.github/actions/setup-bun
  135. - name: Cache apt packages
  136. if: contains(matrix.settings.host, 'ubuntu')
  137. uses: actions/cache@v4
  138. with:
  139. path: ~/apt-cache
  140. key: ${{ runner.os }}-${{ matrix.settings.target }}-apt-${{ hashFiles('.github/workflows/publish.yml') }}
  141. restore-keys: |
  142. ${{ runner.os }}-${{ matrix.settings.target }}-apt-
  143. - name: install dependencies (ubuntu only)
  144. if: contains(matrix.settings.host, 'ubuntu')
  145. run: |
  146. mkdir -p ~/apt-cache && chmod -R a+rw ~/apt-cache
  147. sudo apt-get update
  148. sudo apt-get install -y --no-install-recommends -o dir::cache::archives="$HOME/apt-cache" libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
  149. sudo chmod -R a+rw ~/apt-cache
  150. - name: install Rust stable
  151. uses: dtolnay/rust-toolchain@stable
  152. with:
  153. targets: ${{ matrix.settings.target }}
  154. - uses: Swatinem/rust-cache@v2
  155. with:
  156. workspaces: packages/desktop/src-tauri
  157. shared-key: ${{ matrix.settings.target }}
  158. - name: Prepare
  159. run: |
  160. cd packages/desktop
  161. bun ./scripts/prepare.ts
  162. env:
  163. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  164. GITHUB_TOKEN: ${{ steps.committer.outputs.token }}
  165. RUST_TARGET: ${{ matrix.settings.target }}
  166. GH_TOKEN: ${{ github.token }}
  167. GITHUB_RUN_ID: ${{ github.run_id }}
  168. - name: Resolve tauri portable SHA
  169. if: contains(matrix.settings.host, 'ubuntu')
  170. run: echo "TAURI_PORTABLE_SHA=$(git ls-remote https://github.com/tauri-apps/tauri.git refs/heads/feat/truly-portable-appimage | cut -f1)" >> "$GITHUB_ENV"
  171. # Fixes AppImage build issues, can be removed when https://github.com/tauri-apps/tauri/pull/12491 is released
  172. - name: Install tauri-cli from portable appimage branch
  173. uses: taiki-e/cache-cargo-install-action@v3
  174. if: contains(matrix.settings.host, 'ubuntu')
  175. with:
  176. tool: tauri-cli
  177. git: https://github.com/tauri-apps/tauri
  178. # branch: feat/truly-portable-appimage
  179. rev: ${{ env.TAURI_PORTABLE_SHA }}
  180. - name: Show tauri-cli version
  181. if: contains(matrix.settings.host, 'ubuntu')
  182. run: cargo tauri --version
  183. - name: Setup git committer
  184. id: committer
  185. uses: ./.github/actions/setup-git-committer
  186. with:
  187. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  188. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  189. - name: Build and upload artifacts
  190. uses: tauri-apps/tauri-action@390cbe447412ced1303d35abe75287949e43437a
  191. timeout-minutes: 60
  192. with:
  193. projectPath: packages/desktop
  194. uploadWorkflowArtifacts: true
  195. tauriScript: ${{ (contains(matrix.settings.host, 'ubuntu') && 'cargo tauri') || '' }}
  196. args: --target ${{ matrix.settings.target }} --config ${{ (github.ref_name == 'beta' && './src-tauri/tauri.beta.conf.json') || './src-tauri/tauri.prod.conf.json' }} --verbose
  197. updaterJsonPreferNsis: true
  198. releaseId: ${{ needs.version.outputs.release }}
  199. tagName: ${{ needs.version.outputs.tag }}
  200. releaseDraft: true
  201. releaseAssetNamePattern: opencode-desktop-[platform]-[arch][ext]
  202. repo: ${{ (github.ref_name == 'beta' && 'opencode-beta') || '' }}
  203. releaseCommitish: ${{ github.sha }}
  204. env:
  205. GITHUB_TOKEN: ${{ steps.committer.outputs.token }}
  206. TAURI_BUNDLER_NEW_APPIMAGE_FORMAT: true
  207. TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
  208. TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
  209. APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
  210. APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  211. APPLE_SIGNING_IDENTITY: ${{ env.CERT_ID }}
  212. APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
  213. APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
  214. APPLE_API_KEY_PATH: ${{ runner.temp }}/apple-api-key.p8
  215. publish:
  216. needs:
  217. - version
  218. - build-cli
  219. - build-tauri
  220. runs-on: blacksmith-4vcpu-ubuntu-2404
  221. steps:
  222. - uses: actions/checkout@v3
  223. - uses: ./.github/actions/setup-bun
  224. - name: Login to GitHub Container Registry
  225. uses: docker/login-action@v3
  226. with:
  227. registry: ghcr.io
  228. username: ${{ github.repository_owner }}
  229. password: ${{ secrets.GITHUB_TOKEN }}
  230. - name: Set up QEMU
  231. uses: docker/setup-qemu-action@v3
  232. - name: Set up Docker Buildx
  233. uses: docker/setup-buildx-action@v3
  234. - uses: actions/setup-node@v4
  235. with:
  236. node-version: "24"
  237. registry-url: "https://registry.npmjs.org"
  238. - name: Setup git committer
  239. id: committer
  240. uses: ./.github/actions/setup-git-committer
  241. with:
  242. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  243. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  244. - uses: actions/download-artifact@v4
  245. with:
  246. name: opencode-cli
  247. path: packages/opencode/dist
  248. - name: Cache apt packages (AUR)
  249. uses: actions/cache@v4
  250. with:
  251. path: /var/cache/apt/archives
  252. key: ${{ runner.os }}-apt-aur-${{ hashFiles('.github/workflows/publish.yml') }}
  253. restore-keys: |
  254. ${{ runner.os }}-apt-aur-
  255. - name: Setup SSH for AUR
  256. run: |
  257. sudo apt-get update
  258. sudo apt-get install -y pacman-package-manager
  259. mkdir -p ~/.ssh
  260. echo "${{ secrets.AUR_KEY }}" > ~/.ssh/id_rsa
  261. chmod 600 ~/.ssh/id_rsa
  262. git config --global user.email "opencode@sst.dev"
  263. git config --global user.name "opencode"
  264. ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts || true
  265. - run: ./script/publish.ts
  266. env:
  267. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  268. OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
  269. AUR_KEY: ${{ secrets.AUR_KEY }}
  270. GITHUB_TOKEN: ${{ steps.committer.outputs.token }}
  271. GH_REPO: ${{ needs.version.outputs.repo }}
  272. NPM_CONFIG_PROVENANCE: false