-
Notifications
You must be signed in to change notification settings - Fork 48
171 lines (142 loc) · 5.23 KB
/
diff-v8.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
163
164
165
166
167
168
169
170
171
# Posts a comment listing all the variables that changed in a PR
name: v8 Diff for design tokens
on:
pull_request:
branches-ignore:
- 'changeset-release/**'
workflow_dispatch:
jobs:
changes:
uses: ./.github/workflows/hasChanged.yml
diff:
needs: changes
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:v8
- 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:v8; popd
- name: Install dependecies for diffing
run: npm install shelljs
- name: Diff v8 tokens
id: diff-files
uses: actions/github-script@v7
with:
script: |
const cssFolder = 'dist/css'
const shell = require('shelljs')
const globber = await glob.create(cssFolder + '/**/**/*.css')
const files = await globber.glob()
// create diffs
const diffs = files.map(file => {
// run diff
const diff = shell.exec(`diff -u ${file.replace(cssFolder, 'base/' + cssFolder)} ${file}`)
// get filename
const regexRunnerPath = new RegExp('^[a-z\/]+\/dist', 'g')
const filename = file.replaceAll(regexRunnerPath,'')
console.log('Checking diff for ' + filename + '...')
if (diff.stderr) {
console.error(diff.stderr)
core.setFailed(diff.stderr)
}
if (diff.stdout === '') {
console.log('No diff for ' + filename + '\n')
} else {
console.log(diff.stdout + '\n')
}
return {
file: filename,
diff: diff.stdout || ''
}
})
// filter files with no diffs
.filter(item => {
return item.diff !== ''
})
// set output to use diff in pr comment
core.setOutput('diffs', diffs);
- name: Write summary
uses: actions/github-script@v7
with:
script: |
const diffs = ${{ steps.diff-files.outputs.diffs }}
core.summary.clear()
core.summary.addHeading('V8 Design Token Diff', '1')
if (diffs.length === 0) {
core.summary.addRaw('No design tokens changed', true)
} else {
diffs.forEach(({file: fileName, diff: content}) => {
const diffDetails = `<details><summary><h3>${fileName}</h3></summary>\n\n`+
'```diff\n'+
`${content}\n`+
'```\n\n'+
'</details>'
core.summary.addRaw(diffDetails, true)
})
}
// write summary
core.summary.write({overwrite: true})
- name: Comment on pr
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const diffs = ${{ steps.diff-files.outputs.diffs }}
// prepare comment body
let body = '## Design Token Diff\n\n'
if (diffs.length === 0) {
body += 'No design tokens changed'
} else {
body += diffs.map(({file, diff}) =>
'<details>' +
`<summary><h3>${file}</h3></summary>\n` +
" \n"+
" ```diff"+
` ${diff}` +
" ```"+
'\n</details>'
).join('\n')
}
// get comments
const {data: comments} = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
// get comment if exists
const existingComment = comments.filter(comment => comment.body.includes('## Design Token Diff'));
// if token issue exists, update it
if(existingComment.length > 0) {
await github.rest.issues.updateComment({
comment_id: existingComment[0].id,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
}
// if comment does not exist, create it
else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body
})
}