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. - workflow/publish-updates
  10. - snapshot-*
  11. workflow_dispatch:
  12. inputs:
  13. bump:
  14. description: "Bump major, minor, or patch"
  15. required: false
  16. type: choice
  17. options:
  18. - major
  19. - minor
  20. - patch
  21. version:
  22. description: "Override version (optional)"
  23. required: false
  24. type: string
  25. concurrency: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.version || inputs.bump }}
  26. permissions:
  27. id-token: write
  28. contents: write
  29. packages: write
  30. jobs:
  31. version:
  32. runs-on: blacksmith-4vcpu-ubuntu-2404
  33. if: github.repository == 'anomalyco/opencode'
  34. steps:
  35. - uses: actions/checkout@v3
  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. GITHUB_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@v3
  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. GITHUB_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-4vcpu-ubuntu-2404-arm
  95. target: aarch64-unknown-linux-gnu
  96. runs-on: ${{ matrix.settings.host }}
  97. steps:
  98. - uses: actions/checkout@v3
  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. RUST_TARGET: ${{ matrix.settings.target }}
  147. GITHUB_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: ${{ 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: ${{ 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. - uses: actions/download-artifact@v4
  204. with:
  205. name: opencode-cli
  206. path: packages/opencode/dist
  207. - name: Cache apt packages (AUR)
  208. uses: actions/cache@v4
  209. with:
  210. path: /var/cache/apt/archives
  211. key: ${{ runner.os }}-apt-aur-${{ hashFiles('.github/workflows/publish.yml') }}
  212. restore-keys: |
  213. ${{ runner.os }}-apt-aur-
  214. - name: Setup SSH for AUR
  215. run: |
  216. sudo apt-get update
  217. sudo apt-get install -y pacman-package-manager
  218. mkdir -p ~/.ssh
  219. echo "${{ secrets.AUR_KEY }}" > ~/.ssh/id_rsa
  220. chmod 600 ~/.ssh/id_rsa
  221. git config --global user.email "[email protected]"
  222. git config --global user.name "opencode"
  223. ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts || true
  224. - name: Setup git committer
  225. id: committer
  226. uses: ./.github/actions/setup-git-committer
  227. with:
  228. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  229. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  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