publish.yml 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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: ~/apt-cache
  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. mkdir -p ~/apt-cache && chmod -R a+rw ~/apt-cache
  130. sudo apt-get update
  131. sudo apt-get install -y --no-install-recommends -o dir::cache::archives="$HOME/apt-cache" libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
  132. sudo chmod -R a+rw ~/apt-cache
  133. - name: install Rust stable
  134. uses: dtolnay/rust-toolchain@stable
  135. with:
  136. targets: ${{ matrix.settings.target }}
  137. - uses: Swatinem/rust-cache@v2
  138. with:
  139. workspaces: packages/desktop/src-tauri
  140. shared-key: ${{ matrix.settings.target }}
  141. - name: Prepare
  142. run: |
  143. cd packages/desktop
  144. bun ./scripts/prepare.ts
  145. env:
  146. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  147. GITHUB_TOKEN: ${{ steps.committer.outputs.token }}
  148. RUST_TARGET: ${{ matrix.settings.target }}
  149. GH_TOKEN: ${{ github.token }}
  150. GITHUB_RUN_ID: ${{ github.run_id }}
  151. - name: Resolve tauri portable SHA
  152. if: contains(matrix.settings.host, 'ubuntu')
  153. 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"
  154. # Fixes AppImage build issues, can be removed when https://github.com/tauri-apps/tauri/pull/12491 is released
  155. - name: Install tauri-cli from portable appimage branch
  156. uses: taiki-e/cache-cargo-install-action@v3
  157. if: contains(matrix.settings.host, 'ubuntu')
  158. with:
  159. tool: tauri-cli
  160. git: https://github.com/tauri-apps/tauri
  161. # branch: feat/truly-portable-appimage
  162. rev: ${{ env.TAURI_PORTABLE_SHA }}
  163. - name: Show tauri-cli version
  164. if: contains(matrix.settings.host, 'ubuntu')
  165. run: cargo tauri --version
  166. - name: Build and upload artifacts
  167. uses: tauri-apps/tauri-action@390cbe447412ced1303d35abe75287949e43437a
  168. timeout-minutes: 60
  169. with:
  170. projectPath: packages/desktop
  171. uploadWorkflowArtifacts: true
  172. tauriScript: ${{ (contains(matrix.settings.host, 'ubuntu') && 'cargo tauri') || '' }}
  173. args: --target ${{ matrix.settings.target }} --config ./src-tauri/tauri.prod.conf.json --verbose
  174. updaterJsonPreferNsis: true
  175. releaseId: ${{ needs.version.outputs.release }}
  176. tagName: ${{ needs.version.outputs.tag }}
  177. releaseDraft: true
  178. releaseAssetNamePattern: opencode-desktop-[platform]-[arch][ext]
  179. env:
  180. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  181. TAURI_BUNDLER_NEW_APPIMAGE_FORMAT: true
  182. TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
  183. TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
  184. APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
  185. APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  186. APPLE_SIGNING_IDENTITY: ${{ env.CERT_ID }}
  187. APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
  188. APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
  189. APPLE_API_KEY_PATH: ${{ runner.temp }}/apple-api-key.p8
  190. publish:
  191. needs:
  192. - version
  193. - build-cli
  194. - build-tauri
  195. runs-on: blacksmith-4vcpu-ubuntu-2404
  196. steps:
  197. - uses: actions/checkout@v3
  198. - uses: ./.github/actions/setup-bun
  199. - name: Login to GitHub Container Registry
  200. uses: docker/login-action@v3
  201. with:
  202. registry: ghcr.io
  203. username: ${{ github.repository_owner }}
  204. password: ${{ secrets.GITHUB_TOKEN }}
  205. - name: Set up QEMU
  206. uses: docker/setup-qemu-action@v3
  207. - name: Set up Docker Buildx
  208. uses: docker/setup-buildx-action@v3
  209. - uses: actions/setup-node@v4
  210. with:
  211. node-version: "24"
  212. registry-url: "https://registry.npmjs.org"
  213. - name: Setup git committer
  214. id: committer
  215. uses: ./.github/actions/setup-git-committer
  216. with:
  217. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  218. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  219. - uses: actions/download-artifact@v4
  220. with:
  221. name: opencode-cli
  222. path: packages/opencode/dist
  223. - name: Cache apt packages (AUR)
  224. uses: actions/cache@v4
  225. with:
  226. path: /var/cache/apt/archives
  227. key: ${{ runner.os }}-apt-aur-${{ hashFiles('.github/workflows/publish.yml') }}
  228. restore-keys: |
  229. ${{ runner.os }}-apt-aur-
  230. - name: Setup SSH for AUR
  231. run: |
  232. sudo apt-get update
  233. sudo apt-get install -y pacman-package-manager
  234. mkdir -p ~/.ssh
  235. echo "${{ secrets.AUR_KEY }}" > ~/.ssh/id_rsa
  236. chmod 600 ~/.ssh/id_rsa
  237. git config --global user.email "[email protected]"
  238. git config --global user.name "opencode"
  239. ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts || true
  240. - run: ./script/publish.ts
  241. env:
  242. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  243. OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
  244. AUR_KEY: ${{ secrets.AUR_KEY }}
  245. GITHUB_TOKEN: ${{ steps.committer.outputs.token }}
  246. NPM_CONFIG_PROVENANCE: false