publish.yml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. timeout-minutes: 30
  33. if: github.repository == 'anomalyco/opencode'
  34. steps:
  35. - uses: actions/checkout@v4
  36. with:
  37. fetch-depth: 0
  38. - uses: ./.github/actions/setup-bun
  39. - name: Install OpenCode
  40. if: inputs.bump || inputs.version
  41. run: bun i -g opencode-ai
  42. - id: version
  43. run: |
  44. ./script/version.ts
  45. env:
  46. GH_TOKEN: ${{ github.token }}
  47. OPENCODE_BUMP: ${{ inputs.bump }}
  48. OPENCODE_VERSION: ${{ inputs.version }}
  49. OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
  50. outputs:
  51. version: ${{ steps.version.outputs.version }}
  52. release: ${{ steps.version.outputs.release }}
  53. tag: ${{ steps.version.outputs.tag }}
  54. build-cli:
  55. needs: version
  56. runs-on: blacksmith-4vcpu-ubuntu-2404
  57. if: github.repository == 'anomalyco/opencode'
  58. steps:
  59. - uses: actions/checkout@v4
  60. with:
  61. fetch-tags: true
  62. - uses: ./.github/actions/setup-bun
  63. - name: Build
  64. id: build
  65. run: |
  66. ./packages/opencode/script/build.ts
  67. env:
  68. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  69. OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
  70. GH_TOKEN: ${{ github.token }}
  71. - uses: actions/upload-artifact@v4
  72. with:
  73. name: opencode-cli
  74. path: packages/opencode/dist
  75. outputs:
  76. version: ${{ needs.version.outputs.version }}
  77. build-tauri:
  78. needs:
  79. - build-cli
  80. - version
  81. continue-on-error: false
  82. strategy:
  83. fail-fast: false
  84. matrix:
  85. settings:
  86. - host: macos-latest
  87. target: x86_64-apple-darwin
  88. - host: macos-latest
  89. target: aarch64-apple-darwin
  90. - host: blacksmith-4vcpu-windows-2025
  91. target: x86_64-pc-windows-msvc
  92. - host: blacksmith-4vcpu-ubuntu-2404
  93. target: x86_64-unknown-linux-gnu
  94. - host: blacksmith-8vcpu-ubuntu-2404-arm
  95. target: aarch64-unknown-linux-gnu
  96. runs-on: ${{ matrix.settings.host }}
  97. steps:
  98. - uses: actions/checkout@v4
  99. with:
  100. fetch-tags: true
  101. - uses: apple-actions/import-codesign-certs@v2
  102. if: ${{ runner.os == 'macOS' }}
  103. with:
  104. keychain: build
  105. p12-file-base64: ${{ secrets.APPLE_CERTIFICATE }}
  106. p12-password: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  107. - name: Verify Certificate
  108. if: ${{ runner.os == 'macOS' }}
  109. run: |
  110. CERT_INFO=$(security find-identity -v -p codesigning build.keychain | grep "Developer ID Application")
  111. CERT_ID=$(echo "$CERT_INFO" | awk -F'"' '{print $2}')
  112. echo "CERT_ID=$CERT_ID" >> $GITHUB_ENV
  113. echo "Certificate imported."
  114. - name: Setup Apple API Key
  115. if: ${{ runner.os == 'macOS' }}
  116. run: |
  117. echo "${{ secrets.APPLE_API_KEY_PATH }}" > $RUNNER_TEMP/apple-api-key.p8
  118. - uses: ./.github/actions/setup-bun
  119. - name: Cache apt packages
  120. if: contains(matrix.settings.host, 'ubuntu')
  121. uses: actions/cache@v4
  122. with:
  123. path: /var/cache/apt/archives
  124. key: ${{ runner.os }}-${{ matrix.settings.target }}-apt-${{ hashFiles('.github/workflows/publish.yml') }}
  125. restore-keys: |
  126. ${{ runner.os }}-${{ matrix.settings.target }}-apt-
  127. - name: install dependencies (ubuntu only)
  128. if: contains(matrix.settings.host, 'ubuntu')
  129. run: |
  130. sudo apt-get update
  131. sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
  132. - name: install Rust stable
  133. uses: dtolnay/rust-toolchain@stable
  134. with:
  135. targets: ${{ matrix.settings.target }}
  136. - uses: Swatinem/rust-cache@v2
  137. with:
  138. workspaces: packages/desktop/src-tauri
  139. shared-key: ${{ matrix.settings.target }}
  140. - name: Prepare
  141. run: |
  142. cd packages/desktop
  143. bun ./scripts/prepare.ts
  144. env:
  145. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  146. GITHUB_TOKEN: ${{ steps.committer.outputs.token }}
  147. RUST_TARGET: ${{ matrix.settings.target }}
  148. GH_TOKEN: ${{ github.token }}
  149. GITHUB_RUN_ID: ${{ github.run_id }}
  150. # Fixes AppImage build issues, can be removed when https://github.com/tauri-apps/tauri/pull/12491 is released
  151. - name: Install tauri-cli from portable appimage branch
  152. if: contains(matrix.settings.host, 'ubuntu')
  153. run: |
  154. cargo install tauri-cli --git https://github.com/tauri-apps/tauri --branch feat/truly-portable-appimage --force
  155. echo "Installed tauri-cli version:"
  156. cargo tauri --version
  157. - name: Build and upload artifacts
  158. uses: tauri-apps/tauri-action@390cbe447412ced1303d35abe75287949e43437a
  159. timeout-minutes: 60
  160. with:
  161. projectPath: packages/desktop
  162. uploadWorkflowArtifacts: true
  163. tauriScript: ${{ (contains(matrix.settings.host, 'ubuntu') && 'cargo tauri') || '' }}
  164. args: --target ${{ matrix.settings.target }} --config ./src-tauri/tauri.prod.conf.json --verbose
  165. updaterJsonPreferNsis: true
  166. releaseId: ${{ needs.version.outputs.release }}
  167. tagName: ${{ needs.version.outputs.tag }}
  168. releaseDraft: true
  169. releaseAssetNamePattern: opencode-desktop-[platform]-[arch][ext]
  170. env:
  171. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  172. TAURI_BUNDLER_NEW_APPIMAGE_FORMAT: true
  173. TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
  174. TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
  175. APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
  176. APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  177. APPLE_SIGNING_IDENTITY: ${{ env.CERT_ID }}
  178. APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
  179. APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
  180. APPLE_API_KEY_PATH: ${{ runner.temp }}/apple-api-key.p8
  181. publish:
  182. needs:
  183. - version
  184. - build-cli
  185. - build-tauri
  186. runs-on: blacksmith-4vcpu-ubuntu-2404
  187. timeout-minutes: 60
  188. steps:
  189. - uses: actions/checkout@v4
  190. - uses: ./.github/actions/setup-bun
  191. - name: Login to GitHub Container Registry
  192. uses: docker/login-action@v3
  193. with:
  194. registry: ghcr.io
  195. username: ${{ github.repository_owner }}
  196. password: ${{ secrets.GITHUB_TOKEN }}
  197. - name: Set up QEMU
  198. uses: docker/setup-qemu-action@v3
  199. - name: Set up Docker Buildx
  200. uses: docker/setup-buildx-action@v3
  201. - uses: actions/setup-node@v4
  202. with:
  203. node-version: "24"
  204. registry-url: "https://registry.npmjs.org"
  205. - name: Setup git committer
  206. id: committer
  207. uses: ./.github/actions/setup-git-committer
  208. with:
  209. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  210. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  211. - uses: actions/download-artifact@v4
  212. with:
  213. name: opencode-cli
  214. path: packages/opencode/dist
  215. - name: Cache apt packages (AUR)
  216. uses: actions/cache@v4
  217. with:
  218. path: /var/cache/apt/archives
  219. key: ${{ runner.os }}-apt-aur-${{ hashFiles('.github/workflows/publish.yml') }}
  220. restore-keys: |
  221. ${{ runner.os }}-apt-aur-
  222. - name: Setup SSH for AUR
  223. run: |
  224. sudo apt-get update
  225. sudo apt-get install -y pacman-package-manager
  226. mkdir -p ~/.ssh
  227. echo "${{ secrets.AUR_KEY }}" > ~/.ssh/id_rsa
  228. chmod 600 ~/.ssh/id_rsa
  229. git config --global user.email "[email protected]"
  230. git config --global user.name "opencode"
  231. ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts || true
  232. - run: ./script/publish.ts
  233. env:
  234. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  235. OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
  236. AUR_KEY: ${{ secrets.AUR_KEY }}
  237. GITHUB_TOKEN: ${{ steps.committer.outputs.token }}
  238. NPM_CONFIG_PROVENANCE: false