Skip to content

Commit 286c498

Browse files
authored
ci: pull tokens from Tokens Studio on release (#5155)
* ci: pull tokens from Tokens Studio on release * ci: add concurrency guard, cache-miss fallback, and failure alert to tokens pull
1 parent 725d122 commit 286c498

3 files changed

Lines changed: 96 additions & 11 deletions

File tree

.github/workflows/tokens_studio_release.yaml

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,39 @@ name: Tokens Studio release
33
# CI Triggers). Studio sends a repository_dispatch event with this event
44
# type when a release is created. Note: repository_dispatch only triggers
55
# workflows on the default branch.
6+
#
7+
# The payload does not include the release version, so the workflow pulls
8+
# the current state of the sources configured in
9+
# packages/eds-tokens/.studio.json and opens a PR with any changes.
610
on:
711
repository_dispatch:
812
types: [tokens-release]
13+
# Two releases in quick succession would otherwise race on the shared
14+
# tokens-studio-release branch — serialise runs instead
15+
concurrency:
16+
group: tokens-studio-release
17+
cancel-in-progress: false
918
jobs:
10-
handle-release:
11-
name: Handle Tokens Studio release
12-
runs-on: ubuntu-latest
13-
timeout-minutes: 5
19+
setup:
1420
permissions:
1521
contents: read
22+
uses: ./.github/workflows/_setup.yml
23+
secrets: inherit
24+
with:
25+
cacheKey: ${{ github.sha }}-tokens-studio-release
26+
checkout_paths: packages/eds-tokens
27+
pull-tokens:
28+
name: Pull tokens from Tokens Studio
29+
runs-on: ubuntu-latest
30+
needs: setup
31+
timeout-minutes: 15
32+
permissions:
33+
# OIDC token so the studio CLI can authenticate against the
34+
# Tokens Studio CI integration (no service token needed)
35+
id-token: write
36+
# Create the branch and pull request with the pulled changes
37+
contents: write
38+
pull-requests: write
1639
steps:
1740
- name: Log release payload
1841
env:
@@ -21,3 +44,46 @@ jobs:
2144
run: |
2245
echo "Received repository_dispatch event: $EVENT_TYPE"
2346
echo "$CLIENT_PAYLOAD" | jq .
47+
- name: Install Node.js
48+
uses: actions/setup-node@v6
49+
with:
50+
node-version: '24.16.0'
51+
- name: Use "setup" cache
52+
id: setup-cache
53+
uses: actions/cache@v6
54+
with:
55+
path: |
56+
./*
57+
~/.pnpm-store
58+
key: ${{ github.sha }}-tokens-studio-release
59+
- name: Setup pnpm
60+
uses: pnpm/action-setup@v6
61+
with:
62+
run_install: false
63+
# Fallback if the cache from the setup job was evicted — without it
64+
# the workspace is empty and the studio binary is missing
65+
- name: Checkout (cache-miss fallback)
66+
if: steps.setup-cache.outputs.cache-hit != 'true'
67+
uses: actions/checkout@v7
68+
- name: Install dependencies (cache-miss fallback)
69+
if: steps.setup-cache.outputs.cache-hit != 'true'
70+
run: pnpm install --force
71+
- name: Pull tokens from Tokens Studio
72+
run: pnpm --filter @equinor/eds-tokens exec studio tokens pull --ci
73+
- name: Create Pull Request
74+
uses: peter-evans/create-pull-request@v8
75+
with:
76+
commit-message: 'chore: update tokens from Tokens Studio release'
77+
title: 'chore: update tokens from Tokens Studio release'
78+
body: 'Automated pull of the token state after a Tokens Studio release, via the CI integration and `studio tokens pull`. See `packages/eds-tokens/.studio.json` for the configured sources.'
79+
branch: tokens-studio-release
80+
# This workflow runs unattended (release-triggered) and the PR it
81+
# creates gets no CI runs, so a failed pull must not be silent
82+
- name: log-errors-to-slack
83+
uses: act10ns/slack@v2
84+
env:
85+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
86+
with:
87+
status: ${{ job.status }}
88+
steps: ${{ toJson(steps) }}
89+
if: failure()

documentation/agent-instructions/TOKENS_STUDIO.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,26 @@ The CLI is `@tokens-studio/studio-cli` (binary name `studio`), installed as a **
3030

3131
## Configuration (`.studio.json`)
3232

33-
`studio config init` creates `.studio.json`; `studio config add <alias>` adds a token source (interactively, or with `--project <uuid> --branch <name> --format <fmt> --output <dir>`). The file maps aliases to sources:
33+
`studio config init` creates `.studio.json`; `studio config add <alias>` adds a token source (interactively, or with `--project <uuid> --branch <name> --format <fmt> --output <dir>`). The file maps aliases to sources under a `configurations` key:
3434

3535
```json
3636
{
37-
"sources": {
37+
"$schema": "https://tokens.studio/schema/cli",
38+
"configurations": {
3839
"my-tokens": {
39-
"project": "proj_abc123",
40-
"branch": "main",
41-
"output": "src/tokens/my-tokens"
40+
"project": "4952a007-699a-4124-a043-124e80cc28d6",
41+
"ref": {
42+
"type": "branch",
43+
"name": "main"
44+
},
45+
"output": "src/tokens/my-tokens",
46+
"format": "raw"
4247
}
4348
}
4449
}
4550
```
4651

47-
- Sources can reference a `branch`, a `release`, or a `tag` — pin to a release for reproducible builds.
52+
- The `ref` can reference a `branch`, a `release`, or a `tag` — pin to a release for reproducible builds.
4853
- Pull formats are `raw` (default), `dtcg`, and `css`. **There is no TypeScript pull format** — pull raw/DTCG JSON and generate TS locally, as the existing Style Dictionary build does for `build/ts/*`.
4954
- `studio config show` displays the config; `studio config remove <alias>` (alias `rm`) removes a source from `.studio.json`. It does **not** delete already-pulled token files — clean those up manually.
5055
- `.studio.json` is meant to be committed for team consistency.
@@ -100,4 +105,4 @@ studio
100105
└── flags --host --json --no-color --verbose
101106
```
102107

103-
Known state in this repo at snapshot time: CLI installed as a devDependency of `packages/eds-tokens` and approved in `onlyBuiltDependencies`; no `.studio.json` committed yet.
108+
Known state in this repo at snapshot time: CLI installed as a devDependency of `packages/eds-tokens` and approved in `onlyBuiltDependencies`. `.studio.json` lives in `packages/eds-tokens` and is pulled in CI by `.github/workflows/tokens_studio_release.yaml`, triggered by the Tokens Studio CI integration (`repository_dispatch`, event type `tokens-release`) on every platform release. CI auth is OIDC (`id-token: write` + `--ci`) — no service token stored.

packages/eds-tokens/.studio.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://tokens.studio/schema/cli",
3+
"configurations": {
4+
"eds-test-3": {
5+
"project": "4952a007-699a-4124-a043-124e80cc28d6",
6+
"ref": {
7+
"type": "branch",
8+
"name": "main"
9+
},
10+
"output": "src/tokens/eds-test-3",
11+
"format": "raw"
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)