publish.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. build-electron:
  214. needs:
  215. - build-cli
  216. - version
  217. continue-on-error: false
  218. strategy:
  219. fail-fast: false
  220. matrix:
  221. settings:
  222. - host: macos-latest
  223. target: x86_64-apple-darwin
  224. platform_flag: --mac --x64
  225. - host: macos-latest
  226. target: aarch64-apple-darwin
  227. platform_flag: --mac --arm64
  228. - host: "blacksmith-4vcpu-windows-2025"
  229. target: x86_64-pc-windows-msvc
  230. platform_flag: --win
  231. - host: "blacksmith-4vcpu-ubuntu-2404"
  232. target: x86_64-unknown-linux-gnu
  233. platform_flag: --linux
  234. - host: "blacksmith-4vcpu-ubuntu-2404"
  235. target: aarch64-unknown-linux-gnu
  236. platform_flag: --linux
  237. runs-on: ${{ matrix.settings.host }}
  238. # if: github.ref_name == 'beta'
  239. steps:
  240. - uses: actions/checkout@v3
  241. - uses: apple-actions/import-codesign-certs@v2
  242. if: runner.os == 'macOS'
  243. with:
  244. keychain: build
  245. p12-file-base64: ${{ secrets.APPLE_CERTIFICATE }}
  246. p12-password: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  247. - name: Setup Apple API Key
  248. if: runner.os == 'macOS'
  249. run: echo "${{ secrets.APPLE_API_KEY_PATH }}" > $RUNNER_TEMP/apple-api-key.p8
  250. - uses: ./.github/actions/setup-bun
  251. - uses: actions/setup-node@v4
  252. with:
  253. node-version: "24"
  254. - name: Cache apt packages
  255. if: contains(matrix.settings.host, 'ubuntu')
  256. uses: actions/cache@v4
  257. with:
  258. path: ~/apt-cache
  259. key: ${{ runner.os }}-${{ matrix.settings.target }}-apt-electron-${{ hashFiles('.github/workflows/publish.yml') }}
  260. restore-keys: |
  261. ${{ runner.os }}-${{ matrix.settings.target }}-apt-electron-
  262. - name: Install dependencies (ubuntu only)
  263. if: contains(matrix.settings.host, 'ubuntu')
  264. run: |
  265. mkdir -p ~/apt-cache && chmod -R a+rw ~/apt-cache
  266. sudo apt-get update
  267. sudo apt-get install -y --no-install-recommends -o dir::cache::archives="$HOME/apt-cache" rpm
  268. sudo chmod -R a+rw ~/apt-cache
  269. - name: Setup git committer
  270. id: committer
  271. uses: ./.github/actions/setup-git-committer
  272. with:
  273. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  274. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  275. - name: Prepare
  276. run: bun ./scripts/prepare.ts
  277. working-directory: packages/desktop-electron
  278. env:
  279. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  280. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  281. RUST_TARGET: ${{ matrix.settings.target }}
  282. GH_TOKEN: ${{ github.token }}
  283. GITHUB_RUN_ID: ${{ github.run_id }}
  284. - name: Build
  285. run: bun run build
  286. working-directory: packages/desktop-electron
  287. env:
  288. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  289. - name: Package and publish
  290. if: needs.version.outputs.release
  291. run: npx electron-builder ${{ matrix.settings.platform_flag }} --publish always --config electron-builder.config.ts
  292. working-directory: packages/desktop-electron
  293. timeout-minutes: 60
  294. env:
  295. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  296. GH_TOKEN: ${{ steps.committer.outputs.token }}
  297. CSC_LINK: ${{ secrets.APPLE_CERTIFICATE }}
  298. CSC_KEY_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  299. APPLE_API_KEY: ${{ runner.temp }}/apple-api-key.p8
  300. APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY }}
  301. APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
  302. - name: Package (no publish)
  303. if: ${{ !needs.version.outputs.release }}
  304. run: npx electron-builder ${{ matrix.settings.platform_flag }} --publish never --config electron-builder.config.ts
  305. working-directory: packages/desktop-electron
  306. timeout-minutes: 60
  307. env:
  308. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  309. - uses: actions/upload-artifact@v4
  310. with:
  311. name: opencode-electron-${{ matrix.settings.target }}
  312. path: packages/desktop-electron/dist/*
  313. - uses: actions/upload-artifact@v4
  314. if: needs.version.outputs.release
  315. with:
  316. name: latest-yml-${{ matrix.settings.target }}
  317. path: packages/desktop-electron/dist/latest*.yml
  318. publish:
  319. needs:
  320. - version
  321. - build-cli
  322. - build-tauri
  323. - build-electron
  324. runs-on: blacksmith-4vcpu-ubuntu-2404
  325. steps:
  326. - uses: actions/checkout@v3
  327. - uses: ./.github/actions/setup-bun
  328. - name: Login to GitHub Container Registry
  329. uses: docker/login-action@v3
  330. with:
  331. registry: ghcr.io
  332. username: ${{ github.repository_owner }}
  333. password: ${{ secrets.GITHUB_TOKEN }}
  334. - name: Set up QEMU
  335. uses: docker/setup-qemu-action@v3
  336. - name: Set up Docker Buildx
  337. uses: docker/setup-buildx-action@v3
  338. - uses: actions/setup-node@v4
  339. with:
  340. node-version: "24"
  341. registry-url: "https://registry.npmjs.org"
  342. - name: Setup git committer
  343. id: committer
  344. uses: ./.github/actions/setup-git-committer
  345. with:
  346. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  347. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  348. - uses: actions/download-artifact@v4
  349. with:
  350. name: opencode-cli
  351. path: packages/opencode/dist
  352. - uses: actions/download-artifact@v4
  353. if: needs.version.outputs.release
  354. with:
  355. pattern: latest-yml-*
  356. path: /tmp/latest-yml
  357. - name: Cache apt packages (AUR)
  358. uses: actions/cache@v4
  359. with:
  360. path: /var/cache/apt/archives
  361. key: ${{ runner.os }}-apt-aur-${{ hashFiles('.github/workflows/publish.yml') }}
  362. restore-keys: |
  363. ${{ runner.os }}-apt-aur-
  364. - name: Setup SSH for AUR
  365. run: |
  366. sudo apt-get update
  367. sudo apt-get install -y pacman-package-manager
  368. mkdir -p ~/.ssh
  369. echo "${{ secrets.AUR_KEY }}" > ~/.ssh/id_rsa
  370. chmod 600 ~/.ssh/id_rsa
  371. git config --global user.email "[email protected]"
  372. git config --global user.name "opencode"
  373. ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts || true
  374. - run: ./script/publish.ts
  375. env:
  376. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  377. OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
  378. AUR_KEY: ${{ secrets.AUR_KEY }}
  379. GITHUB_TOKEN: ${{ steps.committer.outputs.token }}
  380. GH_REPO: ${{ needs.version.outputs.repo }}
  381. NPM_CONFIG_PROVENANCE: false
  382. LATEST_YML_DIR: /tmp/latest-yml