Repository navigation
144 lines (130 loc) · 5.99 KB
/
Copy pathspin-client.yml
File metadata and controls
144 lines (130 loc) · 5.99 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
# Spinbox's build of T3 Code's web client. The fork deploys one thing: the client built from the
# `spin` branch (an upstream release tag with the spin/* branches stacked on it), published as a
# release of this fork with the same layout as the client/ directory of upstream's CLI archive.
# The server is upstream's release as it is; Spinbox pins both by hash.
#
# A tag v<upstream version>-spin.<n> on `spin` builds and publishes that release. A push of `spin` -
# the stack rebuilt, on a new tag or with a patch changed - tests and builds it, and publishes nothing.
name: spin-client
on:
push:
branches:
- spin
tags:
- "v*-spin.*"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: spin-client-${{ github.ref }}
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-24.04
timeout-minutes: 20
permissions:
contents: write
steps:
# A clone of the one commit rather than actions/checkout: .repos/ holds gitlinks with no
# .gitmodules entry, and checkout walks submodules even outside a sparse checkout. The fork
# is public, so the clone needs no credential.
- name: Check out
env:
SHA: ${{ github.sha }}
run: |
git init -q .
git remote add origin "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
git fetch -q --depth 1 origin "${SHA}"
git -c advice.detachedHead=false checkout -q FETCH_HEAD
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: package.json
# The image's Node no longer ships corepack; the version is the one packageManager names.
- name: Install pnpm
run: npm install -g "pnpm@$(node -p 'require("./package.json").packageManager.split("@")[1]')"
# The client and the script that brands it, nothing else of the monorepo.
- name: Install
run: pnpm install --frozen-lockfile --filter "@t3tools/web..." --filter "@t3tools/scripts..."
# The patches' own tests: among them, that what they hide is still named upstream - a rename
# upstream merges cleanly and shows the renamed thing again. Upstream's tests are upstream's.
- name: Test the patches
working-directory: apps/web
run: pnpm exec vp test run --project unit src/spin
# The patches' browser tests (src/spin/*.browser.test.tsx) mount the client in headless
# Chromium, the build the pinned Playwright names. Installed as upstream's CI installs it: the
# shell alone, and the system libraries only when the runner lacks one.
- name: Install Chromium
working-directory: apps/web
run: |
node node_modules/playwright/cli.js install --only-shell chromium
browser=$(find "$HOME/.cache/ms-playwright" -name chrome-headless-shell -type f -print -quit)
test -n "$browser"
if ldd "$browser" | grep '=> not found'; then
node node_modules/playwright/cli.js install-deps chromium
fi
# A file can fail to load before any of its assertions run: vitest's Playwright module mocks
# (the tests' vi.mock of the connection driver) lose a race, in 7 of 36 runs measured. Such a
# run says nothing, so it runs again, three runs at most. A failed assertion, or any other
# error, fails the step at once.
- name: Test the patches in Chromium
working-directory: apps/web
env:
NO_COLOR: "1"
run: |
for run in 1 2 3; do
if pnpm exec vp test run --project browser src/spin 2>&1 | tee browser.log; then
exit 0
fi
if grep -qE '^ *Tests .*failed' browser.log ||
! grep -qE 'Failed to import test file|error when mocking a module|did not become ready' browser.log; then
exit 1
fi
echo "::warning::A browser test file did not load, before any assertion (run ${run} of 3)."
done
exit 1
# A tag's client says the tag's version. Left to itself the build reads the version from a
# tag on the commit, which this one-commit clone does not fetch, and falls back to the
# manifest's: upstream's previous release.
- name: Build
env:
REF: ${{ github.ref }}
REF_NAME: ${{ github.ref_name }}
run: |
case "${REF}" in refs/tags/*) export APP_VERSION="${REF_NAME#v}" ;; esac
pnpm --filter @t3tools/web build
node scripts/apply-web-brand-assets.ts production apps/web/dist
rm -rf apps/web/dist/.vite
find apps/web/dist -name '*.map' -delete
# Error reports name the version the client says: a release that says another is pinned by
# one version and reported as a different one.
- name: Check the client says the tag's version
if: startsWith(github.ref, 'refs/tags/')
env:
REF_NAME: ${{ github.ref_name }}
run: |
if ! grep -rqF -- "${REF_NAME#v}" apps/web/dist; then
echo "::error::the client built from ${REF_NAME} does not say it is ${REF_NAME#v}"
exit 1
fi
- name: Package
id: package
env:
REF_NAME: ${{ github.ref_name }}
run: |
version="${REF_NAME#v}"
name="t3-client-${version}"
mkdir -p "out/${name}"
cp -a apps/web/dist "out/${name}/client"
tar -C out -czf "${name}.tar.gz" "${name}"
sha256sum "${name}.tar.gz" | tee "${name}.tar.gz.sha256"
echo "name=${name}" >> "$GITHUB_OUTPUT"
- name: Publish
if: startsWith(github.ref, 'refs/tags/')
env:
GH_TOKEN: ${{ github.token }}
REF_NAME: ${{ github.ref_name }}
NAME: ${{ steps.package.outputs.name }}
run: |
gh release create "${REF_NAME}" "${NAME}.tar.gz" "${NAME}.tar.gz.sha256" \
--repo "${GITHUB_REPOSITORY}" --title "${REF_NAME}" --verify-tag \
--notes "T3 Code's web client built from ${GITHUB_SHA} on the spin branch."