publish.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  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. - uses: actions/setup-node@v4
  134. with:
  135. node-version: "24"
  136. - name: Cache apt packages
  137. if: contains(matrix.settings.host, 'ubuntu')
  138. uses: actions/cache@v4
  139. with:
  140. path: ~/apt-cache
  141. key: ${{ runner.os }}-${{ matrix.settings.target }}-apt-${{ hashFiles('.github/workflows/publish.yml') }}
  142. restore-keys: |
  143. ${{ runner.os }}-${{ matrix.settings.target }}-apt-
  144. - name: install dependencies (ubuntu only)
  145. if: contains(matrix.settings.host, 'ubuntu')
  146. run: |
  147. mkdir -p ~/apt-cache && chmod -R a+rw ~/apt-cache
  148. sudo apt-get update
  149. sudo apt-get install -y --no-install-recommends -o dir::cache::archives="$HOME/apt-cache" libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
  150. sudo chmod -R a+rw ~/apt-cache
  151. - name: install Rust stable
  152. uses: dtolnay/rust-toolchain@stable
  153. with:
  154. targets: ${{ matrix.settings.target }}
  155. - uses: Swatinem/rust-cache@v2
  156. with:
  157. workspaces: packages/desktop/src-tauri
  158. shared-key: ${{ matrix.settings.target }}
  159. - name: Prepare
  160. run: |
  161. cd packages/desktop
  162. bun ./scripts/prepare.ts
  163. env:
  164. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  165. GITHUB_TOKEN: ${{ steps.committer.outputs.token }}
  166. RUST_TARGET: ${{ matrix.settings.target }}
  167. GH_TOKEN: ${{ github.token }}
  168. GITHUB_RUN_ID: ${{ github.run_id }}
  169. - name: Resolve tauri portable SHA
  170. if: contains(matrix.settings.host, 'ubuntu')
  171. 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"
  172. # Fixes AppImage build issues, can be removed when https://github.com/tauri-apps/tauri/pull/12491 is released
  173. - name: Install tauri-cli from portable appimage branch
  174. uses: taiki-e/cache-cargo-install-action@v3
  175. if: contains(matrix.settings.host, 'ubuntu')
  176. with:
  177. tool: tauri-cli
  178. git: https://github.com/tauri-apps/tauri
  179. # branch: feat/truly-portable-appimage
  180. rev: ${{ env.TAURI_PORTABLE_SHA }}
  181. - name: Show tauri-cli version
  182. if: contains(matrix.settings.host, 'ubuntu')
  183. run: cargo tauri --version
  184. - name: Setup git committer
  185. id: committer
  186. uses: ./.github/actions/setup-git-committer
  187. with:
  188. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  189. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  190. - name: Build and upload artifacts
  191. uses: tauri-apps/tauri-action@390cbe447412ced1303d35abe75287949e43437a
  192. timeout-minutes: 60
  193. with:
  194. projectPath: packages/desktop
  195. uploadWorkflowArtifacts: true
  196. tauriScript: ${{ (contains(matrix.settings.host, 'ubuntu') && 'cargo tauri') || '' }}
  197. args: --target ${{ matrix.settings.target }} --config ${{ (github.ref_name == 'beta' && './src-tauri/tauri.beta.conf.json') || './src-tauri/tauri.prod.conf.json' }} --verbose
  198. updaterJsonPreferNsis: true
  199. releaseId: ${{ needs.version.outputs.release }}
  200. tagName: ${{ needs.version.outputs.tag }}
  201. releaseDraft: true
  202. releaseAssetNamePattern: opencode-desktop-[platform]-[arch][ext]
  203. repo: ${{ (github.ref_name == 'beta' && 'opencode-beta') || '' }}
  204. releaseCommitish: ${{ github.sha }}
  205. env:
  206. GITHUB_TOKEN: ${{ steps.committer.outputs.token }}
  207. TAURI_BUNDLER_NEW_APPIMAGE_FORMAT: true
  208. TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
  209. TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
  210. APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
  211. APPLE_CERTIFICATE_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  212. APPLE_SIGNING_IDENTITY: ${{ env.CERT_ID }}
  213. APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
  214. APPLE_API_KEY: ${{ secrets.APPLE_API_KEY }}
  215. APPLE_API_KEY_PATH: ${{ runner.temp }}/apple-api-key.p8
  216. build-electron:
  217. needs:
  218. - build-cli
  219. - version
  220. continue-on-error: false
  221. strategy:
  222. fail-fast: false
  223. matrix:
  224. settings:
  225. - host: macos-latest
  226. target: x86_64-apple-darwin
  227. platform_flag: --mac --x64
  228. - host: macos-latest
  229. target: aarch64-apple-darwin
  230. platform_flag: --mac --arm64
  231. - host: "blacksmith-4vcpu-windows-2025"
  232. target: x86_64-pc-windows-msvc
  233. platform_flag: --win
  234. - host: "blacksmith-4vcpu-ubuntu-2404"
  235. target: x86_64-unknown-linux-gnu
  236. platform_flag: --linux
  237. - host: "blacksmith-4vcpu-ubuntu-2404"
  238. target: aarch64-unknown-linux-gnu
  239. platform_flag: --linux
  240. runs-on: ${{ matrix.settings.host }}
  241. # if: github.ref_name == 'beta'
  242. steps:
  243. - uses: actions/checkout@v3
  244. - uses: apple-actions/import-codesign-certs@v2
  245. if: runner.os == 'macOS'
  246. with:
  247. keychain: build
  248. p12-file-base64: ${{ secrets.APPLE_CERTIFICATE }}
  249. p12-password: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  250. - name: Setup Apple API Key
  251. if: runner.os == 'macOS'
  252. run: echo "${{ secrets.APPLE_API_KEY_PATH }}" > $RUNNER_TEMP/apple-api-key.p8
  253. - uses: ./.github/actions/setup-bun
  254. - uses: actions/setup-node@v4
  255. with:
  256. node-version: "24"
  257. - name: Cache apt packages
  258. if: contains(matrix.settings.host, 'ubuntu')
  259. uses: actions/cache@v4
  260. with:
  261. path: ~/apt-cache
  262. key: ${{ runner.os }}-${{ matrix.settings.target }}-apt-electron-${{ hashFiles('.github/workflows/publish.yml') }}
  263. restore-keys: |
  264. ${{ runner.os }}-${{ matrix.settings.target }}-apt-electron-
  265. - name: Install dependencies (ubuntu only)
  266. if: contains(matrix.settings.host, 'ubuntu')
  267. run: |
  268. mkdir -p ~/apt-cache && chmod -R a+rw ~/apt-cache
  269. sudo apt-get update
  270. sudo apt-get install -y --no-install-recommends -o dir::cache::archives="$HOME/apt-cache" rpm
  271. sudo chmod -R a+rw ~/apt-cache
  272. - name: Setup git committer
  273. id: committer
  274. uses: ./.github/actions/setup-git-committer
  275. with:
  276. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  277. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  278. - name: Prepare
  279. run: bun ./scripts/prepare.ts
  280. working-directory: packages/desktop-electron
  281. env:
  282. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  283. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  284. RUST_TARGET: ${{ matrix.settings.target }}
  285. GH_TOKEN: ${{ github.token }}
  286. GITHUB_RUN_ID: ${{ github.run_id }}
  287. - name: Build
  288. run: bun run build
  289. working-directory: packages/desktop-electron
  290. env:
  291. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  292. - name: Package and publish
  293. if: needs.version.outputs.release
  294. run: npx electron-builder ${{ matrix.settings.platform_flag }} --publish always --config electron-builder.config.ts
  295. working-directory: packages/desktop-electron
  296. timeout-minutes: 60
  297. env:
  298. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  299. GH_TOKEN: ${{ steps.committer.outputs.token }}
  300. CSC_LINK: ${{ secrets.APPLE_CERTIFICATE }}
  301. CSC_KEY_PASSWORD: ${{ secrets.APPLE_CERTIFICATE_PASSWORD }}
  302. APPLE_API_KEY: ${{ runner.temp }}/apple-api-key.p8
  303. APPLE_API_KEY_ID: ${{ secrets.APPLE_API_KEY }}
  304. APPLE_API_ISSUER: ${{ secrets.APPLE_API_ISSUER }}
  305. - name: Package (no publish)
  306. if: ${{ !needs.version.outputs.release }}
  307. run: npx electron-builder ${{ matrix.settings.platform_flag }} --publish never --config electron-builder.config.ts
  308. working-directory: packages/desktop-electron
  309. timeout-minutes: 60
  310. env:
  311. OPENCODE_CHANNEL: ${{ (github.ref_name == 'beta' && 'beta') || 'prod' }}
  312. - uses: actions/upload-artifact@v4
  313. with:
  314. name: opencode-electron-${{ matrix.settings.target }}
  315. path: packages/desktop-electron/dist/*
  316. - uses: actions/upload-artifact@v4
  317. if: needs.version.outputs.release
  318. with:
  319. name: latest-yml-${{ matrix.settings.target }}
  320. path: packages/desktop-electron/dist/latest*.yml
  321. publish:
  322. needs:
  323. - version
  324. - build-cli
  325. - build-tauri
  326. - build-electron
  327. runs-on: blacksmith-4vcpu-ubuntu-2404
  328. steps:
  329. - uses: actions/checkout@v3
  330. - uses: ./.github/actions/setup-bun
  331. - name: Login to GitHub Container Registry
  332. uses: docker/login-action@v3
  333. with:
  334. registry: ghcr.io
  335. username: ${{ github.repository_owner }}
  336. password: ${{ secrets.GITHUB_TOKEN }}
  337. - name: Set up QEMU
  338. uses: docker/setup-qemu-action@v3
  339. - name: Set up Docker Buildx
  340. uses: docker/setup-buildx-action@v3
  341. - uses: actions/setup-node@v4
  342. with:
  343. node-version: "24"
  344. registry-url: "https://registry.npmjs.org"
  345. - name: Setup git committer
  346. id: committer
  347. uses: ./.github/actions/setup-git-committer
  348. with:
  349. opencode-app-id: ${{ vars.OPENCODE_APP_ID }}
  350. opencode-app-secret: ${{ secrets.OPENCODE_APP_SECRET }}
  351. - uses: actions/download-artifact@v4
  352. with:
  353. name: opencode-cli
  354. path: packages/opencode/dist
  355. - uses: actions/download-artifact@v4
  356. if: needs.version.outputs.release
  357. with:
  358. pattern: latest-yml-*
  359. path: /tmp/latest-yml
  360. - name: Cache apt packages (AUR)
  361. uses: actions/cache@v4
  362. with:
  363. path: /var/cache/apt/archives
  364. key: ${{ runner.os }}-apt-aur-${{ hashFiles('.github/workflows/publish.yml') }}
  365. restore-keys: |
  366. ${{ runner.os }}-apt-aur-
  367. - name: Setup SSH for AUR
  368. run: |
  369. sudo apt-get update
  370. sudo apt-get install -y pacman-package-manager
  371. mkdir -p ~/.ssh
  372. echo "${{ secrets.AUR_KEY }}" > ~/.ssh/id_rsa
  373. chmod 600 ~/.ssh/id_rsa
  374. git config --global user.email "[email protected]"
  375. git config --global user.name "opencode"
  376. ssh-keyscan -H aur.archlinux.org >> ~/.ssh/known_hosts || true
  377. - run: ./script/publish.ts
  378. env:
  379. OPENCODE_VERSION: ${{ needs.version.outputs.version }}
  380. OPENCODE_RELEASE: ${{ needs.version.outputs.release }}
  381. AUR_KEY: ${{ secrets.AUR_KEY }}
  382. GITHUB_TOKEN: ${{ steps.committer.outputs.token }}
  383. GH_REPO: ${{ needs.version.outputs.repo }}
  384. NPM_CONFIG_PROVENANCE: false
  385. LATEST_YML_DIR: /tmp/latest-yml