-
Notifications
You must be signed in to change notification settings - Fork 13
executable file
·480 lines (423 loc) · 16.7 KB
/
build.yml
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
name: Build-Test-Deploy
# === Triggers ===
"on":
push:
branches:
- master
- beta
- release
- LTS*
pull_request:
types:
- labeled
- opened
- synchronize
- reopened
schedule:
- cron: 0 0 * * *
# === Workflow Permissions ===
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
# === Workflow-level environment variables ===
env:
AWS_REGION: us-east-1
AWS_ROLE_SESSION_NAME: gha-activestate-cli
# === JOBS ===
jobs:
# === OS Specific Job (runs on each OS) ===
os_specific:
name: ${{ matrix.sys.os }}
timeout-minutes: 90
strategy:
matrix:
go-version:
- 1.20.x
sys:
- {os: ubuntu-20.04}
- {os: macos-11, shell: zsh}
- {os: windows-2019}
fail-fast: false
runs-on: ${{ matrix.sys.os }}
env:
ACTIVESTATE_CI: true
ACTIVESTATE_CLI_DISABLE_RUNTIME: true
SHELL: bash
GITHUB_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
concurrency:
group: ${{ github.ref }}-${{ github.event_name }}-${{ matrix.sys.os }}
cancel-in-progress: true
# === OS Specific Steps ===
steps:
- # === Disable Windows Defender as it slows things down significantly ===
name: Disabling Windows Defender
if: runner.os == 'Windows'
shell: powershell
run: Set-MpPreference -DisableRealtimeMonitoring $true
- # === Checkout Code ===
name: Checkout code
uses: actions/checkout@v2
- # === Install Go ===
name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
# === Install gotestfmt ===
- name: Set up gotestfmt
uses: gotesttools/gotestfmt-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
- # === Install State Tool ===
name: Install State Tool
uses: ActiveState/setup-state-tool@v1
- # === Setup ===
name: Setup
shell: bash
run: |
bin=$(pwd)/.github/deps/${{ runner.os }}/bin
echo "Adding $bin to PATH"
echo "$bin" >> $GITHUB_PATH
if [ -x "$(command -v apt-get)" ]; then
sudo apt-get update
sudo apt-get install fish zsh tcsh -y
# Prevent zsh insecure directory warning.
sudo chmod -R 755 /usr/share/zsh/vendor-completions /usr/share/zsh
sudo chown -R root:root /usr/share/zsh/vendor-completions /usr/share/zsh
touch ~/.zshrc
fi
printenv
- # === Setup Windows ===
name: Setup (Windows)
shell: pwsh
run: |
echo "${PSScriptRoot}/.github/deps/${{ runner.os }}/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
state run install-deps-ci
- # == Setup macOS ==
name: Setup (macOS)
shell: bash
run: brew install fish
if: runner.os == 'macOS'
- # === Preprocess ===
name: Preprocess
shell: bash
timeout-minutes: 3
run: state run preprocess -v
- # === Parallel Tasks ===
name: Parallel Tasks
shell: bash
timeout-minutes: 15
run: |
export PATH="$(pwd)/.github/deps/${{ runner.os }}/bin:$PATH"
parallelize "$(cat <<'EOF'
[
{
"ID": "Unit-Tests",
"Args": ["state", "run", "test", "-json", "2>&1"]
},
{
"ID": "Build-CLI",
"Args": ["state", "run", "build"]
},
{
"ID": "Build-Service",
"Args": ["state", "run", "build-svc"]
},
{
"ID": "Build-Installer",
"Args": ["state", "run", "build-installer"]
},
{
"ID": "Build-Remote-Installer",
"Args": ["state", "run", "build-remote-installer"]
},
{
"ID": "Build-Install-Scripts",
"Args": ["state", "run", "build-install-scripts"]
},
{
"ID": "Build-Executor",
"Args": ["state", "run", "build-exec"]
}
]
EOF
)"
env:
CODE_SIGNING_PASSWD: ${{ secrets.CODE_SIGNING_PASSWD }}
MSI_CERT_BASE64: ${{ secrets.MSI_CERT_BASE64 }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
JIRA_USERNAME: ${{ secrets.JIRA_EMAIL }}
JIRA_TOKEN: ${{ secrets.JIRA_TOKEN }}
- # === Unit Tests ===
name: Unit Tests
id: unit_tests
shell: bash
run: parallelize results Unit-Tests | gotestfmt -hide empty-packages
continue-on-error: ${{ github.event_name != 'schedule' }}
- # === "Build: CLI" ===
name: "Build: CLI"
shell: bash
run: parallelize results Build-CLI
- # === "Build: Service" ===
name: "Build: Service"
shell: bash
run: parallelize results Build-Service
- # === "Build: Installer" ===
name: "Build: Installer"
shell: bash
run: parallelize results Build-Installer
- # === "Build: Remote Installer" ===
name: "Build: Remote Installer"
shell: bash
run: parallelize results Build-Remote-Installer
- # === "Build: Install Scripts" ===
name: "Build: Install Scripts"
shell: bash
run: parallelize results Build-Install-Scripts
- # === "Build: Executor" ===
name: "Build: Executor"
shell: bash
run: parallelize results Build-Executor
- # === Prepare Windows Cert ===
name: Prepare Windows Cert
shell: bash
if: runner.os == 'Windows'
run: |
echo $MSI_CERT_BASE64 | base64 --decode > Cert.p12
env:
MSI_CERT_BASE64: ${{ secrets.MSI_CERT_BASE64 }}
- # === Sign Binaries (Windows only) ===
name: Sign Binaries (Windows only)
shell: bash
if: runner.os == 'Windows' && contains(fromJSON('["refs/heads/beta", "refs/heads/release", "refs/heads/LTS"]'), github.ref)
run: |
export PATH=/c/Program\ Files\ \(x86\)/WiX\ Toolset\ v3.11/bin/:/c/Program\ Files\ \(x86\)/Windows\ Kits/10/bin/10.0.16299.0/x86/:$PATH
signtool.exe sign -d "ActiveState State Tool" -f "Cert.p12" -p ${CODE_SIGNING_PASSWD} ./build/state.exe
signtool.exe sign -d "ActiveState State Service" -f "Cert.p12" -p ${CODE_SIGNING_PASSWD} ./build/state-svc.exe
signtool.exe sign -d "ActiveState State Installer" -f "Cert.p12" -p ${CODE_SIGNING_PASSWD} ./build/state-installer.exe
signtool.exe sign -d "ActiveState State Tool Remote Installer" -f "Cert.p12" -p ${CODE_SIGNING_PASSWD} ./build/state-remote-installer.exe
env:
CODE_SIGNING_PASSWD: ${{ secrets.CODE_SIGNING_PASSWD }}
- # === Sign Install Scripts (Windows only) ===
name: Sign Install Scripts (Windows only)
shell: powershell
if: runner.os == 'Windows' && contains(fromJSON('["refs/heads/beta", "refs/heads/release", "refs/heads/LTS"]'), github.ref)
run: |
$branchInfix = $Env:GITHUB_REF.Replace("refs/heads/", "").Replace("release", "")
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import('Cert.p12',$env:CODE_SIGNING_PASSWD,'DefaultKeySet')
Set-AuthenticodeSignature -FilePath build\installers\$branchInfix\install.ps1 -Certificate $cert
Set-AuthenticodeSignature -FilePath build\installers\$branchInfix\legacy-install.ps1 -Certificate $cert
env:
CODE_SIGNING_PASSWD: ${{ secrets.CODE_SIGNING_PASSWD }}
- # === Generate Update ===
name: Generate Update
shell: bash
run: state run generate-update
- # === Generate Remote Install Deployment ==
name: Generate Remote Install Deployment
shell: bash
run: state run generate-remote-install-deployment
- # === Configure AWS credentials ==
name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-session-name: ${{ env.AWS_ROLE_SESSION_NAME }}
aws-region: ${{ env.AWS_REGION }}
mask-aws-account-id: true
- # === Deploy for Integration Tests # NEVER run this against production branches. This is meant for PR deployments. ===
name: Deploy for Integration Tests # NEVER run this against production branches. This is meant for PR deployments.
if: "!contains(fromJSON('[\"refs/heads/beta\", \"refs/heads/release\", \"refs/heads/LTS\"]'), github.ref)"
shell: bash
run: |
if [ "$GITHUB_EVENT_NAME" != "schedule" ]; then
set +e
LABELS="${{ join(github.event.pull_request.labels.*.name, ',') }}"
LABELCHECK="$(echo $LABELS | grep "Test:")" # This line is causing a non-zero exit if `set -e` is set, and I can't figure out why
TARGET_BRANCH="${{ github.event.pull_request.base.ref }}"
set -e
echo "Labels: $LABELS"
echo "Target Branch: $TARGET_BRANCH"
if [ "$LABELCHECK" == "" ] && [ "$TARGET_BRANCH" != "beta" ] && [ "$TARGET_BRANCH" != "release" ] && [[ -z "`echo $TARGET_BRANCH | grep -o '^LTS'`" ]]; then
echo "Not running because no test labels were set nor beta, release or LTS were targeted."
exit 0
fi
fi
state run deploy-updates
state run deploy-installers
state run deploy-remote-installer
- # === Integration Tests ===
name: Integration Tests
id: integration_tests
if: "!contains(fromJSON('[\"refs/heads/beta\", \"refs/heads/release\", \"refs/heads/LTS\"]'), github.ref)"
shell: bash
run: |
if [ "$GITHUB_EVENT_NAME" != "schedule" ]; then
LABELS="${{ join(github.event.pull_request.labels.*.name, ',') }}"
IFS=',' read -r -a TESTS <<< "$LABELS"
TEST_SUITE_TAGS=""
for i in "${TESTS[@]}"; do
START=${i%:*}
if [ "$START" == "Test" ]; then
TAG=${i##*:}
TAG=$(echo $TAG | xargs)
if [[ "$TEST_SUITE_TAGS" == "" ]]; then
TEST_SUITE_TAGS=$TAG
else
TEST_SUITE_TAGS="$TAG:$TEST_SUITE_TAGS"
fi
fi
done
TARGET_BRANCH="${{ github.event.pull_request.base.ref }}"
echo "Target branch: $TARGET_BRANCH"
if [ "$TEST_SUITE_TAGS" == "" ] && [ "$TARGET_BRANCH" != "master" ] && [ "$TARGET_BRANCH" != "beta" ] && [ "$TARGET_BRANCH" != "release" ] && [ "$TARGET_BRANCH" != "lts-release" ]; then
echo "Not running because no test labels were set nor master, beta or release were targeted."
exit 0
fi
else
TEST_SUITE_TAGS="all"
fi
echo "Running integration tests with tags: $TEST_SUITE_TAGS (empty means every test not specifically tagged)"
export TEST_SUITE_TAGS="$TEST_SUITE_TAGS"
TIMEOUT=30m
if [[ "$TEST_SUITE_TAGS" == "all" ]]; then
TIMEOUT=60m
fi
SHELL='${{ matrix.sys.shell }}' go test -timeout $TIMEOUT -v `go list ./... | grep "integration"` -json 2>&1 | gotestfmt -hide empty-packages
continue-on-error: ${{ github.event_name == 'schedule' }}
env:
INTEGRATION_TEST_USERNAME: ${{ secrets.INTEGRATION_TEST_USERNAME }}
INTEGRATION_TEST_PASSWORD: ${{ secrets.INTEGRATION_TEST_PASSWORD }}
INTEGRATION_TEST_TOKEN: ${{ secrets.INTEGRATION_TEST_TOKEN }}
PLATFORM_API_TOKEN: ${{ secrets.PLATFORM_API_TOKEN }}
- # === Fail If Unscheduled Unit Tests Failed (Expand 'Unit Tests' above for more information) ===
name: Fail If Unscheduled Unit Tests Failed
if: github.event_name != 'schedule' && steps.unit_tests.outcome == 'failure'
shell: bash
run: exit 1
- # === Notify Slack of Nightly Integration Test Failures ===
name: Notify Slack of Nightly Integration Test Failures
if: github.event_name == 'schedule' && steps.integration_tests.outcome == 'failure'
uses: slackapi/[email protected]
with:
payload: |
{
"text": "Nightly integration test failure(s) on ${{ runner.os }}",
"blocks": [
{
"type": "section",
"text": {
"type": "plain_text",
"text": "Nightly integration test failure(s) on ${{ runner.os }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
},
{
"type": "section",
"text": {
"type": "plain_text",
"text": "Select the '${{ matrix.sys.os }}' job and expand 'Integration Tests' to inspect the failures."
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
- # === Fail If Nightly Integration Tests Failed (Expand 'Integration Tests' above for more information) ===
name: Fail If Nightly Integration Tests Failed
if: github.event_name == 'schedule' && steps.integration_tests.outcome == 'failure'
shell: bash
run: exit 1
- # === Upload Session Artifacts ===
name: Upload Session Artifacts
uses: actions/upload-artifact@v2
with:
name: session-build-${{ matrix.sys.os }}
path: build/
# === Deploy job (runs once with combined artifacts from OS specific job) ===
deploy:
name: Deploy
needs:
- os_specific
runs-on: ubuntu-20.04
env:
ACTIVESTATE_CI: true
ACTIVESTATE_CLI_DISABLE_RUNTIME: true
SHELL: bash
GITHUB_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
timeout-minutes: 10
if: contains(fromJSON('["refs/heads/master", "refs/heads/beta", "refs/heads/release", "refs/heads/LTS"]'), github.ref) || startsWith(github.event.pull_request.head.ref, 'version/')
# === Deploy Steps ===
steps:
- # === Checkout code ===
name: Checkout code
uses: actions/checkout@v2
- # === Install Go ===
name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
- # === Install State Tool ===
name: Install State Tool
uses: ActiveState/setup-state-tool@v1
- # === Download All Build Session Artifacts ===
name: Download All Build Session Artifacts
uses: actions/download-artifact@v2
with:
path: build/
- # === Sanitize All Session Artifacts ===
name: Sanitize All Session Artifacts
shell: bash
run: |
cd build
rm -Rf session-shared-build
find . -mindepth 2 -maxdepth 2 -print0 | xargs -0 -I file rsync -av file .
rm -Rf session*
- # === Preprocess ===
name: Preprocess
shell: bash
run: state run preprocess -v
- # === Cleanup Build Dir ===
name: Cleanup Build Dir
shell: bash
run: rm build/state* || true
- # === Configure AWS credentials ==
name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-session-name: ${{ env.AWS_ROLE_SESSION_NAME }}
aws-region: ${{ env.AWS_REGION }}
mask-aws-account-id: true
- # === Generate updated master versions.json if necessary ===
name: Generate version list
shell: bash
run: state run generate-versions-list
- # === Deploy ===
name: Deploy
shell: bash
run: |
state run deploy-updates
state run deploy-installers
state run deploy-remote-installer
- # === Cleanup Session Artifacts ===
name: Cleanup Session Artifacts
uses: geekyeggo/delete-artifact@v1
with:
name: |
session-build-ubuntu-20.04
session-build-macos-11
session-build-windows-2019
- # === Upload Artifacts ===
name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: build
path: build/