publish.yml 8.7 KB

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