Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
570 lines (521 loc) · 21 KB
/
Copy pathTaskfile.yml
File metadata and controls
570 lines (521 loc) · 21 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
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
# Copyright (c) 2026 Circle Internet Services, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# SPDX-License-Identifier: MIT
version: '3'
vars:
RESULTS_DIR: test-reports
TEST_REPORT: test-reports/tests.xml
LINT_REPORT: test-reports/lint.xml
# Hugo project lives in docs/website/; built output lands in docs/website/public.
SITE_DIR: docs/website
SITE_OUT: docs/website/public
GH_NAME: 'circleci'
GH_EMAIL: 'ops+deploy-bot@circleci.com'
# Release version: the newest "## [x.y.z]" heading in CHANGELOG.md (see
# RELEASE.md). Keep the pattern in step with sectionHeading in cmd/ci/release.
#
# No pre-release suffix: these are full releases, marked latest on GitHub and
# published to the stable channel of every package manager.
RELEASE_VERSION:
sh: sed -n -E 's/^## \[([0-9]+\.[0-9]+\.[0-9]+)\].*/v\1/p' CHANGELOG.md | head -n 1
tasks:
build:
desc: Build the circleci binary
vars:
DEST: '{{default "dist/circleci" .DEST}}'
# git describe --long against the last CLI release tag, e.g.
# 1.12.0-5-gd4823563, which the update check reads as ahead of 1.12.0 and
# so never nags about it. --long keeps the -N-g<sha> part even on a tag, so
# a source build never passes for the release binary. --match skips the
# clikit/vX.Y.Z tag on the same commit and --exclude skips -pre tags.
# -dirty comes from git status, not describe --dirty, so untracked files
# count. Without a reachable tag (a shallow or --no-tags clone) the
# version is "dev", which skips the update check; the build warns.
VERSION:
sh: |
v=$(git describe --tags --long --match 'v[0-9]*' --exclude 'v*-*' 2>/dev/null) || { echo dev; exit 0; }
test -z "$(git status --porcelain 2>/dev/null)" || v="$v-dirty"
echo "${v#v}"
cmds:
- cmd: >-
echo 'warning: no CLI release tag reachable, stamping version "dev" (update checks off). Run `git fetch --tags` to fix.' >&2
if: '[ "{{.VERSION}}" = dev ]'
- go build -ldflags="-X main.version={{.VERSION}}" -o "{{.DEST}}" ./cmd/circleci
release-check:
desc: Check if the release is ready to be published
cmds:
- go tool -modfile tools/go.mod goreleaser check
test:
desc: Run unit tests
# clikit is a separate module, so ./... does not reach it. A relative
# ./clikit/... is rejected as outside the main module, but the module path
# resolves through the replace in go.mod.
vars:
ARGS: '{{default "./... github.com/CircleCI-Public/circleci-cli/clikit/..." .CLI_ARGS}}'
cmds:
- go tool -modfile tools/go.mod gotestsum -- -race -count=1 {{.ARGS}}
check:
desc: Run all static checks
cmds:
- task: fmt
vars:
CLI_ARGS: ./... --diff
- task: fmt:clikit
vars:
CLI_ARGS: ./... --diff
- task: lint
- task: lint:clikit
- task: license
vars:
CLI_ARGS: -check .
- task: mod-tidy
vars:
CLI_ARGS: -diff
- task: release-check
fix:
desc: Auto-fix static checks
cmds:
- task: fmt
- task: fmt:clikit
- task: license
- task: mod-tidy
- task: lint
vars:
CLI_ARGS: ./... --fix
- task: lint:clikit
vars:
CLI_ARGS: ./... --fix
lint:
desc: Run golangci-lint
vars:
ARGS: '{{default "./..." .CLI_ARGS}}'
cmds:
- go tool -modfile tools/go.mod golangci-lint run {{.ARGS}}
lint:clikit:
desc: Run golangci-lint on the clikit module
dir: clikit
vars:
ARGS: '{{default "./..." .CLI_ARGS}}'
cmds:
- go tool -modfile ../tools/go.mod golangci-lint run {{.ARGS}}
fmt:
desc: Format the code
vars:
ARGS: '{{default "./..." .CLI_ARGS}}'
cmds:
- go tool -modfile tools/go.mod golangci-lint fmt {{.ARGS}}
fmt:clikit:
desc: Format the clikit module
dir: clikit
vars:
ARGS: '{{default "./..." .CLI_ARGS}}'
cmds:
- go tool -modfile ../tools/go.mod golangci-lint fmt {{.ARGS}}
license:
desc: Manage license headers
vars:
ARGS: '{{default "." .CLI_ARGS}}'
cmds:
- |
go tool -modfile tools/go.mod addlicense \
-c "Circle Internet Services, Inc." \
-l mit \
-s \
-ignore ".idea/**" \
-ignore ".circleci/**" \
-ignore ".claude/**" \
-ignore ".git/**" \
-ignore ".github/**" \
-ignore "test-reports/**" \
-ignore "**/*.html" \
-ignore "acceptance/testdata/**" \
-ignore "bin/**" \
-ignore "dist/**" \
-ignore "docs/website/content/**" \
-ignore "docs/website/public/**" \
{{.ARGS}}
mod-tidy:
desc: Run 'go mod tidy'
vars:
ARGS: '{{default "-v" .CLI_ARGS}}'
cmds:
- go mod tidy {{.ARGS}}
- go -C clikit mod tidy {{.ARGS}}
- go -C tools mod tidy {{.ARGS}}
mod-download:
desc: Run 'go mod download'
cmds:
- go mod download
- go -C clikit mod download
- go mod download -modfile tools/go.mod
dev-install:
desc: Build from source and install to ~/.local/bin
vars:
DEST: '${HOME}/.local/bin'
cmds:
- mkdir -p "{{.DEST}}"
- task: build
vars:
DEST: '{{.DEST}}/circleci'
generate:
desc: Run go generate
cmds:
- go generate ./...
# Demo tasks
#
# Static PNG/SVG screenshots of the CLI in action are captured with
# charmbracelet/freeze. Animated GIFs are recorded with charmbracelet/vhs
# (pinned in tools/go.mod alongside freeze), which additionally needs ttyd,
# ffmpeg, and the demo font at record time — run `task demo:install` once
# to install them.
#
# The vhs tapes in docs/demos/*.tape run the freshly built dist/circleci
# against real data, so record while logged in — each tape's header comment
# explains any per-tape prep (e.g. logging out first for auth-login, or
# substituting a real run id).
demo:
desc: Generate all README/docs screenshots
cmds:
- task: demo:run-get-png
demo:run-get-png:
desc: Capture a macOS-style PNG and SVG of `circleci run get -b main`
cmds:
- for: ['svg']
cmd: >-
CIRCLE_NO_PAGER=1 CIRCLE_SPINNER_DISABLED=1
go tool -modfile tools/go.mod freeze
--config docs/demos/freeze.json
--execute "go run ./cmd/circleci run get -b main"
--execute.timeout 60s
--output docs/demos/run-get.{{.ITEM}}
demo:install:
desc: Install the recording dependencies for the VHS demos (ttyd, ffmpeg, JetBrains Mono)
cmds:
- brew install ttyd ffmpeg
# vhs records in a headless browser, so the demo font must be installed
# system-wide (the copy bundled inside JetBrains IDEs is not visible to it).
- brew install --cask font-jetbrains-mono
demo:gifs:
desc: Record all animated GIF demos with VHS (requires ttyd + ffmpeg)
deps: [build]
cmds:
- for: ['auth-login', 'run-list-get', 'run-get-tui', 'setting-theme', 'run-get-jq']
cmd: PATH="$PWD/dist:$PATH" go tool -modfile tools/go.mod vhs docs/demos/{{.ITEM}}.tape
demo:gif:
desc: 'Record a single demo tape by name, e.g.: task demo:gif -- run-get-tui'
deps: [build]
cmds:
- PATH="$PWD/dist:$PATH" go tool -modfile tools/go.mod vhs docs/demos/{{.CLI_ARGS}}.tape
extensions:install:
desc: Install known official extensions
cmds:
- go run ./cmd/circleci extension install testsuite
- go run ./cmd/circleci extension install configoptimizer
docs:reference:
desc: Generate the reference page from the live command tree
deps:
- extensions:install
cmds:
- mkdir -p {{.SITE_DIR}}/content/reference {{.SITE_DIR}}/static/img
# The landing page (/) is a hand-written template; the screenshot it shows
# is the freeze-captured demo, copied into the site's static tree.
- cp docs/demos/run-get.svg {{.SITE_DIR}}/static/img/run-get.svg
# Generate the help-topic bodies once, then derive three artifacts:
#
# static/llms.txt — the short index llmstxt.org actually
# describes: getting started (install,
# authenticate, MCP), installing the
# agent skills, plus links out. This
# file used to be the full dump, which cost
# an agent ~50k tokens to answer "how do I
# install this?" — and then sent it to the
# README anyway. Keep it small.
# static/llms-full.txt — every topic plus the whole command tree,
# for agents that need command detail.
# content/reference/_index.md — the same full body with Hugo front
# matter, served at /reference.
#
# Hugo copies static/ to the site root verbatim. Both .txt files open with
# an H1 + blockquote summary per the llms.txt spec.
- |
INTRO="$(mktemp)"
REST="$(mktemp)"
{
go run ./cmd/circleci help getting-started
echo
go run ./cmd/circleci help agents
} > "$INTRO"
{
go run ./cmd/circleci help environment
echo
go run ./cmd/circleci help formatting
echo
go run ./cmd/circleci help reference
} > "$REST"
{
echo '# CircleCI CLI'
echo
echo '> Command-line interface to CircleCI for use in your terminal or scripts. This is the short index: install, authenticate, install the agent skills, and links to the full reference.'
echo
cat "$INTRO"
echo
echo '## Reference'
echo
echo '- [Full command reference](https://cli.circleci.com/llms-full.txt): every command, flag and JSON field, generated from the live command tree. Large — fetch it when you need command detail.'
echo '- [Command reference on the web](https://cli.circleci.com/reference/): the same content as a browsable page.'
echo '- [Environment variables](https://cli.circleci.com/reference/#environment): authentication, colour, paging and telemetry. Also `circleci help environment`.'
echo '- [Output formatting](https://cli.circleci.com/reference/#formatting): `--json`, `--jq` and templates. Also `circleci help formatting`.'
echo '- [Source, issue tracker and prebuilt binaries](https://github.com/CircleCI-Public/circleci-cli)'
} > {{.SITE_DIR}}/static/llms.txt
{
echo '# CircleCI CLI'
echo
echo '> Command-line interface to CircleCI for use in your terminal or scripts. This is the full command reference, generated from the live command tree. The short index is at https://cli.circleci.com/llms.txt'
echo
cat "$INTRO"
echo
cat "$REST"
} > {{.SITE_DIR}}/static/llms-full.txt
{
echo '---'
echo 'title: CircleCI CLI Reference'
echo '---'
echo
cat "$INTRO"
echo
cat "$REST"
} > {{.SITE_DIR}}/content/reference/_index.md
rm -f "$INTRO" "$REST"
docs:clean:
desc: Remove the built docs site
cmds:
- rm -rf {{.SITE_OUT}}
docs:build:
desc: Generate the reference and build the static site
deps:
- docs:clean
- docs:reference
cmds:
- 'go tool -modfile tools/go.mod hugo --source {{.SITE_DIR}} --minify --gc'
docs:server:
desc: Serve the docs site locally with live reload
deps:
- docs:reference
cmds:
- 'go tool -modfile tools/go.mod hugo server --source {{.SITE_DIR}} {{.CLI_ARGS}}'
docs:test:
desc: Validate the built site's internal links with htmltest
cmds:
- 'go tool -modfile tools/go.mod htmltest -c {{.SITE_DIR}}/.htmltest.yml {{.CLI_ARGS}}'
docs:hugo:
desc: Run the pinned Hugo binary with arbitrary arguments
cmds:
- 'go tool -modfile tools/go.mod hugo --source {{.SITE_DIR}} {{.CLI_ARGS}}'
ci:docs:publish:
desc: Publish the built site to the gh-pages branch (CI only)
vars:
BRANCH: gh-pages
WORKTREE: .gh-pages
MESSAGE: 'Deploy docs from {{env "CIRCLE_SHA1" | default "local"}}'
cmds:
- test -d {{.SITE_OUT}} || { echo "Run 'task docs:build' first."; exit 1; }
# Only set the deploy-bot identity in CI; never clobber a local git config.
- |
if [ -n "${CI:-}" ]; then
git config --global user.email '{{.GH_EMAIL}}'
git config --global user.name '{{.GH_NAME}}'
fi
- rm -rf {{.WORKTREE}}
- git worktree prune
- |
git fetch origin {{.BRANCH}} || true
if git rev-parse --verify --quiet refs/remotes/origin/{{.BRANCH}}; then
git worktree add -B {{.BRANCH}} {{.WORKTREE}} origin/{{.BRANCH}}
else
git worktree add --orphan -b {{.BRANCH}} {{.WORKTREE}}
fi
# Replace the branch's contents wholesale so deletions propagate, then copy
# in the freshly built site (the .git pointer file must survive).
- find {{.WORKTREE}} -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
- cp -R {{.SITE_OUT}}/. {{.WORKTREE}}/
- |
git -C {{.WORKTREE}} add -A
git -C {{.WORKTREE}} commit -m '{{.MESSAGE}}' || { echo "No changes to publish."; }
git -C {{.WORKTREE}} push origin {{.BRANCH}}
- git worktree remove --force {{.WORKTREE}}
# CI tasks
ci:lint:
desc: Lint with JUnit output
cmds:
- mkdir -p "{{.RESULTS_DIR}}"
- task: lint
vars:
CLI_ARGS: |
./... \
--output.junit-xml.path "{{.LINT_REPORT}}" --output.junit-xml.extended \
--output.text.path=stdout --output.text.colors=true
ci:test:
desc: Run tests with JUnit output
vars:
NAME: '{{if not (eq OS "windows")}}ci tests{{else}}windows tests{{end}}'
cmds:
- mkdir -p {{.RESULTS_DIR}}
- circleci testsuite run "{{.NAME}}"
ci:check:
desc: Check no uncommitted diffs after generate/fmt/tidy
cmds:
- task: fmt
vars:
CLI_ARGS: ./... --diff
- task: fmt:clikit
vars:
CLI_ARGS: ./... --diff
- task: ci:lint
- task: lint:clikit
- task: license
vars:
CLI_ARGS: -check .
- task: mod-tidy
vars:
CLI_ARGS: -diff
- task: release-check
- task: generate
- git diff --exit-code
ci:release-pr:
desc: Open, update or close the release PR for what's merged since the last release (CI only)
cmds:
- go run ./cmd/ci/release pr
ci:halt-unless-unreleased:
desc: End the CI job, successfully, unless the release is untagged — its release PR was just merged (CI only)
vars:
VERSION: '{{.RELEASE_VERSION}}'
cmds:
# ls-remote exits 2 when the tag doesn't exist. Any other failure fails the job.
- |
if [ -z '{{.VERSION}}' ]; then
echo 'CHANGELOG.md has no "## [x.y.z]" release section.' >&2
exit 1
fi
status=0
git ls-remote --exit-code --tags origin 'refs/tags/{{.VERSION}}' >/dev/null || status=$?
case "$status" in
0) echo '{{.VERSION}} is already released.'; circleci-agent step halt ;;
2) echo 'Releasing {{.VERSION}}.' ;;
*) exit "$status" ;;
esac
ci:release:
desc: Tag, build, and publish the newest release in CHANGELOG.md
vars:
VERSION: '{{.RELEASE_VERSION}}'
cmds:
# Only set the deploy-bot identity in CI; never clobber a local git config.
- |
if [ -n "${CI:-}" ]; then
git config --global user.email '{{.GH_EMAIL}}'
git config --global user.name '{{.GH_NAME}}'
fi
- git tag -a '{{.VERSION}}' -m 'Release {{.VERSION}}'
- git push origin '{{.VERSION}}'
# The GitHub release's notes are the version's CHANGELOG.md section, which
# its release PR added. Written outside dist/, which --clean empties.
- |
notes="$(mktemp)"
go run ./cmd/ci/release notes > "$notes"
go tool -modfile tools/go.mod goreleaser release --clean --release-notes "$notes"
- task: ci:packagecloud
- task: ci:cloudsmith
- task: ci:virustotal
- task: ci:tag-clikit
ci:tag-clikit:
desc: Tag the clikit module so extension authors can 'go get' this release
vars:
TAG: 'clikit/{{.RELEASE_VERSION}}'
cmds:
# Only set the deploy-bot identity in CI; never clobber a local git config.
- |
if [ -n "${CI:-}" ]; then
git config --global user.email '{{.GH_EMAIL}}'
git config --global user.name '{{.GH_NAME}}'
fi
- git tag -a '{{.TAG}}' -m 'Release {{.TAG}}'
- git push origin '{{.TAG}}'
ci:virustotal:
desc: Submit the release artifacts in dist/ to VirusTotal for scanning
# VT_APIKEY must be set in the environment to actually upload; without it the
# step logs a skip and exits 0. Submission is best-effort and never gates the
# release — VirusTotal frequently false-flags Go binaries. Set DRY_RUN to list
# the artifacts without contacting VirusTotal.
vars:
DRY_RUN: '{{default "" .DRY_RUN}}'
cmds:
# Submit what users actually download: the archives and the Linux packages.
# VirusTotal unpacks archives and scans the contained binaries.
- go run ./cmd/ci/virustotal submit {{if .DRY_RUN}}--dry-run {{end}}dist/*.tar.gz dist/*.zip dist/*.deb dist/*.rpm
ci:packagecloud:
desc: Publish the Linux nfpm packages (rpm + deb) from dist/ to packagecloud
# PACKAGECLOUD_TOKEN must be set in the environment (not needed when DRY_RUN is
# set). Override REPO to target a different packagecloud repository
# (<user>/<repo>); set DRY_RUN to validate without uploading.
vars:
REPO: '{{default "circleci/circleci" .REPO}}'
DRY_RUN: '{{default "" .DRY_RUN}}'
cmds:
# goreleaser only pushes to packagecloud under a Pro licence, so cmd/ci/packagecloud
# uploads the nfpm output to the public REST API instead — no Ruby CLI needed.
- go run ./cmd/ci/packagecloud pkg push {{if .DRY_RUN}}--dry-run {{end}}--repo '{{.REPO}}' dist/*.rpm dist/*.deb
ci:cloudsmith:
desc: Publish the Linux nfpm packages (deb + rpm) from dist/ to Cloudsmith
# CLOUDSMITH_API_KEY must be set in the environment (not needed when DRY_RUN is
# set). Override CLOUDSMITH_REPO to target a different Cloudsmith repository
# (<owner>/<repo>); set DRY_RUN to validate without uploading.
vars:
CLOUDSMITH_REPO: '{{default "circleci-deps/public" .CLOUDSMITH_REPO}}'
DRY_RUN: '{{default "" .DRY_RUN}}'
cmds:
# goreleaser can't push to Cloudsmith without a Pro licence, so cmd/ci/cloudsmith
# uploads the nfpm output to the public REST API instead. Every package is
# published to the generic "any-distro/any-version" distribution.
- go run ./cmd/ci/cloudsmith push deb {{if .DRY_RUN}}--dry-run {{end}}--repo '{{.CLOUDSMITH_REPO}}' dist/*.deb
- go run ./cmd/ci/cloudsmith push rpm {{if .DRY_RUN}}--dry-run {{end}}--repo '{{.CLOUDSMITH_REPO}}' dist/*.rpm
ci:build:
desc: Dry-run a release — build a snapshot (incl. nfpms) and dry-run the packagecloud publish
vars:
VERSION: '{{.RELEASE_VERSION}}'
cmds:
# Only set the deploy-bot identity in CI; never clobber a local git config.
- |
if [ -n "${CI:-}" ]; then
git config --global user.email '{{.GH_EMAIL}}'
git config --global user.name '{{.GH_NAME}}'
fi
# Forced: the version is usually released already, and its tag may have
# been fetched. The tag is never pushed.
- git tag -f -a '{{.VERSION}}' -m 'Release {{.VERSION}}'
- go tool -modfile tools/go.mod goreleaser release --snapshot --skip=snapcraft --skip=chocolatey --clean
- task: ci:packagecloud
vars:
DRY_RUN: "true"
- task: ci:cloudsmith
vars:
DRY_RUN: "true"
- task: ci:virustotal
vars:
DRY_RUN: "true"