Skip to content

Commit 8994c57

Browse files
authored
ci: simplify Tokens Studio backup workflow (#5176)
* ci: simplify Tokens Studio backup workflow * ci: harden CLI install in backup workflow after review
1 parent ed60e0d commit 8994c57

2 files changed

Lines changed: 39 additions & 16 deletions

File tree

.github/workflows/tokens_studio_backup.yaml

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ name: Tokens Studio backup
77
# commits changes to the orphan branch `tokens-studio-backup`, giving us
88
# diffs, history and a recovery point independent of the platform.
99
# Recovery instructions: documentation/agent-instructions/TOKENS_STUDIO.md
10+
#
11+
# The CLI is installed standalone with npm outside the pnpm workspace —
12+
# a full workspace install just to obtain one binary is not worth two
13+
# minutes every hour. npm cannot run inside the workspace (workspace:
14+
# protocol deps), hence the --prefix install into the runner home.
1015
on:
1116
schedule:
1217
# Hourly, off the whole hour to avoid the GitHub cron rush
@@ -43,29 +48,45 @@ jobs:
4348
with:
4449
ref: tokens-studio-backup
4550
path: backup
46-
- name: Install Node.js
47-
uses: actions/setup-node@v6
48-
with:
49-
node-version: '24.16.0'
50-
# Same key as _setup.yml so the store cache is shared with the
51-
# other workflows
52-
- name: Cache pnpm-store
51+
# The version spec comes from package.json (single source of
52+
# truth). Because the install is cached on the spec string, the
53+
# CLI is effectively pinned to the patch resolved on the first
54+
# cold run — it only moves when the spec in package.json changes.
55+
# That stability is intentional for an unattended backup.
56+
- name: Resolve studio CLI version
57+
id: cli-version
58+
run: |
59+
version=$(jq -er '.devDependencies["@tokens-studio/studio-cli"]' packages/eds-tokens/package.json) \
60+
|| { echo "::error::@tokens-studio/studio-cli not found in eds-tokens devDependencies"; exit 1; }
61+
echo "version=$version" >> "$GITHUB_OUTPUT"
62+
# Caches the installed CLI (including the platform binary its
63+
# postinstall downloads) — a warm run skips npm entirely
64+
- name: Cache studio CLI
65+
id: cache-cli
5366
uses: actions/cache@v6
5467
with:
55-
path: ~/.pnpm-store
56-
key: ${{ runner.os }}-pnpm-and-store-force-${{ hashFiles('pnpm-lock.yaml') }}
57-
- name: Setup pnpm
58-
uses: pnpm/action-setup@v6
59-
with:
60-
run_install: false
61-
- name: Install dependencies
62-
run: pnpm install --force
68+
path: ~/studio-cli
69+
key: studio-cli-${{ runner.os }}-${{ steps.cli-version.outputs.version }}
70+
# The cache post-step saves even when the job fails, so a partial
71+
# install (e.g. network blip during the binary download) would be
72+
# cached and poison every later run. Verify the binary and remove
73+
# the directory on failure — no directory, nothing to cache
74+
- name: Install studio CLI
75+
if: steps.cache-cli.outputs.cache-hit != 'true'
76+
run: |
77+
if ! npm install --prefix ~/studio-cli "@tokens-studio/studio-cli@${{ steps.cli-version.outputs.version }}" --no-audit --no-fund \
78+
|| ! ~/studio-cli/node_modules/.bin/studio --version; then
79+
rm -rf ~/studio-cli
80+
echo "::error::studio CLI install failed verification"
81+
exit 1
82+
fi
6383
# No alias argument = pull every source configured in
6484
# packages/eds-tokens/.studio.json (token sets + $themes.json +
6585
# $metadata.json). --verbose because the run is unattended — the
6686
# Actions log is the only place to diagnose a bad pull
6787
- name: Pull tokens from Tokens Studio
68-
run: pnpm --filter @equinor/eds-tokens exec studio tokens pull --ci --verbose
88+
working-directory: packages/eds-tokens
89+
run: ~/studio-cli/node_modules/.bin/studio tokens pull --ci --verbose
6990
# Aliases and output dirs are read from .studio.json so a config
7091
# rename (e.g. the planned eds-test-3 → eds) never requires a
7192
# workflow change. Each source lands at backup/<alias>/;

documentation/agent-instructions/TOKENS_STUDIO.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ Classify every command before running it:
9999

100100
The platform has **no undo, rollback or restore** — only a read-only version history of releases — and plugin changes push to Studio in real time. `.github/workflows/tokens_studio_backup.yaml` is the safety net for everything between releases: every hour (cron `23 * * * *`, plus manual `workflow_dispatch`) it runs `studio tokens pull` for all sources in `.studio.json` and commits changes to the orphan branch **`tokens-studio-backup`** (one directory per source alias — never merge this branch). Runs that find no changes make no commit. Auth is the same inbound CI Integration as the release pipeline — no extra setup. Failures alert via the Slack step; an hourly backup that fails silently is no safety net.
101101

102+
Unlike the release workflow, the backup does **not** install the pnpm workspace — it installs the CLI standalone with `npm install --prefix` outside the workspace (version resolved from the package's `devDependencies` range) and caches the install. This is the one sanctioned exception to "never install the CLI with npm": npm only fails on `workspace:` protocol deps _inside_ the workspace, and a full workspace install every hour just to obtain one binary is not worth the time.
103+
102104
**Recovery is manual — the CLI has no push command (only `pull`/`watch`):**
103105

104106
1. On the `tokens-studio-backup` branch, find the last good state: `git log --stat -- <alias>/`, then `git diff` between commits to locate when the bad change landed (hourly granularity).

0 commit comments

Comments
 (0)