-
Notifications
You must be signed in to change notification settings - Fork 6
453 lines (379 loc) · 13 KB
/
Copy pathtest-and-build.yml
File metadata and controls
453 lines (379 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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
name: Build and Release
on:
push:
branches: [ main ]
tags: [ 'v*' ]
paths-ignore:
- '**/README.md'
- 'examples/**'
- 'docs/**'
- 'config/**'
- 'deploy/**'
pull_request:
branches: [ main ]
paths-ignore:
- '**/README.md'
- 'examples/**'
- 'docs/**'
- 'config/**'
- 'deploy/**'
permissions:
contents: write
packages: write
env:
GO_VERSION: '1.26'
GOEXPERIMENT: 'jsonv2'
MACOS_XCODE_VERSION: 'latest-stable'
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
unit-tests:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: recursive
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Run unit tests
run: |
make gen-buf
# Run all tests except functional and integration tests
go test -v -short $(go list ./... | grep -v '/test/functional' | grep -v '/test/integration')
workflowcheck:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: recursive
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Install workflowcheck
run: go install go.temporal.io/sdk/contrib/tools/workflowcheck@v0.4.0
- name: Run workflowcheck
run: |
make gen-buf
workflowcheck -test=false -config workflowcheck.yaml ./internal/... ./sdk/...
functional-tests:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: recursive
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Run functional tests
run: |
make gen-buf
# Run functional tests (these use testcontainers/Docker)
# Docker is available by default on ubuntu-latest runners
cd test && go test -v -timeout 10m ./functional/...
integration-services:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: recursive
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Run services integration tests
run: |
make gen-buf
cd test && go test -v -timeout 5m ./integration/services/...
integration-workflows:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: recursive
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Run workflows integration tests
run: |
make gen-buf
cd test && go test -v -timeout 15m ./integration/workflows/...
build-linux-amd64:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: recursive
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Build linux/amd64 binary
run: make build-linux-amd64
- name: Upload linux/amd64 binary
uses: actions/upload-artifact@v4
with:
name: thand-linux-amd64
path: bin/thand-linux-amd64
retention-days: 1
macos-validation:
runs-on: macos-latest
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: recursive
- name: Select Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: ${{ env.MACOS_XCODE_VERSION }}
- name: Capture Xcode version
id: xcode
run: |
VERSION=$(xcodebuild -version | tr '\n' ' ' | sed 's/ */ /g')
echo "version=$VERSION" >> $GITHUB_OUTPUT
xcodebuild -version
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Install XcodeGen
run: |
brew list xcodegen >/dev/null 2>&1 || brew install xcodegen
xcodegen version
- name: Cache macOS DerivedData
uses: actions/cache@v4
with:
path: .build/macos/DerivedData
key: macos-deriveddata-${{ runner.os }}-${{ steps.xcode.outputs.version }}-${{ hashFiles('proto/localbroker/**/*.proto', 'buf*.yaml', 'platform/macos/PrivilegeServices/project.yml', 'platform/macos/PrivilegeServices/**/*.swift', 'platform/macos/PrivilegeServices/**/*.plist', 'platform/macos/PrivilegeServices/**/*.entitlements', 'platform/macos/PrivilegeServices/**/*.template', 'scripts/*macos-privilege-services*.sh', 'scripts/localbroker-codegen-common.sh', 'Makefile') }}
restore-keys: |
macos-deriveddata-${{ runner.os }}-${{ steps.xcode.outputs.version }}-
- name: Build
run: make build
- name: Test
run: make test
- name: Verify unsigned package layout
run: THAND_MACOS_SKIP_SIGNING=1 make package-macos-privilege-services-dev
integration-frontend:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
needs: [build-linux-amd64]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: recursive
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Download linux/amd64 binary
uses: actions/download-artifact@v4
with:
name: thand-linux-amd64
path: bin/
- name: Make binary executable
run: chmod +x bin/thand-linux-amd64
- name: Install Chrome/Chromium
run: |
sudo apt-get update
sudo apt-get install -y chromium-browser
- name: Run frontend E2E integration tests
run: |
make gen-buf
cd test && go test -v -timeout 30m ./integration/frontend/...
env:
DISPLAY: :99
CHROME_BIN: /usr/bin/chromium-browser
auto-tag:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
outputs:
new-tag: ${{ steps.bump.outputs.new-version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get latest tag
id: latest-tag
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "latest-tag=$LATEST_TAG" >> $GITHUB_OUTPUT
- name: Bump version
id: bump
run: |
LATEST_TAG=${{ steps.latest-tag.outputs.latest-tag }}
# Remove 'v' prefix and split version
VERSION=${LATEST_TAG#v}
IFS='.' read -ra VERSION_PARTS <<< "$VERSION"
MAJOR=${VERSION_PARTS[0]:-0}
MINOR=${VERSION_PARTS[1]:-0}
PATCH=${VERSION_PARTS[2]:-0}
# Check commit messages for version bump indicators
if git log --format=%B -n 1 | grep -qi "BREAKING CHANGE\|major:"; then
NEW_VERSION="v$((MAJOR + 1)).0.0"
elif git log --format=%B -n 1 | grep -qi "feat:\|feature:\|minor:"; then
NEW_VERSION="v$MAJOR.$((MINOR + 1)).0"
else
NEW_VERSION="v$MAJOR.$MINOR.$((PATCH + 1))"
fi
echo "new-version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Bumping from $LATEST_TAG to $NEW_VERSION"
- name: Create and push tag
run: |
NEW_VERSION=${{ steps.bump.outputs.new-version }}
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a $NEW_VERSION -m "Auto-release $NEW_VERSION"
git push origin $NEW_VERSION
build:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: [auto-tag, unit-tests, functional-tests, integration-services, integration-workflows, integration-frontend]
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: recursive
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Get version from auto-tag
id: version
run: |
VERSION="${{ needs.auto-tag.outputs.new-tag }}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Build for ${{ matrix.goos }}/${{ matrix.goarch }}
run: |
make gen-buf
VERSION=${{ steps.version.outputs.version }}
COMMIT=${{ steps.version.outputs.commit }}
GOOS=${{ matrix.goos }}
GOARCH=${{ matrix.goarch }}
# Create dist directory
mkdir -p dist
# Set output name
output_name="agent"
if [ "$GOOS" = "windows" ]; then
output_name="agent.exe"
fi
echo "Building for $GOOS/$GOARCH..."
GOEXPERIMENT=jsonv2 CGO_ENABLED=0 GOOS=$GOOS GOARCH=$GOARCH go build -a -installsuffix cgo \
-ldflags "-X github.com/thand-io/agent/internal/common.Version=$VERSION -X github.com/thand-io/agent/internal/common.GitCommit=$COMMIT" \
-o "dist/$output_name" .
# Create archive
if [ "$GOOS" = "windows" ]; then
cd dist && zip "agent-${GOOS}-${GOARCH}.zip" "$output_name" && cd ..
else
cd dist && tar -czf "agent-${GOOS}-${GOARCH}.tar.gz" "$output_name" && cd ..
fi
# Also keep the binary for direct download
mv "dist/$output_name" "dist/agent-${GOOS}-${GOARCH}$([ "$GOOS" = "windows" ] && echo ".exe" || echo "")"
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.goos }}-${{ matrix.goarch }}-${{ steps.version.outputs.version }}
path: dist/
docker-release:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: [auto-tag, build]
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Get version from auto-tag
id: version
run: |
VERSION="${{ needs.auto-tag.outputs.new-tag }}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "commit=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
pattern: binaries-*-${{ steps.version.outputs.version }}
path: dist/
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for release
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=dev
type=raw,value=${{ steps.version.outputs.version }}
- name: Build and push Docker image (dev + version tags)
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.cicd
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ steps.version.outputs.version }}
COMMIT=${{ steps.version.outputs.commit }}
cache-from: type=gha
cache-to: type=gha,mode=max