Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
286 lines (257 loc) · 15.4 KB
/
Copy pathTaskfile.yml
File metadata and controls
286 lines (257 loc) · 15.4 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
version: "3"
# The site: Astro Starlight under src/, and two Go tools under tools/ - refgen writes the
# reference pages from the sources they describe, linkcheck fails on a link the build did not
# produce. SPIN, TERRAFORM and BRAND are checkouts of spin-stack/spin, spin-stack/spin-terraform-aws
# and spin-stack/brand: by default the ones task sources fetches into .sources/, at the commits
# versions.yaml pins. SHOTS is where it unpacks the dashboard's screenshots, which spin's
# release carries as site-shots.tar.gz. Node and pnpm run in the image the Dockerfile makes: a host
# needs Go and Docker, and every machine builds with the same Node.
vars:
SPIN: '{{.SPIN | default ".sources/spin"}}'
TERRAFORM: '{{.TERRAFORM | default ".sources/spin-terraform-aws"}}'
BRAND: '{{.BRAND | default ".sources/brand"}}'
SHOTS: '{{.SHOTS | default ".sources/spin-site-shots"}}'
BASE_PATH: '{{.BASE_PATH | default "/"}}'
PORT: '{{.PORT | default "4321"}}'
HOST: '{{.HOST | default "127.0.0.1"}}'
IMAGE: spinbox-docs
# The Cloudflare Pages project, and the domain its main is served at.
PROJECT: spinbox-docs
DOMAIN: docs.spinbox.dev
UID:
sh: id -u
GID:
sh: id -g
# versions, bump, lint:workflows, release and consumers are go-tools' (its
# internal/tasks/tasks.yml), the same in every spin-stack repository. Nobody copies from the
# site, so consumers refuses here.
#
# bump moves any one pin but a source's. spin, spin-terraform-aws and brand say in versions.yaml
# (bump:) that sources:bump moves them, which also refuses a release the site cannot take yet
# and fetches it; bump refuses them and names it.
includes:
common:
taskfile: "{{.GO_TOOLS_TASKS}}"
flatten: true
vars:
RELEASE:
map:
none: "pages.yml uploads every push to main to Cloudflare Pages, so the site is deployed and no tag or release names a version of it"
tasks:
# The images are versions.yaml's (versions args). GITHUB_TOKEN, when set, is what sfw downloads
# the firewall with: anonymous downloads are the first GitHub sheds under load. A secret, so it
# is in no layer of the image.
install:
desc: Build the image with the site's dependencies from the lockfile, installed through Socket Firewall (sfw) - the Dockerfile's deps stage. The tasks that need it build it.
cmds:
- docker build --target deps $(versions args golang node) --secret id=github_token,env=GITHUB_TOKEN -t {{.IMAGE}}:deps .
dev:
desc: Serve the site with live reload at http://localhost:4321 (HOST=0.0.0.0 for every interface, PORT=N for another port). The source is mounted; node_modules comes from the image.
deps: [install]
cmds:
# The mount point for the image's node_modules; made here so it is yours, not root's.
- mkdir -p node_modules
- >-
docker run --rm -it --init
--user {{.UID}}:{{.GID}} -e HOME=/tmp
-v "$PWD":/app -v /app/node_modules
-p {{.HOST}}:{{.PORT}}:4321
{{.IMAGE}}:deps
sh -c 'node tools/marks.mjs && pnpm dev --port 4321 --host 0.0.0.0'
sources:
desc: Fetch spin, spin-terraform-aws and brand into .sources/, each at the commit versions.yaml pins, and spin's release's screenshots (site-shots.tar.gz) beside them. spin is private - SOURCES_TOKEN, or git's own credentials, reads it.
cmds:
- go run ./tools/sources spin spin-terraform-aws brand
sources:bump:
desc: Move the pins to the newest releases - spin only to one that holds the commit pinned - and fetch them, and rewrite the prices and the blog's posts. Then task reference.
cmds:
- go run ./tools/sources -bump spin spin-terraform-aws brand
- task: pricing
- task: posts
# The cost page's numbers: generated, dated, and refused by reference:check once they are a
# month old or of other machines than the module starts, so a figure on the page is never
# quietly stale. The sync rewrites them every day.
pricing:
desc: Write src/data/pricing.json - what the machines the module starts by default cost an hour, on demand, in each region with images, from the lists the AWS pricing page loads (tools/pricing).
cmds:
- go run ./tools/pricing -terraform {{.TERRAFORM}} -out src/data/pricing.json
# The posts a page may link, [why](<post:the-slug>): what the blog's feed lists, so a draft's
# slug never reaches this public site. The build reads the file and never the feed, and a feed
# that cannot be read keeps it. The sync rewrites it every day.
posts:
desc: Write src/data/posts.json - the posts the blog has published, from its feed (tools/posts).
cmds:
- go run ./tools/posts -out src/data/posts.json
sync:pr:
desc: Commit what sources:bump and reference changed to branch sync/sources as the sync App (SYNC_TOKEN, BOT its login), and open its one pull request or update it. sync.yml runs it.
cmds:
- go run ./tools/sync pr -bot '{{.BOT}}' -reference '{{.REFERENCE | default "success"}}'
sync:issue:
desc: Write spin's issue "Site vs spin main" as the sources App (SOURCES_TOKEN, BOT its login) - MODE release, the commits a bump takes in, or main, what spin main has past the pin - with the release chain. sync.yml runs it.
cmds:
- go run ./tools/sync issue -mode '{{.MODE}}' -bot '{{.BOT}}'
# Only the entries the Gate builds or runs on the pull request: node and golang the image task
# check makes, actionlint task gate's lint:workflows. spin, spin-terraform-aws and brand are
# sources:bump's, which sync.yml runs every day.
refresh:
desc: Propose what is behind of the entries the Gate checks (node, golang, actionlint) as one pull request; refresh.yml's step, and it pushes and opens a pull request as GITHUB_TOKEN or GH_TOKEN
cmds:
- versions refresh -propose node golang actionlint
# refresh.yml commits and pushes as the sync App, so that its pull request starts the Gate: one
# opened with the run's own token starts no workflow.
git:app:
desc: Make git commit and push as the GitHub App whose token is GH_TOKEN (APP_SLUG= its slug) - a workflow's step, as it writes git's global configuration.
requires:
vars: [APP_SLUG]
preconditions:
- sh: test -n "${GITHUB_ACTIONS:-}"
msg: git:app rewrites git's global user and credentials; it is for a workflow's runner, not this machine
cmds:
- |
set -e
gh auth setup-git
id=$(gh api "/users/{{.APP_SLUG}}[bot]" --jq .id)
git config --global user.name "{{.APP_SLUG}}[bot]"
git config --global user.email "${id}+{{.APP_SLUG}}[bot]@users.noreply.github.com"
reference:
desc: Write the reference pages (CLI, Terraform, config file, API) and what the site copies from the spin, spin-terraform-aws and brand checkouts.
cmds:
- task: sources
- go run ./tools/refgen -spin {{.SPIN}} -terraform {{.TERRAFORM}} -brand {{.BRAND}} -shots {{.SHOTS}}
reference:check:
desc: Fail if a reference page is not what the sources say.
cmds:
- task: sources
- go run ./tools/refgen -spin {{.SPIN}} -terraform {{.TERRAFORM}} -brand {{.BRAND}} -shots {{.SHOTS}} -check
- go run ./tools/pricing -terraform {{.TERRAFORM}} -check
# A hand-written page names what it reads and the release it was read against (tools/refgen's
# reads.go), and reference:check fails once that has changed. This is the answer: after reading
# the page against the diff the check named, and correcting it.
reviewed:
desc: Stamp a hand-written page's reads with the sources as they are - PAGE=src/content/docs/<page> - once it has been read against what changed.
requires:
vars: [PAGE]
cmds:
- go run ./tools/refgen -spin {{.SPIN}} -terraform {{.TERRAFORM}} -reviewed {{.PAGE}}
reference:public:
desc: Fail if what the site has of spin-terraform-aws and brand is not what they say at the commits versions.yaml pins. Needs no spin checkout, nor any credential.
# A fork's pull request has no token to read spin with, and this half needs nothing of it:
# what the site says of spin stays as reference.json has it, and is held by reference:check.
cmds:
- go run ./tools/sources spin-terraform-aws brand
- go run ./tools/refgen -only terraform,brand -terraform .sources/spin-terraform-aws -brand .sources/brand -check
- go run ./tools/pricing -terraform .sources/spin-terraform-aws -check
build:
desc: Build the site into dist/, with llms.txt, llms-full.txt and a .md twin of every page - the Dockerfile's build stage, after the build's own tests. SITE_URL and BASE_PATH are where it is served, GTM_ID the Google Tag Manager container production's build is given.
cmds:
- rm -rf dist
- >-
docker build --target dist $(versions args golang node) --secret id=github_token,env=GITHUB_TOKEN
--build-arg SITE_URL={{.SITE_URL}} --build-arg BASE_PATH={{.BASE_PATH}} --build-arg GTM_ID={{.GTM_ID}}
--output type=local,dest=dist .
lint:
desc: Biome over the code (lint, formatting, sorted imports; biome.json) and astro check over the types, as a stage of the image. Biome's own fixes are `pnpm exec biome check --write` in it.
cmds:
- docker build --target lint $(versions args golang node) --secret id=github_token,env=GITHUB_TOKEN --output type=cacheonly .
links:
desc: Fail on a link to a page or an anchor the build did not produce.
cmds:
- go run ./tools/linkcheck -base {{.BASE_PATH}} dist
links:external:
desc: Open every link out of the site and every ghcr.io reference, as a reader with no credential would. Run it on the day the repositories go public.
cmds:
- go run ./tools/linkcheck -external dist
gate:
desc: What CI runs - every install through the firewall and every workflow step a task, the workflows linted, the install, vet and the tools' tests, Biome and astro check, the reference against the public sources, the build, every link, and no Pages Function.
cmds:
- sfw check
# The Task running this one, which taskgate asks for the task names a workflow step runs.
- taskgate -common -task {{.TASK_EXE}}
# AGENTS.md is loaded into every session of an agent's: a path or a task it names that the
# tree does not have is an instruction to do what cannot be done.
- refs -task {{.TASK_EXE}}
- task: lint:workflows
- task: install
- go vet ./...
- go test ./...
- task: lint
- task: reference:public
- task: build
- task: links
- task: static
# Cloudflare Pages serves static files free and without limit; a Function is billed as a Workers
# request. The site has none, and this keeps it that way: a `functions/` directory or a
# `_worker.js` in what is uploaded would turn every page view into one.
static:
desc: Fail when the upload would carry a Pages Function - functions/ in the tree, or _worker.js in dist/ - since a Function's requests are billed and a static file's are not.
cmds:
- 'if [ -e functions ] || [ -e dist/_worker.js ]; then echo "a Pages Function (functions/ or dist/_worker.js): the site is static, and a Function is billed per request"; exit 1; fi'
# Cloudflare Pages: main is production at https://docs.spinbox.dev, and any other branch a preview at
# its own address, <branch>.spinbox-docs.pages.dev, public as the repository is. wrangler is a
# dependency of the lockfile's, installed through the firewall as the rest are.
deploy:
desc: Build the site and upload it to Cloudflare Pages as BRANCH (else the checkout's) - main is production at https://docs.spinbox.dev, any other a preview at its own pages.dev address. Needs CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID.
cmds:
- task: build
- task: upload
upload:
desc: Upload dist/ as it is to Cloudflare Pages as BRANCH (else the checkout's), and say its address - in the job's summary in CI, and as a comment on pull request PR when given. CI runs it after task check built dist/. Needs CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID.
vars:
BRANCH:
sh: echo "${BRANCH:-$(git rev-parse --abbrev-ref HEAD)}"
# A preview's address is the branch's alias: lowercase, anything else a hyphen, 28 characters.
URL:
sh: |
if [ "{{.BRANCH}}" = main ]; then echo "https://{{.DOMAIN}}/"; else
alias=$(printf %s "{{.BRANCH}}" | tr 'A-Z' 'a-z' | sed 's/[^a-z0-9]/-/g' | cut -c1-28 | sed 's/-*$//')
echo "https://$alias.{{.PROJECT}}.pages.dev/"
fi
preconditions:
- sh: test -n "$CLOUDFLARE_API_TOKEN" && test -n "$CLOUDFLARE_ACCOUNT_ID"
msg: CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID are needed to upload
- sh: test -f dist/index.html
msg: nothing in dist/ to upload - task build first
cmds:
- task: static
- task: install
- >-
docker run --rm -e CLOUDFLARE_API_TOKEN -e CLOUDFLARE_ACCOUNT_ID
-v "$PWD/dist":/dist:ro {{.IMAGE}}:deps
pnpm exec wrangler pages deploy /dist --project-name {{.PROJECT}} --branch {{.BRANCH}}
--commit-hash "$(git rev-parse HEAD)" --commit-dirty=true
- '[ -z "$GITHUB_STEP_SUMMARY" ] || echo "{{.BRANCH}} is at {{.URL}}" >> "$GITHUB_STEP_SUMMARY"'
# One comment, edited at each push: the address stays, and the commit it shows moves.
- '[ -z "$PR" ] || gh pr comment "$PR" --edit-last --create-if-none --body "Preview of $(git rev-parse --short HEAD): {{.URL}}"'
cf:setup:
desc: Once - create the Cloudflare Pages project (production branch main) and attach docs.spinbox.dev to it. The DNS record (a CNAME to spinbox-docs.pages.dev) is Route 53's, in spinbox.dev-deploy, as the blog's is. Needs CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID.
preconditions:
- sh: test -n "$CLOUDFLARE_API_TOKEN" && test -n "$CLOUDFLARE_ACCOUNT_ID"
msg: CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID are needed
cmds:
- task: install
- >-
curl -fsS -o /dev/null -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects/{{.PROJECT}}"
|| docker run --rm -e CLOUDFLARE_API_TOKEN -e CLOUDFLARE_ACCOUNT_ID {{.IMAGE}}:deps
pnpm exec wrangler pages project create {{.PROJECT}} --production-branch main
- >-
curl -fsS -X POST
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" -H "Content-Type: application/json"
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/pages/projects/{{.PROJECT}}/domains"
-d '{"name":"{{.DOMAIN}}"}' || echo "{{.DOMAIN}} may already be attached; see the project's Custom domains"
exposure:
desc: What this repository shows the world - every ref's commits, pull request heads included, and its issues, pull requests and comments - against .github/exposure-allow.txt.
# The repository is public: a value that lands in a pull request is published the moment the
# pull request is opened. The private repositories are named, so this finds what the daily
# workflow does, whose token sees none of the organization's.
cmds:
- exposure -allow .github/exposure-allow.txt -gitleaks-config .gitleaks.toml -private ami,ci,shipset,skills,spin,spinbox.dev-deploy spin-stack/website
check:
desc: What CI runs with the token that reads spin - the reference against the sources at their pins, and the gate.
cmds:
- task: reference:check
- task: gate
check:public:
desc: What CI runs with no token to read spin, a fork's pull request - the gate, whose reference:public needs none.
cmds:
- task: gate