-
Notifications
You must be signed in to change notification settings - Fork 13
/
activestate.yaml
512 lines (489 loc) · 18.9 KB
/
activestate.yaml
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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
project: https://platform.activestate.com/ActiveState/cli?branch=main&commitID=9eee7512-b2ab-4600-b78b-ab0cf2e817d8
constants:
- name: CLI_BUILDFLAGS
value: -ldflags="-s -w"
- name: CLI_PKGS
value: ./cmd/state
- name: DAEMON_PKGS
value: ./cmd/state-svc
- name: INSTALLER_PKGS
value: ./cmd/state-installer
- name: EXECUTOR_PKGS
value: ./cmd/state-exec
- name: BUILD_TARGET_PREFIX_DIR
value: ./build
- name: BUILD_TARGET
if: ne .OS.Name "Windows"
value: state
- name: SVC_BUILDFLAGS
if: ne .OS.Name "Windows"
value: $constants.CLI_BUILDFLAGS
- name: BUILD_DAEMON_TARGET
if: ne .OS.Name "Windows"
value: state-svc
- name: BUILD_EXEC_TARGET
if: ne .OS.Name "Windows"
value: state-exec
- name: BUILD_INSTALLER_TARGET
if: ne .OS.Name "Windows"
value: state-installer
- name: BUILD_REMOTE_INSTALLER_TARGET
value: state-remote-installer
- name: INTEGRATION_TEST_REGEX
value: 'integration\|automation'
- name: SET_ENV
description: The environment settings used throughout our project
value: |
GOPATH="${GOPATH:=`go env GOPATH`}"
GOROOT="${GOROOT:=`go env GOROOT`}"
export CGO_ENABLED=0
PATH="${GOROOT}/bin:${GOPATH}/bin:${PATH}"
BUILD_EXEC_TARGET=$constants.BUILD_EXEC_TARGET
# add the GOARCH as infix to BUILD_TARGET_DIR if not amd64
BUILD_TARGET_DIR=$constants.BUILD_TARGET_PREFIX_DIR/${GOARCH#amd64}
- name: SCRIPT_EXT
if: ne .OS.Name "Windows"
value: .sh
scripts:
- name: install-deps-dev
language: bash
standalone: true
if: ne .Shell "cmd"
value: |
if ! type "go" &> /dev/null; then
echo "go is not installed. Please install Go version 1.22 or above."
exit 1
fi
if ! type "golangci-lint" &> /dev/null; then
echo "golangci-lint was not found on your PATH. Installing .."
go install github.com/golangci/golangci-lint/cmd/[email protected]
fi
git config core.hooksPath .githooks
if ! type "swagger" &> /dev/null; then
echo "swagger was not found on your PATH. Installing .."
go install github.com/go-swagger/go-swagger/cmd/[email protected]
fi
if ! type "actionlint" &> /dev/null; then
echo "actionlint was not found on your PATH. Installing .."
go install github.com/rhysd/actionlint/cmd/[email protected]
fi
if { [[ "$GOOS" == "windows" ]] || [[ "$OS" == "Windows_NT" ]]; } && ! type "goversioninfo" &> /dev/null; then
echo "goversioninfo was not found on your PATH. Installing .."
GOFLAGS="" go install github.com/josephspurrier/goversioninfo/cmd/[email protected]
fi
- name: install-deps-os
language: bash
standalone: true
if: ne .OS.Name "Linux"
description: Install OS specific deps
value: ""
- name: install-deps-ci
language: bash
standalone: true
if: ne .Shell "cmd"
value: |
if { [[ "$GOOS" == "windows" ]] || [[ "$OS" == "Windows_NT" ]]; } && ! type "goversioninfo" &> /dev/null; then
echo "goversioninfo was not found on your PATH. Installing .."
GOFLAGS="" go install github.com/josephspurrier/goversioninfo/cmd/[email protected]
fi
- name: preprocess
language: bash
standalone: true
description: Generates assets required by the project that aren't just specific to the build
value: |
set -e
$constants.SET_ENV
go run scripts/constants-generator/main.go ${@} -- internal/constants/generated.go
if [[ "$GOOS" == "windows" || "$OS" == "Windows_NT" ]]; then
go run scripts/versioninfo-generator/main.go version.txt cmd/state/versioninfo.json "State Tool"
go run scripts/versioninfo-generator/main.go version.txt cmd/state-svc/versioninfo.json "State Service"
fi
- name: build
language: bash
standalone: true
description: Builds the project with the host OS as the target OS.
value: |
set -e
$constants.SET_ENV
# Generate resource.syso for Windows
if [[ "$GOOS" == "windows" || "$OS" == "Windows_NT" ]]; then
pushd cmd/state > /dev/null
go generate
popd > /dev/null
fi
go build -tags "$GO_BUILD_TAGS" -o $BUILD_TARGET_DIR/$constants.BUILD_TARGET $constants.CLI_BUILDFLAGS $constants.CLI_PKGS
- name: build-for
language: bash
standalone: true
description: Builds the project with the specified OS as the target OS. (valid values darwin, linux, windows)
value: |
set -e
$constants.SET_ENV
export GOOS=${1}
export GOARCH=amd64
[ -z "${2}" ] && >&2 echo "must provide output file as 2nd arg" && exit 1
go build -tags "internal $GO_BUILD_TAGS" -o ${2} $constants.CLI_BUILDFLAGS $constants.CLI_PKGS
- name: build-svc
language: bash
standalone: true
description: Builds the state-svc daemon
value: |
set -e
$constants.SET_ENV
# Generate resource.syso for Windows
if [[ "$GOOS" == "windows" || "$OS" == "Windows_NT" ]]; then
pushd cmd/state-svc > /dev/null
go generate
popd > /dev/null
fi
go build -tags "$GO_BUILD_TAGS" -o $BUILD_TARGET_DIR/$constants.BUILD_DAEMON_TARGET $constants.SVC_BUILDFLAGS $constants.DAEMON_PKGS
- name: build-exec
description: Builds the State Executor application
language: bash
standalone: true
value: |
set -e
$constants.SET_ENV
go build -tags "$GO_BUILD_TAGS" -o $BUILD_TARGET_DIR/$constants.BUILD_EXEC_TARGET $constants.CLI_BUILDFLAGS $constants.EXECUTOR_PKGS
- name: build-all
description: Builds all our tools
language: bash
standalone: true
value: |
set -e
echo "Building State Tool"
$scripts.build.path()
echo "Building State Installer"
$scripts.build-installer.path()
echo "Building State Remote Installer"
$scripts.build-remote-installer.path()
echo "Building State Service"
$scripts.build-svc.path()
echo "Building State Executor"
$scripts.build-exec.path()
- name: build-installer
language: bash
standalone: true
description: Builds the state-installer
value: |
set -e
$constants.SET_ENV
go build -tags "$GO_BUILD_TAGS" -o $BUILD_TARGET_DIR/$constants.BUILD_INSTALLER_TARGET $constants.INSTALLER_PKGS
- name: build-remote-installer
language: bash
standalone: true
description: Builds the state-remote-installer
value: |
set -e
$constants.SET_ENV
TARGET=$constants.BUILD_REMOTE_INSTALLER_TARGET
if [[ "$GOOS" == "windows" || "$OS" == "Windows_NT" ]]; then
TARGET="${constants.BUILD_REMOTE_INSTALLER_TARGET}.exe"
fi
GOFLAGS="" go install github.com/josephspurrier/goversioninfo/cmd/[email protected]
cd cmd/state-remote-installer
go generate
go build -tags "$GO_BUILD_TAGS" -o ../../$BUILD_TARGET_DIR/$TARGET .
- name: install
language: bash
standalone: true
description: Installs the current HEAD version into GOBIN
value: |
$constants.SET_ENV
go install $constants.CLI_BUILDFLAGS $CLI_PKGS
- name: deploy-updates
language: bash
standalone: true
description: Deploys update files to S3. This steps is automated by CI and should never be ran manually unless you KNOW WHAT YOU'RE DOING.
value: |
set -e
$constants.SET_ENV
echo "If using tokens make sure to run 'go run extras/aws-mfa-auth/main.go' on TheHomeRepot first."
go run scripts/ci/s3-deployer/main.go ${constants.BUILD_TARGET_PREFIX_DIR}/update us-east-1 state-tool update/state
- name: build-install-scripts
language: bash
standalone: true
description: Replaces installer channel with branch and copies install scripts to build dir
value: |
set -e
if [ "$GITHUB_HEAD_REF" != "" ]; then
BRANCH=${GITHUB_HEAD_REF}
elif [ "$GITHUB_REF" != "" ]; then
BRANCH=$(echo $GITHUB_REF | awk -F'/' '{print $NF}')
else
BRANCH=$(git rev-parse --abbrev-ref HEAD)
fi
if [ "$BRANCH" == "" ]; then
echo "Branch cannot be empty"
exit 1
fi
if [ "$BRANCH" == "release" ]; then
BRANCH=""
fi
INSTALLERS_DIR=build/installers/$BRANCH
mkdir -p $INSTALLERS_DIR
echo "Copying to $INSTALLERS_DIR"
cp installers/legacy-install.sh $INSTALLERS_DIR/legacy-install${constants.SCRIPT_EXT}
if [ "$BRANCH" != "" ]; then
sed "s/\(CHANNEL[[:space:]]*=[[:space:]]*\)\"release\"/\\1\"${BRANCH/\//\\/}\"/" installers/install${constants.SCRIPT_EXT} > $INSTALLERS_DIR/install${constants.SCRIPT_EXT}
else
cp installers/install${constants.SCRIPT_EXT} $INSTALLERS_DIR/install${constants.SCRIPT_EXT}
fi
cp installers/stop${constants.SCRIPT_EXT} $INSTALLERS_DIR/stop${constants.SCRIPT_EXT}
- name: deploy-installers
language: bash
standalone: true
description: Deploys update files to S3. This steps is automated by CI and should never be ran manually unless you KNOW WHAT YOU'RE DOING.
value: |
go run scripts/ci/s3-deployer/main.go build/installers us-east-1 state-tool update/state
- name: deploy-remote-installer
language: bash
standalone: true
value: |
set -e
$constants.SET_ENV
go run scripts/ci/s3-deployer/main.go $BUILD_TARGET_DIR/remote-installer us-east-1 state-tool remote-installer
- name: build-workflow-assets
language: bash
standalone: true
description: Generates our github workflows
value: |
$scripts.build-for.path() "windows" ./.github/deps/Windows/bin/state.exe
$scripts.build-for.path() "linux" ./.github/deps/Linux/bin/state
$scripts.build-for.path() "darwin" ./.github/deps/macOS/bin/state
GOOS=windows go build -o .github/deps/Windows/bin/parallelize.exe github.com/ActiveState/cli/scripts/ci/parallelize/
GOOS=linux go build -o .github/deps/Linux/bin/parallelize github.com/ActiveState/cli/scripts/ci/parallelize/
GOOS=darwin go build -o .github/deps/macOS/bin/parallelize github.com/ActiveState/cli/scripts/ci/parallelize/
- name: update-workflow-assets
language: bash
standalone: true
description: Generates our github workflows
value: |
[ -z "${2}" ] && >&2 echo "Usage: update-workflow-assets [branch] [version]" && exit 1
tmpDir=$(mktemp -d)
pushd $tmpDir
wget https://state-tool.s3.amazonaws.com/update/state/${1}/${2}/darwin-amd64/state-darwin-amd64-${2}.tar.gz
tar xzf state-darwin-amd64-${2}.tar.gz
cp -Rfv state-install/bin/state $project.path()/.github/deps/macOS/bin
cp -Rfv state-install/bin/state-svc $project.path()/.github/deps/macOS/bin
popd
rm -Rf $tmpDir
tmpDir=$(mktemp -d)
pushd $tmpDir
wget https://state-tool.s3.amazonaws.com/update/state/${1}/${2}/linux-amd64/state-linux-amd64-${2}.tar.gz
tar xzf state-linux-amd64-${2}.tar.gz
cp -Rfv state-install/bin/state $project.path()/.github/deps/Linux/bin
cp -Rfv state-install/bin/state-svc $project.path()/.github/deps/Linux/bin
popd
rm -Rf $tmpDir
tmpDir=$(mktemp -d)
pushd $tmpDir
wget https://state-tool.s3.amazonaws.com/update/state/${1}/${2}/windows-amd64/state-windows-amd64-${2}.zip
unzip state-windows-amd64-${2}.zip
cp -Rfv state-install/bin/state.exe $project.path()/.github/deps/Windows/bin
cp -Rfv state-install/bin/state-svc.exe $project.path()/.github/deps/Windows/bin
popd
rm -Rf $tmpDir
- name: test
language: bash
standalone: true
description: Runs unit tests (not integration tests)
value: |
go test -v `go list ./... | grep -v integration | grep -v automation | grep -v expect | grep -v state-svc | grep -v state-offline` $@
- name: integration-tests
language: bash
standalone: true
description: Runs integration tests.
value: |
unset ACTIVESTATE_ACTIVATED
export INTEGRATION_TEST_USERNAME=$secrets.project.INTEGRATION_TEST_USERNAME
export INTEGRATION_TEST_PASSWORD=$secrets.project.INTEGRATION_TEST_PASSWORD
go test `go list ./... | grep "${INTEGRATION_TEST_REGEX}"` -v "${@:1}" -timeout 20m
- name: integration-tests-build-check
language: bash
standalone: true
description: Builds integration tests and removes the executable artifact(s).
value: |
out="x.test"
go list ./... | grep "${INTEGRATION_TEST_REGEX}" | xargs -L 1 go test -o $out -c
[ -f $out ] && rm $out
- name: clean
language: bash
standalone: true
description: Cleans out the build dir.
value: |
go clean
rm -Rf build
- name: run
language: bash
standalone: true
description: Builds the State Tool and runs it with `--help`
value: |
$scripts.build.path()
build/state --help
- name: debug
language: bash
standalone: true
description: "Runs a remote debugger that can be hooked into from your IDE. Example usage: `state run debug activate` (will debug `state activate`)"
value: dlv debug --headless --listen=:2346 --api-version=2 github.com/ActiveState/cli/cmd/state -- $@
- name: scripted
language: bash
standalone: true
description: "Runs a command via 'go run'"
value: go run github.com/ActiveState/cli/cmd/state $@
- name: story-cleanup
language: bash
standalone: true
description: "Runs Python script to move old stories from primary project to storage project"
value: |
export PT_API_TOKEN=$secrets.project.PT_API_TOKEN
export PT_PROJID_PRIMARY=$secrets.project.PT_PROJID_PRIMARY
export PT_PROJID_STORAGE=$secrets.project.PT_PROJID_STORAGE
export PT_DAYS_AGED=190 # set this value to control cleanup
python3 ./scripts/story-cleanup/story-cleanup.py
- name: lint
language: bash
standalone: true
description: "Runs linting for untracked and unstaged changes (if any), or staged changes"
value: |
golangci-lint run --new
actionlint
- name: lint-staged
language: bash
standalone: true
description: "Runs linting for staged changes (skipping untracked and unstaged-only files)"
value: |
golangci-lint run \
--new-from-rev=HEAD~ \
--skip-files="$(git ls-files --others --exclude-standard -z | xargs -0 -I{} echo "^"{})" \
--skip-files="$(comm -13 <(git diff --cached --name-only | sort) <(git diff --name-only | sort))"
actionfiles=$(git diff --cached --name-only --diff-filter=ACM | grep '^.github/workflows/' | grep '.yml$')
[ -z "$actionfiles" ] && exit 0
actionlint $actionfiles
- name: lint-all
language: bash
standalone: true
description: "Runs linting for all files"
value: |
golangci-lint run --no-config
actionlint
- name: check-format
language: bash
standalone: true
description: "Checks if the code is formatted correctly"
value: |
set -e
TARGET_BRANCH=$GITHUB_BASE_REF
if [ "$GITHUB_BASE_REF" == "" ]; then
TARGET_BRANCH="master"
fi
if [ "$TARGET_BRANCH" == "master" ]; then
echo "Target branch is master, not checking for newlines"
exit 0
fi
git fetch --quiet origin $TARGET_BRANCH:refs/remotes/origin/$TARGET_BRANCH
CHANGED=$(git diff --name-only origin/$TARGET_BRANCH | grep -v testdata | grep -v vendor)
NO_NEWLINE=0
for FILE in $CHANGED; do
if file "$FILE" | grep -q -E 'text|ASCII'; then
if [ $(tail -c 1 "$FILE" | wc -l) -eq 0 ]; then
echo "Missing newline at end of file: $FILE"
NO_NEWLINE=1
fi
fi
done
if [ "$NO_NEWLINE" -ne 0 ]; then
echo "Error: Some text files are missing a newline at the end."
exit 1
else
echo "Success: All modified text files end with a newline."
fi
- name: grab-mergecommits
language: bash
standalone: true
value: |
export JIRA_USERNAME=${secrets.user.JIRA_USERNAME}
export JIRA_TOKEN=${secrets.user.JIRA_TOKEN}
export GITHUB_TOKEN=${secrets.user.GITHUB_TOKEN}
go run $project.path()/scripts/grab-mergecommits/main.go $1
- name: target-version-pr
language: bash
standalone: true
value: |
export JIRA_USERNAME=${secrets.user.JIRA_USERNAME}
export JIRA_TOKEN=${secrets.user.JIRA_TOKEN}
export GITHUB_TOKEN=${secrets.user.GITHUB_TOKEN}
go run $project.path()/scripts/ci/target-version-pr/main.go $1
- name: create-version-pr
language: bash
standalone: true
value: |
export JIRA_USERNAME=${secrets.user.JIRA_USERNAME}
export JIRA_TOKEN=${secrets.user.JIRA_TOKEN}
export GITHUB_TOKEN=${secrets.user.GITHUB_TOKEN}
go run $project.path()/scripts/create-version-pr/main.go $1
- name: propagate-pr
language: bash
standalone: true
value: |
export JIRA_USERNAME=${secrets.user.JIRA_USERNAME}
export JIRA_TOKEN=${secrets.user.JIRA_TOKEN}
export GITHUB_TOKEN=${secrets.user.GITHUB_TOKEN}
go run $project.path()/scripts/ci/propagate-pr/main.go $1
- name: verify-pr
language: bash
standalone: true
value: |
export JIRA_USERNAME=${secrets.user.JIRA_USERNAME}
export JIRA_TOKEN=${secrets.user.JIRA_TOKEN}
export GITHUB_TOKEN=${secrets.user.GITHUB_TOKEN}
go run $project.path()/scripts/ci/verify-pr/main.go $1
- name: start-story
language: bash
standalone: true
value: |
export JIRA_USERNAME=${secrets.user.JIRA_USERNAME}
export JIRA_TOKEN=${secrets.user.JIRA_TOKEN}
export GITHUB_TOKEN=${secrets.user.GITHUB_TOKEN}
go run $project.path()/scripts/start-story/main.go "$@"
- name: ghapi
language: bash
standalone: true
value: |
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token ${secrets.user.GITHUB_TOKEN}" \
https://api.github.com/repos/ActiveState/cli/${1}
- name: benchmark-exec
if: eq .OS.Name "Linux"
language: bash
standalone: true
description: "Benchmarks executable leveraging highly sensitive/accurate tooling"
value: |
# example usage:
# state run benchmark-exec -- state-exec /tmp/state-ipc/my.sock /home/me/.cache/abcd1234/bin/python3 -c "print('123');"
paranoid="$(cat /proc/sys/kernel/perf_event_paranoid)"
updated=false
if [[ "${paranoid}" != "-1" ]]; then
sudo sh -c 'echo -1 >/proc/sys/kernel/perf_event_paranoid'
updated=true
fi
perf stat -d -r 8 -e task-clock,page-faults,cycles,instructions -- ${@} >/dev/null
${updated} && sudo sh -c 'echo '${paranoid}' >/proc/sys/kernel/perf_event_paranoid'
- name: to-buildscript
language: bash
standalone: true
value: go run $project.path()/scripts/to-buildscript/main.go $@
- name: to-buildexpression
language: bash
standalone: true
value: go run $project.path()/scripts/to-buildexpression/main.go $@
events:
- name: activate
if: ne .Shell "cmd"
value: |
$scripts.install-deps-dev.path()
- name: file-changed
scope: [ "internal/locale/locales" ]
value: build
config_version: 1