publish.yml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. name: publish
  2. run-name: "${{ format('release {0}', inputs.bump) }}"
  3. on:
  4. push:
  5. branches:
  6. - dev
  7. - snapshot-*
  8. workflow_dispatch:
  9. inputs:
  10. bump:
  11. description: "Bump major, minor, or patch"
  12. required: false
  13. type: choice
  14. options:
  15. - major
  16. - minor
  17. - patch
  18. version:
  19. description: "Override version (optional)"
  20. required: false
  21. type: string
  22. concurrency: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.version || inputs.bump }}
  23. permissions:
  24. id-token: write
  25. contents: write
  26. packages: write
  27. jobs:
  28. publish:
  29. runs-on: blacksmith-4vcpu-ubuntu-2404
  30. if: github.repository == 'anomalyco/opencode'
  31. steps:
  32. - uses: actions/checkout@v3
  33. with:
  34. fetch-depth: 0
  35. - run: git fetch --force --tags
  36. - uses: ./.github/actions/setup-bun
  37. - name: Install OpenCode
  38. if: inputs.bump || inputs.version
  39. run: bun i -g [email protected]
  40. - name: Login to GitHub Container Registry
  41. uses: docker/login-action@v3
  42. with:
  43. registry: ghcr.io
  44. username: ${{ github.repository_owner }}
  45. password: ${{ secrets.GITHUB_TOKEN }}
  46. - name: Set up QEMU
  47. uses: docker/setup-qemu-action@v3
  48. - name: Set up Docker Buildx
  49. uses: docker/setup-buildx-action@v3
  50. - uses: actions/setup-node@v4
  51. with:
  52. node-version: "24"
  53. registry-url: "https://registry.npmjs.org"
  54. - name: Setup Git Identity
  55. run: |
  56. git config --global user.email "[email protected]"
  57. git config --global user.name "opencode"
  58. git remote set-url origin https://x-access-token:${{ secrets.SST_GITHUB_TOKEN }}@github.com/${{ github.repository }}
  59. - name: Publish
  60. id: publish
  61. run: ./script/publish-start.ts
  62. env:
  63. OPENCODE_BUMP: ${{ inputs.bump }}
  64. OPENCODE_VERSION: ${{ inputs.version }}
  65. OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
  66. AUR_KEY: ${{ secrets.AUR_KEY }}
  67. GITHUB_TOKEN: ${{ secrets.SST_GITHUB_TOKEN }}
  68. NPM_CONFIG_PROVENANCE: false
  69. - uses: actions/upload-artifact@v4
  70. with:
  71. name: opencode-cli
  72. path: packages/opencode/dist
  73. outputs:
  74. release: ${{ steps.publish.outputs.release }}
  75. tag: ${{ steps.publish.outputs.tag }}
  76. version: ${{ steps.publish.outputs.version }}
  77. publish-tauri:
  78. needs: publish
  79. continue-on-error: false
  80. strategy:
  81. fail-fast: false
  82. matrix:
  83. settings:
  84. - host: macos-latest
  85. target: x86_64-apple-darwin
  86. - host: macos-latest
  87. target: aarch64-apple-darwin
  88. - host: blacksmith-4vcpu-windows-2025
  89. target: x86_64-pc-windows-msvc
  90. - host: blacksmith-4vcpu-ubuntu-2404
  91. target: x86_64-unknown-linux-gnu
  92. - host: blacksmith-4vcpu-ubuntu-2404-arm
  93. target: aarch64-unknown-linux-gnu
  94. runs-on: ${{ matrix.settings.host }}
  95. steps:
  96. - uses: actions/checkout@v3
  97. with:
  98. fetch-depth: 0
  99. ref: ${{ needs.publish.outputs.tag }}
  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. - run: git fetch --force --tags
  118. - uses: ./.github/actions/setup-bun
  119. - name: install dependencies (ubuntu only)
  120. if: contains(matrix.settings.host, 'ubuntu')
  121. run: |
  122. sudo apt-get update
  123. sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
  124. - name: install Rust stable
  125. uses: dtolnay/rust-toolchain@stable
  126. with:
  127. targets: ${{ matrix.settings.target }}
  128. - uses: Swatinem/rust-cache@v2
  129. with:
  130. workspaces: packages/desktop/src-tauri
  131. shared-key: ${{ matrix.settings.target }}
  132. - name: Prepare
  133. run: |
  134. cd packages/desktop
  135. bun ./scripts/prepare.ts
  136. env:
  137. OPENCODE_VERSION: ${{ needs.publish.outputs.version }}
  138. NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
  139. GITHUB_TOKEN: ${{ secrets.SST_GITHUB_TOKEN }}
  140. AUR_KEY: ${{ secrets.AUR_KEY }}
  141. OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
  142. RUST_TARGET: ${{ matrix.settings.target }}
  143. GH_TOKEN: ${{ github.token }}
  144. GITHUB_RUN_ID: ${{ github.run_id }}
  145. # Fixes AppImage build issues, can be removed when https://github.com/tauri-apps/tauri/pull/12491 is released
  146. - name: Install tauri-cli from portable appimage branch
  147. if: contains(matrix.settings.host, 'ubuntu')
  148. run: |
  149. cargo install tauri-cli --git https://github.com/tauri-apps/tauri --branch feat/truly-portable-appimage --force
  150. echo "Installed tauri-cli version:"
  151. cargo tauri --version
  152. - name: Build and upload artifacts
  153. uses: Wandalen/wretry.action@v3
  154. timeout-minutes: 60
  155. with:
  156. attempt_limit: 3
  157. attempt_delay: 10000
  158. action: tauri-apps/tauri-action@390cbe447412ced1303d35abe75287949e43437a
  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.publish.outputs.release }}
  166. tagName: ${{ needs.publish.outputs.tag }}
  167. releaseAssetNamePattern: opencode-desktop-[platform]-[arch][ext]
  168. releaseDraft: true
  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-release:
  181. needs:
  182. - publish
  183. - publish-tauri
  184. if: needs.publish.outputs.tag
  185. runs-on: blacksmith-4vcpu-ubuntu-2404
  186. steps:
  187. - uses: actions/checkout@v3
  188. with:
  189. fetch-depth: 0
  190. ref: ${{ needs.publish.outputs.tag }}
  191. - uses: ./.github/actions/setup-bun
  192. - name: Setup SSH for AUR
  193. run: |
  194. sudo apt-get update
  195. sudo apt-get install -y pacman-package-manager
  196. mkdir -p ~/.ssh
  197. echo "${{ secrets.AUR_KEY }}" > ~/.ssh/id_rsa
  198. chmod 600 ~/.ssh/id_rsa
  199. git config --global user.email "[email protected]"
  200. git config --global user.name "opencode"
  201. ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts || true
  202. - run: ./script/publish-complete.ts
  203. env:
  204. OPENCODE_VERSION: ${{ needs.publish.outputs.version }}
  205. AUR_KEY: ${{ secrets.AUR_KEY }}
  206. GITHUB_TOKEN: ${{ secrets.SST_GITHUB_TOKEN }}