Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
133 lines (126 loc) · 4.97 KB
/
Copy pathaction.yml
File metadata and controls
133 lines (126 loc) · 4.97 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
name: "designlang — Design Regression Guard"
description: "Extract a live URL, diff its design tokens against a committed baseline, annotate the pull request and fail on drift."
author: "Manavarya09"
branding:
icon: "layers"
color: "orange"
inputs:
url:
description: "URL to extract design from (required)."
required: true
baseline:
description: "Path to the baseline *-design-tokens.json file in your repo."
required: true
comment:
description: "Whether to post a PR comment with the diff (true/false)."
default: "true"
fail-on-change:
description: "Fail the job if any token changed. Set to false to report without gating."
default: "true"
full:
description: "Pass --full to designlang (screenshots, responsive, interactions)."
default: "false"
extra-args:
description: "Additional CLI args passed to `designlang`."
default: ""
github-token:
description: "Token used to comment on the PR. Defaults to github.token."
default: ${{ github.token }}
outputs:
changed:
description: "true/false — whether any tokens changed since the baseline."
value: ${{ steps.diff.outputs.changed }}
changed-count:
description: "Number of changed tokens."
value: ${{ steps.diff.outputs.changed-count }}
diff-path:
description: "Path to the generated diff markdown."
value: ${{ steps.diff.outputs.diff-path }}
version:
description: "The designlang version that ran."
value: ${{ steps.install.outputs.version }}
runs:
using: "composite"
steps:
# Pinned to the designlang release this action was tagged with, so a gate on
# @vX.Y.Z never changes behaviour under you.
- name: Install designlang
id: install
shell: bash
env:
ACTION_PATH: ${{ github.action_path }}
run: |
VERSION="$(node -p "require(process.env.ACTION_PATH + '/../package.json').version")"
if npm view "designlang@$VERSION" version >/dev/null 2>&1; then
npm install -g "designlang@$VERSION"
else
echo "::warning::designlang@$VERSION is not on npm (untagged ref?); using the latest release"
npm install -g designlang
VERSION="$(designlang --version)"
fi
designlang install-browser --with-deps
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Extract tokens
shell: bash
env:
URL: ${{ inputs.url }}
FULL: ${{ inputs.full }}
EXTRA: ${{ inputs.extra-args }}
run: |
mkdir -p .designlang-run
ARGS="--out .designlang-run"
if [ "$FULL" = "true" ]; then ARGS="$ARGS --full"; fi
if [ -n "$EXTRA" ]; then ARGS="$ARGS $EXTRA"; fi
set +e
designlang "$URL" $ARGS
CODE=$?
set -e
if [ "$CODE" -eq 3 ]; then
echo "::error::designlang timed out loading the page (exit 3). This is retryable; the design was not checked."
elif [ "$CODE" -ne 0 ]; then
echo "::error::designlang could not extract the page (exit $CODE). The design was not checked."
fi
exit "$CODE"
- name: Diff tokens against baseline
id: diff
shell: bash
env:
BASELINE: ${{ inputs.baseline }}
ACTION_PATH: ${{ github.action_path }}
run: |
NEW=$(ls .designlang-run/*-design-tokens.json | head -n 1)
node "$ACTION_PATH/diff-tokens.cjs" "$BASELINE" "$NEW" > .designlang-run/diff.md || true
CHANGED=$(grep -c '^- ' .designlang-run/diff.md || true)
echo "changed=$([ "$CHANGED" -gt 0 ] && echo true || echo false)" >> "$GITHUB_OUTPUT"
echo "changed-count=$CHANGED" >> "$GITHUB_OUTPUT"
echo "diff-path=.designlang-run/diff.md" >> "$GITHUB_OUTPUT"
# One annotation per token. Values come from the audited site, so escape
# them the way the Actions toolkit does before emitting a command.
grep '^- ' .designlang-run/diff.md | head -n 50 | while IFS= read -r line; do
msg="${line#- }"
msg="${msg//'%'/%25}"
msg="${msg//$'\r'/%0D}"
echo "::warning title=designlang drift::$msg"
done
- name: Comment on PR
if: ${{ inputs.comment == 'true' && github.event_name == 'pull_request' }}
uses: actions/github-script@v7
with:
github-token: ${{ inputs.github-token }}
script: |
const fs = require('fs');
const body = fs.readFileSync('.designlang-run/diff.md', 'utf8');
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `### designlang — design regression guard\n\n${body}`,
});
- name: Fail on change
if: ${{ inputs.fail-on-change == 'true' && steps.diff.outputs.changed == 'true' }}
shell: bash
env:
COUNT: ${{ steps.diff.outputs.changed-count }}
run: |
echo "::error::$COUNT design token(s) changed vs baseline. Update the baseline if the change is intended."
exit 1