publish.yml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. test:
  29. if: github.event_name == 'workflow_dispatch'
  30. uses: ./.github/workflows/test.yml
  31. publish:
  32. needs: test
  33. runs-on: blacksmith-4vcpu-ubuntu-2404
  34. if: always() && github.repository == 'anomalyco/opencode' && (github.event_name != 'workflow_dispatch' || needs.test.result == 'success')
  35. steps:
  36. - uses: actions/checkout@v3
  37. with:
  38. fetch-depth: 0
  39. - run: git fetch --force --tags
  40. - uses: ./.github/actions/setup-bun
  41. - name: Install OpenCode
  42. if: inputs.bump || inputs.version
  43. run: bun i -g [email protected]
  44. - name: Login to GitHub Container Registry
  45. uses: docker/login-action@v3
  46. with:
  47. registry: ghcr.io
  48. username: ${{ github.repository_owner }}
  49. password: ${{ secrets.GITHUB_TOKEN }}
  50. - name: Set up QEMU
  51. uses: docker/setup-qemu-action@v3
  52. - name: Set up Docker Buildx
  53. uses: docker/setup-buildx-action@v3
  54. - uses: actions/setup-node@v4
  55. with:
  56. node-version: "24"
  57. registry-url: "https://registry.npmjs.org"
  58. - name: Setup Git Identity
  59. run: |
  60. git config --global user.email "[email protected]"
  61. git config --global user.name "opencode"
  62. git remote set-url origin https://x-access-token:${{ secrets.SST_GITHUB_TOKEN }}@github.com/${{ github.repository }}
  63. - name: Publish
  64. id: publish
  65. run: ./script/publish-start.ts
  66. env:
  67. OPENCODE_BUMP: ${{ inputs.bump }}
  68. OPENCODE_VERSION: ${{ inputs.version }}
  69. OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
  70. AUR_KEY: ${{ secrets.AUR_KEY }}
  71. GITHUB_TOKEN: ${{ secrets.SST_GITHUB_TOKEN }}
  72. NPM_CONFIG_PROVENANCE: false
  73. - uses: actions/upload-artifact@v4
  74. with:
  75. name: opencode-cli
  76. path: packages/opencode/dist
  77. outputs:
  78. release: ${{ steps.publish.outputs.release }}
  79. tag: ${{ steps.publish.outputs.tag }}
  80. version: ${{ steps.publish.outputs.version }}
  81. publish-tauri:
  82. needs: publish
  83. continue-on-error: false
  84. strategy:
  85. fail-fast: false
  86. matrix:
  87. settings:
  88. - host: macos-latest
  89. target: x86_64-apple-darwin
  90. - host: macos-latest
  91. target: aarch64-apple-darwin
  92. - host: blacksmith-4vcpu-windows-2025
  93. target: x86_64-pc-windows-msvc
  94. - host: blacksmith-4vcpu-ubuntu-2404
  95. target: x86_64-unknown-linux-gnu
  96. - host: blacksmith-4vcpu-ubuntu-2404-arm
  97. target: aarch64-unknown-linux-gnu
  98. runs-on: ${{ matrix.settings.host }}
  99. steps:
  100. - uses: actions/checkout@v3
  101. with:
  102. fetch-depth: 0
  103. ref: ${{ needs.publish.outputs.tag }}
  104. - uses: apple-actions/import-codesign-certs@v2
  105. if: ${{ runner.os == 'macOS' }}
  106. with:
  107. keychain: build
  108. p12-file-base64: ${{ secrets.APPLE_CERTIFICATE }}
  109. p12-password: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  110. - name: Verify Certificate
  111. if: ${{ runner.os == 'macOS' }}
  112. run: |
  113. CERT_INFO=$(security find-identity -v -p codesigning build.keychain | grep "Developer ID Application")
  114. CERT_ID=$(echo "$CERT_INFO" | awk -F'"' '{print $2}')
  115. echo "CERT_ID=$CERT_ID" >> $GITHUB_ENV
  116. echo "Certificate imported."
  117. - name: Setup Apple API Key
  118. if: ${{ runner.os == 'macOS' }}
  119. run: |
  120. echo "${{ secrets.APPLE_API_KEY_PATH }}" > $RUNNER_TEMP/apple-api-key.p8
  121. - run: git fetch --force --tags
  122. - uses: ./.github/actions/setup-bun
  123. - name: install dependencies (ubuntu only)
  124. if: contains(matrix.settings.host, 'ubuntu')
  125. run: |
  126. sudo apt-get update
  127. sudo apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
  128. - name: install Rust stable
  129. uses: dtolnay/rust-toolchain@stable
  130. with:
  131. targets: ${{ matrix.settings.target }}
  132. - uses: Swatinem/rust-cache@v2
  133. with:
  134. workspaces: packages/desktop/src-tauri
  135. shared-key: ${{ matrix.settings.target }}
  136. - name: Prepare
  137. run: |
  138. cd packages/desktop
  139. bun ./scripts/prepare.ts
  140. env:
  141. OPENCODE_VERSION: ${{ needs.publish.outputs.version }}
  142. NPM_CONFIG_TOKEN: ${{ secrets.NPM_TOKEN }}
  143. GITHUB_TOKEN: ${{ secrets.SST_GITHUB_TOKEN }}
  144. AUR_KEY: ${{ secrets.AUR_KEY }}
  145. OPENCODE_API_KEY: ${{ secrets.OPENCODE_API_KEY }}
  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: Wandalen/wretry.action@v3
  158. timeout-minutes: 60
  159. with:
  160. attempt_limit: 3
  161. attempt_delay: 10000
  162. action: tauri-apps/tauri-action@390cbe447412ced1303d35abe75287949e43437a
  163. with: |
  164. projectPath: packages/desktop
  165. uploadWorkflowArtifacts: true
  166. tauriScript: ${{ (contains(matrix.settings.host, 'ubuntu') && 'cargo tauri') || '' }}
  167. args: --target ${{ matrix.settings.target }} --config ./src-tauri/tauri.prod.conf.json --verbose
  168. updaterJsonPreferNsis: true
  169. releaseId: ${{ needs.publish.outputs.release }}
  170. tagName: ${{ needs.publish.outputs.tag }}
  171. releaseAssetNamePattern: opencode-desktop-[platform]-[arch][ext]
  172. releaseDraft: true
  173. env:
  174. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  175. TAURI_BUNDLER_NEW_APPIMAGE_FORMAT: true
  176. TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
  177. TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
  178. APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
  179. APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  180. APPLE_SIGNING_IDENTITY: ${{ env.CERT_ID }}
  181. APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
  182. APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
  183. APPLE_API_KEY_PATH: ${{ runner.temp }}/apple-api-key.p8
  184. publish-release:
  185. needs:
  186. - publish
  187. - publish-tauri
  188. if: needs.publish.outputs.tag
  189. runs-on: blacksmith-4vcpu-ubuntu-2404
  190. steps:
  191. - uses: actions/checkout@v3
  192. with:
  193. fetch-depth: 0
  194. ref: ${{ needs.publish.outputs.tag }}
  195. - uses: ./.github/actions/setup-bun
  196. - name: Setup SSH for AUR
  197. run: |
  198. sudo apt-get update
  199. sudo apt-get install -y pacman-package-manager
  200. mkdir -p ~/.ssh
  201. echo "${{ secrets.AUR_KEY }}" > ~/.ssh/id_rsa
  202. chmod 600 ~/.ssh/id_rsa
  203. git config --global user.email "[email protected]"
  204. git config --global user.name "opencode"
  205. ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts || true
  206. - run: ./script/publish-complete.ts
  207. env:
  208. OPENCODE_VERSION: ${{ needs.publish.outputs.version }}
  209. AUR_KEY: ${{ secrets.AUR_KEY }}
  210. GITHUB_TOKEN: ${{ secrets.SST_GITHUB_TOKEN }}