Repository navigation
161 lines (152 loc) · 6.12 KB
/
Copy pathbuild-metadata.yml
File metadata and controls
161 lines (152 loc) · 6.12 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
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
name: Build metadata
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
permissions:
contents: read
jobs:
build:
name: Build metadata
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
with:
ref: ${{ github.ref }}
- name: Install dependencies
uses: ./.github/actions/npm-ci
- name: Build
run: |
npx gulp build --polyfills
- name: Upload dependencies.json
if: ${{ github.event_name == 'pull_request' }}
uses: actions/upload-artifact@v7
with:
name: dependencies.json
path: ./build/dist/dependencies.json
- name: Cache polyfills.json
uses: ./.github/actions/polyfills
with:
sha: ${{ github.sha }}
input: ./build/dist/polyfills.json
- name: Generate PR info
if: ${{ github.event_name == 'pull_request' }}
run: |
echo '{ "prNo": ${{ github.event.pull_request.number }} }' >> ${{ runner.temp}}/prInfo.json
- name: Upload PR info
if: ${{ github.event_name == 'pull_request' }}
uses: actions/upload-artifact@v7
with:
name: prInfo
path: ${{ runner.temp}}/prInfo.json
metadata:
# The release fails if a module declares a GVL ID that is deleted from (or missing in) the GVL, which
# can happen without any change here, when a vendor is removed from the GVL. Run the same metadata
# compilation on every master push so that it fails master, and is fixed, before release day.
# (On pull requests, adapter-naming.yml runs it too, but only to report naming problems.)
if: ${{ github.event_name == 'push' }}
name: Validate metadata (GVL IDs)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Install dependencies
uses: ./.github/actions/npm-ci
- name: Compile metadata
# --no-fetch skips storage disclosure downloads; the GVL is still fetched to validate GVL IDs
run: |
npx gulp update-metadata --no-fetch
polyfills:
needs: [build]
if: ${{ github.event_name == 'pull_request' }}
name: Check polyfill diff
runs-on: ubuntu-latest
outputs:
base: ${{ steps.base.outputs.base }}
steps:
- name: Checkout
uses: actions/checkout@v7
with:
fetch-depth: 2
- name: Calculate base SHA and diff
id: base
run: |
base=$(git rev-parse HEAD^1)
git diff --name-only $base..HEAD > ${{runner.temp}}/changed_files.txt
echo "base=$base" >> $GITHUB_OUTPUT
- name: Restore from cache
id: restore
uses: ./.github/actions/polyfills
with:
sha: ${{ steps.base.outputs.base }}
output: ${{ runner.temp }}/base-polyfills.json
- name: Check out base branch
if: ${{ steps.restore.outputs.cache-hit != 'true' }}
run: |
git checkout ${{ steps.base.outputs.base }}
- name: Install dependencies for base branch
if: ${{ steps.restore.outputs.cache-hit != 'true' }}
uses: ./.github/actions/npm-ci
- name: Build base branch
if: ${{ steps.restore.outputs.cache-hit != 'true' }}
run: |
npx gulp build --polyfills
- name: Cache base branch polyfills.json
if: ${{ steps.restore.outputs.cache-hit != 'true' }}
uses: ./.github/actions/polyfills
with:
sha: ${{ steps.base.outputs.base }}
input: './build/dist/polyfills.json'
output: ${{ runner.temp }}/base-polyfills.json
- name: Retrieve head branch polyfills.json
uses: ./.github/actions/polyfills
with:
sha: ${{ github.sha }}
output: ${{ runner.temp }}/head-polyfills.json
fail-on-cache-miss: true
- name: Compare and post comment
uses: actions/github-script@v9
id: comment
with:
result-encoding: string
script: |
const fs = require('fs');
const path = require('path');
const process = require('process');
const base = JSON.parse(fs.readFileSync('${{ runner.temp }}/base-polyfills.json').toString());
const head = JSON.parse(fs.readFileSync('${{ runner.temp }}/head-polyfills.json').toString());
// spec files are not shipped, and they already run on older browsers in the normal PR checks
const files = fs.readFileSync('${{ runner.temp }}/changed_files.txt').toString().split('\n').map(f => f.trim())
.filter(f => !/_spec\.[jtm]sx?$/.test(f));
const diff = files.reduce((memo, file) => {
const fileBase = new Set(base.files[file] ?? []);
const fileHead = new Set(head.files[file] ?? []);
const fileDiff = fileHead.difference(fileBase);
if (fileDiff.size > 0) {
memo[file] = Array.from(fileDiff).toSorted();
}
return memo;
}, {});
if (Object.keys(diff).length > 0) {
const cm = ['This PR introduces changes that may not work on all browsers. According to Babel, the following polyfills may be needed, and they are *not* automatically included:\n'];
Object.entries(diff).forEach(([filename, polys]) => {
cm.push(`* Changes to \`${filename}\` may need:`);
polys.forEach(poly => cm.push(` * \`${poly}\``))
})
cm.push(`\nThe best way to address this is to provide good test coverage, as normal PR checks run unit tests on older browsers.`)
fs.writeFileSync("${{ runner.temp }}/comment.json", JSON.stringify({
issue_number: context.issue.number,
body: cm.join('\n')
}))
return "true";
}
return "false";
- name: Upload comment data
if: ${{ steps.comment.outputs.result == 'true' }}
uses: actions/upload-artifact@v7
with:
name: comment
path: ${{ runner.temp }}/comment.json