-
Notifications
You must be signed in to change notification settings - Fork 45
162 lines (142 loc) · 5.13 KB
/
diff-design-tokens.yml
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
# Posts a comment listing all the variables that changed in a PR
name: Diff for design tokens
on:
pull_request:
branches-ignore:
- 'changeset-release/**'
workflow_dispatch:
jobs:
changes:
uses: ./.github/workflows/hasChanged.yml
setup:
runs-on: ubuntu-latest
outputs:
diffs: ${{ steps.config.outputs.diffs }}
steps:
- name: Setup config
id: config
uses: actions/github-script@v7
with:
script: |
core.setOutput('diffs', `[{
"title": "Design Token Diff (CSS)",
"folder": "dist/css",
"globString": "**/**/*.css",
"outputFile": "diff_css.json"
},{
"title": "Design Token Diff (StyleLint)",
"folder": "dist/styleLint",
"globString": "**/**/*.json",
"outputFile": "diff_style_lint.json"
},{
"title": "Design Token Diff (Figma)",
"folder": "dist/figma",
"globString": "**/**/*.json",
"outputFile": "diff_figma.json"
},{
"title": "Design Token Diff (Fallbacks)",
"folder": "dist/fallbacks",
"globString": "**/**/*.json",
"outputFile": "diff_fallbacks.json"
}]`)
diff:
needs: [changes, setup]
if: needs.changes.outputs.outputAffected == 'true' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Checkout base branch
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
path: base
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install dependencies (pr)
run: npm ci --no-audit --no-fund --include=dev --ignore-scripts
- name: Build tokens (pr)
run: npm run build
- name: Install dependencies (base)
run: pushd base; npm i --no-audit --no-fund --ignore-scripts; popd
- name: Build tokens (base)
run: pushd base; npm run build; popd
- name: Install dependecies for diffing
run: npm install shelljs
- name: Diff tokens
id: diff-files
uses: actions/github-script@v7
with:
script: |
const fs = require('fs')
const diffFiles = require('./.github/workflows/utilities/diffFiles.cjs')
// get config
const diffConfig = ${{ needs.setup.outputs.diffs }}
// create diff for each config
for (const config of diffConfig) {
await diffFiles(config, 'base')
}
- name: Write summary
uses: actions/github-script@v7
with:
script: |
const fs = require('fs')
const addSummary = require('./.github/workflows/utilities/addSummary.cjs')
const diffConfig = ${{ needs.setup.outputs.diffs }}
const output = []
// read diff files
for (const config of diffConfig) {
const diff = JSON.parse(fs.readFileSync(config.outputFile, 'utf8'))
// add to output
output.push({
title: config.title,
sections: diff
})
}
// add summary
addSummary(output, true)
- name: Comment on pr
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_RUN_ID: ${{ github.run_id }}
with:
script: |
const fs = require('fs')
const addComment = require('./.github/workflows/utilities/addComment.cjs')
const diffConfig = ${{ needs.setup.outputs.diffs }}
const WORKFLOW_SUMMARY_URL = `https://github.com/${{env.GITHUB_REPOSITORY}}/actions/runs/${{env.GITHUB_RUN_ID}}`
// read diff files
for (const config of diffConfig) {
const diff = JSON.parse(fs.readFileSync(config.outputFile, 'utf8'))
await addComment({
title: config.title,
sections: diff
}, WORKFLOW_SUMMARY_URL, context, github)
}
remove_comment:
needs: [changes, setup]
if: needs.changes.outputs.outputAffected == 'false'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Remove comment and summary
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const deleteComment = require('./.github/workflows/utilities/deleteCommentByContent.cjs')
const diffs = ${{ needs.setup.outputs.diffs }}
const commentTitles = diffs.map(({title}) => title)
// delete all comments
for (const title of commentTitles) {
await deleteComment(`## ${title}`, context, github)
}
// remove summary
core.summary.clear()
core.summary.write({overwrite: true})