publish.yml 8.7 KB

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