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