cli-publish.yml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. name: Publish CLI
  2. on:
  3. pull_request:
  4. types: [closed]
  5. workflow_dispatch:
  6. env:
  7. GIT_REF: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || 'main' }}
  8. TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
  9. TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
  10. NODE_VERSION: 20.20.0
  11. PNPM_VERSION: 10.8.1
  12. DOCKER_IMAGE_NAME: kiloai/cli
  13. DOCKER_PLATFORMS: linux/amd64,linux/arm64
  14. jobs:
  15. check-version:
  16. runs-on: ubuntu-latest
  17. if: >
  18. ( github.event_name == 'pull_request' &&
  19. github.event.pull_request.merged == true &&
  20. github.event.pull_request.base.ref == 'main' &&
  21. contains(github.event.pull_request.title, 'Changeset version bump') ) ||
  22. github.event_name == 'workflow_dispatch'
  23. outputs:
  24. version: ${{ steps.check.outputs.version }}
  25. publish: ${{ steps.check.outputs.publish }}
  26. steps:
  27. - name: Checkout code
  28. uses: actions/checkout@v6
  29. with:
  30. ref: ${{ env.GIT_REF }}
  31. - name: Setup Node.js
  32. uses: actions/setup-node@v6
  33. with:
  34. node-version: ${{ env.NODE_VERSION }}
  35. - name: Check Published Version
  36. id: check
  37. working-directory: cli
  38. run: |
  39. version=$(node -p "require('./package.json').version")
  40. published_version=$(npm view @kilocode/cli version 2>/dev/null || echo "0.0.0")
  41. if npx semver "$version" -r "> $published_version"; then
  42. echo "publish=true" >> $GITHUB_OUTPUT
  43. else
  44. echo "publish=false" >> $GITHUB_OUTPUT
  45. fi
  46. echo "version=$version" >> $GITHUB_OUTPUT
  47. build-and-test:
  48. needs: check-version
  49. if: needs.check-version.outputs.publish == 'true'
  50. runs-on: ubuntu-latest
  51. steps:
  52. - name: Checkout code
  53. uses: actions/checkout@v6
  54. with:
  55. ref: ${{ env.GIT_REF }}
  56. - name: Install pnpm
  57. uses: pnpm/action-setup@v4
  58. with:
  59. version: ${{ env.PNPM_VERSION }}
  60. - name: Setup Node.js
  61. uses: actions/setup-node@v6
  62. with:
  63. node-version: ${{ env.NODE_VERSION }}
  64. cache: "pnpm"
  65. - name: Turbo cache setup
  66. uses: actions/cache@v5
  67. with:
  68. path: .turbo
  69. key: ${{ runner.os }}-turbo-${{ github.sha }}
  70. restore-keys: |
  71. ${{ runner.os }}-turbo-
  72. - name: Install dependencies
  73. run: pnpm install
  74. - name: Create .env file
  75. working-directory: cli
  76. run: echo "KILOCODE_POSTHOG_API_KEY=${{ secrets.POSTHOG_API_KEY }}" >> .env
  77. - name: Build CLI
  78. shell: bash
  79. run: pnpm run cli:bundle
  80. - name: Run integration tests
  81. shell: bash
  82. run: pnpm --filter @kilocode/cli test:integration
  83. env:
  84. CI: true
  85. KILOCODE_TOKEN: ${{ secrets.KILOCODE_INTEGRATION_TOKEN }}
  86. KILOCODE_ORGANIZATION_ID: ${{ secrets.KILOCODE_INTEGRATION_ORGANIZATION_ID }}
  87. - name: Pack CLI
  88. working-directory: cli/dist
  89. run: npm pack
  90. - name: Upload Packaged CLI
  91. uses: actions/upload-artifact@v6
  92. with:
  93. name: cli-packaged
  94. path: cli/dist/*.tgz
  95. retention-days: 1
  96. compression-level: 0
  97. publish-npm:
  98. needs: [check-version, build-and-test]
  99. runs-on: ubuntu-latest
  100. permissions:
  101. id-token: write
  102. contents: read
  103. steps:
  104. - name: Checkout code
  105. uses: actions/checkout@v6
  106. with:
  107. ref: ${{ env.GIT_REF }}
  108. - name: Setup Node.js
  109. uses: actions/setup-node@v6
  110. with:
  111. node-version: ${{ env.NODE_VERSION }}
  112. - name: Update npm
  113. run: npm install -g npm@latest
  114. - name: Download Build Artifact
  115. uses: actions/download-artifact@v7
  116. with:
  117. name: cli-packaged
  118. path: cli/dist
  119. - name: Publish to NPM
  120. working-directory: cli/dist
  121. run: |
  122. version=${{ needs.check-version.outputs.version }}
  123. npm publish --access public --provenance kilocode-cli-${version}.tgz
  124. publish-docker-debian:
  125. needs: [check-version, build-and-test]
  126. runs-on: ubuntu-latest
  127. steps:
  128. - name: Checkout code
  129. uses: actions/checkout@v6
  130. with:
  131. ref: ${{ env.GIT_REF }}
  132. - name: Set up Docker Buildx
  133. uses: docker/setup-buildx-action@v3
  134. - name: Log in to Docker Hub
  135. uses: docker/login-action@v3
  136. with:
  137. username: ${{ secrets.DOCKER_USERNAME }}
  138. password: ${{ secrets.DOCKER_PASSWORD }}
  139. - name: Download Packaged CLI
  140. uses: actions/download-artifact@v7
  141. with:
  142. name: cli-packaged
  143. path: cli/dist
  144. - name: Build and push Debian image
  145. uses: docker/build-push-action@v6
  146. with:
  147. context: ./cli
  148. file: ./cli/Dockerfile
  149. target: debian
  150. platforms: ${{ env.DOCKER_PLATFORMS }}
  151. push: true
  152. cache-from: type=gha,scope=debian
  153. cache-to: type=gha,mode=max,scope=debian
  154. tags: |
  155. ${{ env.DOCKER_IMAGE_NAME }}:${{ needs.check-version.outputs.version }}
  156. ${{ env.DOCKER_IMAGE_NAME }}:latest
  157. ${{ env.DOCKER_IMAGE_NAME }}:${{ needs.check-version.outputs.version }}-debian
  158. ${{ env.DOCKER_IMAGE_NAME }}:latest-debian
  159. build-args: |
  160. VERSION=${{ needs.check-version.outputs.version }}
  161. BUILD_DATE=${{ github.event.repository.updated_at }}
  162. VCS_REF=${{ github.sha }}
  163. publish-docker-alpine:
  164. needs: [check-version, build-and-test]
  165. runs-on: ubuntu-latest
  166. steps:
  167. - name: Checkout code
  168. uses: actions/checkout@v6
  169. with:
  170. ref: ${{ env.GIT_REF }}
  171. - name: Set up Docker Buildx
  172. uses: docker/setup-buildx-action@v3
  173. - name: Log in to Docker Hub
  174. uses: docker/login-action@v3
  175. with:
  176. username: ${{ secrets.DOCKER_USERNAME }}
  177. password: ${{ secrets.DOCKER_PASSWORD }}
  178. - name: Download Packaged CLI
  179. uses: actions/download-artifact@v7
  180. with:
  181. name: cli-packaged
  182. path: cli/dist
  183. - name: Build and push Alpine image
  184. uses: docker/build-push-action@v6
  185. with:
  186. context: ./cli
  187. file: ./cli/Dockerfile
  188. target: alpine
  189. platforms: ${{ env.DOCKER_PLATFORMS }}
  190. push: true
  191. cache-from: type=gha,scope=alpine
  192. cache-to: type=gha,mode=max,scope=alpine
  193. tags: |
  194. ${{ env.DOCKER_IMAGE_NAME }}:${{ needs.check-version.outputs.version }}-alpine
  195. ${{ env.DOCKER_IMAGE_NAME }}:latest-alpine
  196. build-args: |
  197. VERSION=${{ needs.check-version.outputs.version }}
  198. BUILD_DATE=${{ github.event.repository.updated_at }}
  199. VCS_REF=${{ github.sha }}
  200. create-release:
  201. needs: [check-version, publish-npm, publish-docker-debian, publish-docker-alpine]
  202. runs-on: ubuntu-latest
  203. permissions:
  204. contents: write
  205. steps:
  206. - name: Checkout code
  207. uses: actions/checkout@v6
  208. with:
  209. ref: ${{ env.GIT_REF }}
  210. - name: Download Build Artifact
  211. uses: actions/download-artifact@v7
  212. with:
  213. name: cli-packaged
  214. path: cli/dist
  215. - name: Configure Git
  216. run: |
  217. git config user.name "github-actions[bot]"
  218. git config user.email "github-actions[bot]@users.noreply.github.com"
  219. - name: Create and Push Git Tag
  220. run: |
  221. version=${{ needs.check-version.outputs.version }}
  222. if git ls-remote --tags origin | grep -q "refs/tags/cli-v${version}$"; then
  223. echo "Tag cli-v${version} already exists remotely, skipping tag creation"
  224. else
  225. git tag -a "cli-v${version}" -m "Release CLI - cli-v${version}"
  226. git push origin "cli-v${version}" --no-verify
  227. echo "Successfully created and pushed git tag cli-v${version}"
  228. fi
  229. - name: Create GitHub Release
  230. env:
  231. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  232. run: |
  233. version=${{ needs.check-version.outputs.version }}
  234. if gh release view "cli-v${version}" >/dev/null 2>&1; then
  235. exit 0
  236. fi
  237. changelog_content=$(sed -E -n "/^## \\[?v?${version}\\]?/,/^## /p" cli/CHANGELOG.md | sed '$d')
  238. gh release create "cli-v${version}" \
  239. --title "Release CLI - v${version}" \
  240. --notes "$changelog_content" \
  241. --target main \
  242. cli/dist/kilocode-cli-${version}.tgz
  243. echo "Successfully created CLI GitHub Release v${version}"