publish.yml 10 KB

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