-
Notifications
You must be signed in to change notification settings - Fork 112
405 lines (343 loc) · 13 KB
/
Copy pathci.yml
File metadata and controls
405 lines (343 loc) · 13 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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
name: ci
on:
push:
branches:
- main
- 'release-[0-9]*'
pull_request:
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled
- ready_for_review
branches:
- main
- 'release-[0-9]*'
concurrency:
# PRs share a group so superseded revisions are cancelled. Pushes use their
# immutable commit SHA so every main commit can publish an image.
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
build-main-image-contexts:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
outputs:
image-version: ${{ steps.image-version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup environment
uses: ./.github/actions/setup
- name: Derive main image version
id: image-version
shell: bash
run: |
set -euo pipefail
base_version="$(sed -n 's/.*Version = "\([^"]*\)".*/\1/p' cli/version.go)"
if [[ -z "$base_version" ]]; then
echo "::error::Could not read the base version from cli/version.go."
exit 1
fi
echo "version=${base_version}+${GITHUB_SHA:0:12}" >> "$GITHUB_OUTPUT"
- name: Build frontend for production image
env:
CHATTO_BUILD_VERSION: ${{ steps.image-version.outputs.version }}
run: mise build-frontend
- name: Verify frontend build version
env:
EXPECTED_VERSION: ${{ steps.image-version.outputs.version }}
shell: bash
run: |
jq -e --arg expected "$EXPECTED_VERSION" \
'.version == $expected' \
apps/frontend/build/_app/version.json
- name: Build production image contexts
shell: bash
env:
VERSION: ${{ steps.image-version.outputs.version }}
run: |
set -euo pipefail
for arch in amd64 arm64; do
context=".context/ci/docker/linux-${arch}"
mkdir -p "$context/docker" "$context/LICENSES"
cp docker/Dockerfile.goreleaser "$context/Dockerfile"
cp docker/docker-entrypoint.sh "$context/docker/docker-entrypoint.sh"
cp docker/nats-wrapper.sh "$context/docker/nats-wrapper.sh"
cp LICENSES/AGPL-3.0-or-later.txt "$context/LICENSES/AGPL-3.0-or-later.txt"
cp NOTICE "$context/NOTICE"
(
cd cli
CGO_ENABLED=0 GOOS=linux GOARCH="$arch" go build -trimpath \
-ldflags="-s -w -X main.Version=${VERSION}" \
-o "../$context/chatto" .
)
done
- name: Upload production image contexts
uses: actions/upload-artifact@v7
with:
name: production-image-contexts
path: .context/ci/docker
retention-days: 1
license-check:
# runs-on: ubicloud-standard-4
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup mise
uses: jdx/mise-action@v4
with:
experimental: true
- name: Check license metadata
run: mise license-check
codegen-proto-drift:
# runs-on: ubicloud-standard-4
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup environment
uses: ./.github/actions/setup
- name: Fetch protobuf breaking base
run: |
base_ref="${GITHUB_BASE_REF:-${GITHUB_REF_NAME}}"
git fetch --no-tags --depth=1 origin "${base_ref}:refs/remotes/origin/${base_ref}"
- name: Check storage and internal protobuf breaking changes
run: |
base_ref="${GITHUB_BASE_REF:-${GITHUB_REF_NAME}}"
cd proto
mise x -- buf breaking . --against "../.git#branch=origin/${base_ref},subdir=proto" \
--exclude-imports \
--exclude-path chatto/discovery/v1 \
--exclude-path chatto/api/v1 \
--exclude-path chatto/admin/v1 \
--exclude-path chatto/operator/v1 \
--exclude-path chatto/realtime/v1
- name: Check public API protobuf breaking changes
if: ${{ github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'api-breaking-change') }}
run: |
base_ref="${GITHUB_BASE_REF:-${GITHUB_REF_NAME}}"
cd proto
mise x -- buf breaking . --against "../.git#branch=origin/${base_ref},subdir=proto" \
--path chatto/discovery/v1 \
--path chatto/api/v1 \
--path chatto/admin/v1 \
--path chatto/operator/v1 \
--path chatto/realtime/v1
- name: Acknowledge intentional public API protobuf breaking changes
if: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'api-breaking-change') }}
run: |
echo "::notice::Skipping public API Buf breaking check because this PR has the api-breaking-change label. Storage/internal protobuf breaking checks and codegen drift are still checked."
- name: Regenerate protobuf bindings
run: mise codegen-proto
- name: Check generated protobuf bindings are current
run: |
if ! git diff --exit-code; then
git status --short
exit 1
fi
test-frontend-unit:
# runs-on: ubicloud-standard-4
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup environment
uses: ./.github/actions/setup
with:
install-cli-deps: "false"
- name: Setup Playwright
uses: ./.github/actions/setup-playwright
timeout-minutes: 15
- name: Run frontend typecheck
run: pnpm run check:frontend
- name: Run frontend lint
run: pnpm run lint:frontend
- name: Run frontend unit tests
run: pnpm run test:frontend
- name: Build Storybook design-system catalog
run: pnpm run build:storybook
test-cli:
# runs-on: ubicloud-standard-4
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup environment
uses: ./.github/actions/setup
- name: Build frontend
run: mise build-frontend
- name: Run Go tests
run: cd cli && go test -trimpath -p 1 -tags test_endpoints ./...
test-e2e:
# runs-on: ubicloud-standard-4
runs-on: ubuntu-latest
name: test-e2e (${{ matrix.shard }}/4)
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3, 4]
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup environment
uses: ./.github/actions/setup
- name: Setup Playwright
uses: ./.github/actions/setup-playwright
timeout-minutes: 15
- name: Build E2E server
run: mise build-e2e-server
- name: Run E2E tests
run: cd apps/frontend && pnpm exec playwright test --grep-invert @ffmpeg --shard=${{ matrix.shard }}/4
- name: Upload Playwright report
uses: actions/upload-artifact@v7
if: ${{ failure() }}
with:
name: playwright-report-${{ matrix.shard }}-of-4
path: apps/frontend/playwright-report/
retention-days: 14
test-e2e-remote-compatibility:
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup environment
uses: ./.github/actions/setup
- name: Setup Playwright
uses: ./.github/actions/setup-playwright
timeout-minutes: 15
- name: Prepare latest stable 0.4.x release
id: release
uses: ./.github/actions/prepare-released-chatto
with:
release-series: "0.4"
- name: Build current production executable with embedded frontend
run: mise build-compatibility-server
- name: Run remote compatibility smoke test
working-directory: apps/frontend
env:
CHATTO_COMPAT_CURRENT_BINARY: ${{ github.workspace }}/apps/frontend/e2e/fixtures/bin/chatto-current
CHATTO_COMPAT_REMOTE_BINARY: ${{ steps.release.outputs.path }}
CHATTO_COMPAT_REMOTE_VERSION: ${{ steps.release.outputs.version }}
run: pnpm exec playwright test --config playwright.compat.config.ts
- name: Upload remote compatibility diagnostics
uses: actions/upload-artifact@v7
if: ${{ failure() }}
with:
name: playwright-report-remote-compatibility
path: |
apps/frontend/playwright-report-remote-compatibility/
apps/frontend/test-results/
retention-days: 14
test-e2e-media:
# runs-on: ubicloud-standard-4
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Setup environment
uses: ./.github/actions/setup
timeout-minutes: 15
with:
install-ffmpeg: "true"
- name: Setup Playwright
uses: ./.github/actions/setup-playwright
timeout-minutes: 15
- name: Build E2E server
run: mise build-e2e-server
- name: Run media E2E tests
run: cd apps/frontend && pnpm exec playwright test --grep @ffmpeg
- name: Upload Playwright report
uses: actions/upload-artifact@v7
if: ${{ failure() }}
with:
name: playwright-report-media
path: apps/frontend/playwright-report/
retention-days: 14
publish-main-image:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs:
- build-main-image-contexts
- license-check
- codegen-proto-drift
- test-frontend-unit
- test-cli
- test-e2e
- test-e2e-remote-compatibility
- test-e2e-media
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Download production image contexts
uses: actions/download-artifact@v8
with:
name: production-image-contexts
path: docker-contexts
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Derive immutable main image tag
id: main-image
shell: bash
run: echo "tag=main-$(date -u +%Y%m%dT%H%M%SZ)-${GITHUB_SHA:0:12}" >> "$GITHUB_OUTPUT"
- name: Build and push amd64 image
uses: docker/build-push-action@v6
with:
context: docker-contexts/linux-amd64
file: docker-contexts/linux-amd64/Dockerfile
push: true
platforms: linux/amd64
tags: ghcr.io/chattocorp/chatto:${{ github.sha }}-amd64
cache-from: type=gha,scope=chatto-main-amd64
cache-to: type=gha,scope=chatto-main-amd64,mode=max
labels: |
org.opencontainers.image.source=https://github.com/chattocorp/chatto
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ needs.build-main-image-contexts.outputs.image-version }}
org.opencontainers.image.licenses=AGPL-3.0-or-later
- name: Build and push arm64 image
uses: docker/build-push-action@v6
with:
context: docker-contexts/linux-arm64
file: docker-contexts/linux-arm64/Dockerfile
push: true
platforms: linux/arm64
tags: ghcr.io/chattocorp/chatto:${{ github.sha }}-arm64
cache-from: type=gha,scope=chatto-main-arm64
cache-to: type=gha,scope=chatto-main-arm64,mode=max
labels: |
org.opencontainers.image.source=https://github.com/chattocorp/chatto
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=${{ needs.build-main-image-contexts.outputs.image-version }}
org.opencontainers.image.licenses=AGPL-3.0-or-later
- name: Publish multi-platform commit image
shell: bash
run: |
docker buildx imagetools create \
--tag "ghcr.io/chattocorp/chatto:${GITHUB_SHA}" \
--tag "ghcr.io/chattocorp/chatto:${{ steps.main-image.outputs.tag }}" \
"ghcr.io/chattocorp/chatto:${GITHUB_SHA}-amd64" \
"ghcr.io/chattocorp/chatto:${GITHUB_SHA}-arm64"
{
echo "### Main commit image"
echo
echo "\`ghcr.io/chattocorp/chatto:${GITHUB_SHA}\`"
echo "\`ghcr.io/chattocorp/chatto:${{ steps.main-image.outputs.tag }}\`"
echo
echo "Version: \`${{ needs.build-main-image-contexts.outputs.image-version }}\`"
} >> "$GITHUB_STEP_SUMMARY"