-
Notifications
You must be signed in to change notification settings - Fork 6
369 lines (320 loc) Β· 13.6 KB
/
ci.yml
File metadata and controls
369 lines (320 loc) Β· 13.6 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
name: CI
on:
pull_request:
push:
branches: [main, master]
permissions:
contents: read
jobs:
check:
runs-on: ubuntu-latest
steps:
# Pinned by SHA to prevent tag-swapping supply chain attacks.
# To update: verify the new SHA on the action's releases page,
# then update both the SHA and the version comment.
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: "1.3.8"
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Audit dependencies
run: bun pm ls --all 2>&1 | head -200
- name: Typecheck
run: bun run typecheck
- name: Lint
run: bun run lint
- name: Test (unit + integration, excludes smoke)
run: bun test tests/*.test.ts
- name: Build (node target)
run: bun run build
- name: Build (binary)
run: bun run build:binary
- name: Smoke tests (binary + package)
run: bun test tests/smoke/
check-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: "1.3.8"
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Test (unit + integration, excludes smoke)
shell: pwsh
run: |
$files = Get-ChildItem -Path tests -Filter *.test.ts | ForEach-Object { $_.FullName }
bun test @files
- name: Build (node target)
run: bun run build
- name: Build (binary)
run: bun run build:binary
- name: Smoke tests (binary + package)
run: bun test tests/smoke/
e2e:
needs: [check]
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: "1.3.8"
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Build (binary)
run: bun run build:binary
- name: Run e2e tests
run: bun test tests/e2e/
env:
E2E_RESEND_API_KEY: ${{ secrets.E2E_RESEND_API_KEY }}
E2E_TEST_EMAIL: ${{ secrets.E2E_TEST_EMAIL }}
E2E_INBOX_EMAIL: ${{ secrets.E2E_INBOX_EMAIL }}
e2e-windows:
needs: [check-windows]
runs-on: windows-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
persist-credentials: false
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: "1.3.8"
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Build (binary)
run: bun run build:binary
- name: Run e2e tests
shell: pwsh
run: bun test tests/e2e/
env:
E2E_RESEND_API_KEY: ${{ secrets.E2E_RESEND_API_KEY }}
E2E_TEST_EMAIL: ${{ secrets.E2E_TEST_EMAIL }}
E2E_INBOX_EMAIL: ${{ secrets.E2E_INBOX_EMAIL }}
# ββ Release jobs (master push only) ββββββββββββββββββββββββββββββ
version:
needs: [check]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.bump.outputs.version }}
should_release: ${{ steps.bump.outputs.should_release }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
token: ${{ secrets.RELEASE_TOKEN }}
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: "1.3.8"
- run: bun install --frozen-lockfile
- name: Bump version
id: bump
run: |
rc=0
output=$(node scripts/auto-version.mjs 2>&1) || rc=$?
if [ "$rc" -eq 1 ]; then
echo "No release needed β skipping."
echo "$output"
echo "should_release=false" >> "$GITHUB_OUTPUT"
exit 0
elif [ "$rc" -ne 0 ]; then
echo "::error::auto-version.mjs crashed (exit $rc):"
echo "$output"
exit 1
fi
version=$(echo "$output" | grep '^NEW_VERSION=' | cut -d= -f2)
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "should_release=true" >> "$GITHUB_OUTPUT"
- name: Commit version bump and tag
if: steps.bump.outputs.should_release == 'true'
env:
VERSION: ${{ steps.bump.outputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add package.json
git commit -m "chore(release): ${VERSION}"
git tag -a "${VERSION}" -m "Release ${VERSION}"
git push origin master "${VERSION}"
build-binaries:
needs: [version]
if: needs.version.outputs.should_release == 'true'
strategy:
matrix:
include:
- os: ubuntu-latest
target: bun-linux-x64
artifact: 10x-linux-x64
- os: ubuntu-latest
target: bun-linux-arm64
artifact: 10x-linux-arm64
- os: macos-latest
target: bun-darwin-arm64
artifact: 10x-darwin-arm64
- os: macos-14
target: bun-darwin-x64
artifact: 10x-darwin-x64
- os: windows-latest
target: bun-windows-x64
artifact: 10x-windows-x64.exe
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
ref: ${{ needs.version.outputs.new_version }}
persist-credentials: false
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: "1.3.8"
- run: bun install --frozen-lockfile
- name: Build binary
run: bun build --compile --minify src/index.ts --target ${{ matrix.target }} --outfile dist/${{ matrix.artifact }}
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: ${{ matrix.artifact }}
path: dist/${{ matrix.artifact }}
publish-npm:
needs: [version]
if: needs.version.outputs.should_release == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
ref: ${{ needs.version.outputs.new_version }}
persist-credentials: false
- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2
with:
bun-version: "1.3.8"
- run: bun install --frozen-lockfile && bun run build
- name: Publish to npm
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
npm publish --access public
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
github-release:
needs: [version, build-binaries]
if: needs.version.outputs.should_release == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
path: release-assets
merge-multiple: true
- uses: softprops/action-gh-release@da05d552573ad5aba039eaac05058a918a7bf631 # v2
with:
tag_name: ${{ needs.version.outputs.new_version }}
generate_release_notes: true
files: release-assets/**/*
notify-slack:
needs: [check, e2e, version, publish-npm, github-release]
if: always() && github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- name: Build notification payload
id: payload
run: |
MSG=$(echo "${{ github.event.head_commit.message }}" | head -1 | cut -c1-80)
echo "commit_msg=${MSG}" >> "$GITHUB_OUTPUT"
if [[ "${{ needs.check.result }}" != "success" || "${{ needs.e2e.result }}" == "failure" || "${{ needs.publish-npm.result }}" == "failure" || "${{ needs.version.result }}" == "failure" || "${{ needs.github-release.result }}" == "failure" ]]; then
echo "failed=true" >> "$GITHUB_OUTPUT"
else
echo "failed=false" >> "$GITHUB_OUTPUT"
fi
- name: Post to #observability
uses: slackapi/slack-github-action@v2
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
{
"text": "${{ steps.payload.outputs.failed == 'true' && 'π΄' || needs.version.outputs.should_release == 'true' && needs.publish-npm.result == 'success' && 'π¦' || 'π’' }} 10x-cli pipeline",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "${{ steps.payload.outputs.failed == 'true' && 'π΄' || needs.version.outputs.should_release == 'true' && needs.publish-npm.result == 'success' && 'π¦' || 'π’' }} 10x-cli${{ needs.version.outputs.should_release == 'true' && format(' β v{0}', needs.version.outputs.new_version) || '' }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ needs.check.result == 'success' && 'β
' || needs.check.result == 'skipped' && 'βοΈ' || 'β' }} Tests ${{ needs.e2e.result == 'success' && 'β
' || needs.e2e.result == 'skipped' && 'βοΈ' || 'β' }} E2E ${{ needs.publish-npm.result == 'success' && 'β
' || needs.publish-npm.result == 'skipped' && 'βοΈ' || 'β' }} npm ${{ needs.github-release.result == 'success' && 'β
' || needs.github-release.result == 'skipped' && 'βοΈ' || 'β' }} Release"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "π <${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|`${{ github.sha }}`> ${{ steps.payload.outputs.commit_msg }} Β· π€ ${{ github.actor }} Β· <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|π Workflow>${{ steps.payload.outputs.failed == 'true' && ' Β· π see #alerting' || '' }}"
}
]
}
]
}
- name: Post to #alerting
if: steps.payload.outputs.failed == 'true'
uses: slackapi/slack-github-action@v2
with:
webhook: ${{ secrets.SLACK_ALERTS_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
{
"text": "π¨ 10x-cli pipeline failure",
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "π¨ 10x-cli β FAILURE"
}
},
{
"type": "section",
"fields": [
{ "type": "mrkdwn", "text": "*Tests*\n${{ needs.check.result == 'success' && 'β
passed' || needs.check.result == 'skipped' && 'βοΈ skipped' || 'β failed' }}" },
{ "type": "mrkdwn", "text": "*E2E*\n${{ needs.e2e.result == 'success' && 'β
passed' || needs.e2e.result == 'skipped' && 'βοΈ skipped' || 'β failed' }}" },
{ "type": "mrkdwn", "text": "*npm*\n${{ needs.publish-npm.result == 'success' && 'β
published' || needs.publish-npm.result == 'skipped' && 'βοΈ skipped' || 'β failed' }}" },
{ "type": "mrkdwn", "text": "*Release*\n${{ needs.github-release.result == 'success' && 'β
created' || needs.github-release.result == 'skipped' && 'βοΈ skipped' || 'β failed' }}" }
]
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "π *Commit:* <${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|`${{ github.sha }}`>\n${{ steps.payload.outputs.commit_msg }}\n\nπ€ *Author:* ${{ github.actor }}"
},
"accessory": {
"type": "button",
"text": { "type": "plain_text", "text": "View Run" },
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "π <${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|Commit diff> Β· π <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Full logs> Β· π¦ <https://www.npmjs.com/package/@przeprogramowani/10x-cli|npm package>"
}
]
}
]
}