-
-
Notifications
You must be signed in to change notification settings - Fork 166
192 lines (159 loc) · 7.66 KB
/
nodejs.yml
File metadata and controls
192 lines (159 loc) · 7.66 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
name: minimizer-webpack-plugin
on:
push:
branches:
- main
- next
pull_request:
branches:
- main
- next
permissions:
contents: read
jobs:
lint:
name: Lint - ${{ matrix.os }} - Node v${{ matrix.node-version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
os: [ubuntu-latest]
node-version: [lts/*]
runs-on: ${{ matrix.os }}
concurrency:
group: lint-${{ matrix.os }}-v${{ matrix.node-version }}-${{ github.ref }}
cancel-in-progress: true
steps:
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Build types
run: npm run build:types
- name: Check types
run: if [ -n "$(git status types --porcelain)" ]; then echo "Missing types. Update types by running 'npm run build:types'"; exit 1; else echo "All types are valid"; fi
- name: Security audit
run: npm run security
test:
name: Test - ${{ matrix.os }} - Node v${{ matrix.node-version }}, Webpack ${{ matrix.webpack-version }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [10.x, 12.x, 14.x, 16.x, 18.x, 20.x, 22.x, 24.x]
webpack-version: [latest]
runs-on: ${{ matrix.os }}
concurrency:
group: test-${{ matrix.os }}-v${{ matrix.node-version }}-${{ matrix.webpack-version }}-${{ github.ref }}
cancel-in-progress: true
steps:
- name: Setup Git
if: matrix.os == 'windows-latest'
run: git config --global core.autocrlf input
- name: Checkout Repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
id: calculate_architecture
with:
result-encoding: string
script: |
if ('${{ matrix.os }}' === 'macos-latest' && ('${{ matrix['node-version'] }}' === '10.x' || '${{ matrix['node-version'] }}' === '12.x' || '${{ matrix['node-version'] }}' === '14.x')) {
return "x64"
} else {
return ''
}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: ${{ matrix.node-version }}
architecture: ${{ steps.calculate_architecture.outputs.result }}
cache: "npm"
- name: Pin older jest in package.json (Node 10/12)
if: matrix.node-version == '10.x' || matrix.node-version == '12.x'
shell: bash
# Rewrite the jest devDependency before installing so npm resolves a
# consistent @jest/* tree. jest@30 only supports Node >=18.14.
run: |
node -e "const fs=require('fs');const p=require('./package.json');p.devDependencies.jest='^27.5.1';fs.writeFileSync('./package.json',JSON.stringify(p,null,2)+'\n');"
- name: Pin older jest in package.json (Node 14/16)
if: matrix.node-version == '14.x' || matrix.node-version == '16.x'
shell: bash
run: |
node -e "const fs=require('fs');const p=require('./package.json');p.devDependencies.jest='^29.7.0';fs.writeFileSync('./package.json',JSON.stringify(p,null,2)+'\n');"
- name: Install dependencies (old)
run: |
npm install -D typescript@4 --force
npm install --ignore-scripts --force
if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x' || matrix.node-version == '16.x' || matrix.node-version == '18.x'
- name: Install dependencies
run: npm ci
if: matrix.node-version != '10.x' && matrix.node-version != '12.x' && matrix.node-version != '14.x' && matrix.node-version != '16.x' && matrix.node-version != '18.x'
- name: Install older cssnano (Node 10/12)
if: matrix.node-version == '10.x' || matrix.node-version == '12.x'
run: npm install -D --no-save cssnano@^5 --force
- name: Install older cssnano (Node 14/16)
if: matrix.node-version == '14.x' || matrix.node-version == '16.x'
run: npm install -D --no-save cssnano@^6 --force
- name: Install older memfs (Node 10/12)
# memfs@4 uses optional chaining / nullish coalescing and isn't
# transpiled by babel-jest (node_modules is ignored), so it can't be
# parsed on Node 10/12. v3 still supports legacy Node and produces the
# same in-memory output, so it doesn't affect snapshots.
if: matrix.node-version == '10.x' || matrix.node-version == '12.x'
run: npm install -D --no-save memfs@^3.6.0 --force
- name: Pin terser to the locked version (Node 10/12/14)
# npm 6 (bundled with Node <= 14) can't read the lockfileVersion 3
# package-lock.json, so the install step re-resolves `terser` to the
# latest match of its range instead of the locked version (and
# rewrites package-lock.json to v1 in the process). A newer terser
# changes the minified output, which breaks the snapshots. Read the
# locked version from the pristine committed lockfile and reinstall
# that exact version so these rows match the snapshots.
if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x'
shell: bash
run: |
git show HEAD:package-lock.json > pristine-package-lock.json
TERSER_VERSION="$(node -e "process.stdout.write(require('./pristine-package-lock.json').packages['node_modules/terser'].version)")"
rm -f pristine-package-lock.json
npm install -D --no-save --ignore-scripts --force "terser@${TERSER_VERSION}"
- name: Install webpack ${{ matrix.webpack-version }}
if: matrix.webpack-version != 'latest'
run: npm i webpack@${{ matrix.webpack-version }}
- name: Run tests for webpack version ${{ matrix.webpack-version }}
# Skip tests whose minimizers can't run on the current Node version
# (`-t` is a Jest test-name pattern with a negative lookahead).
# `swcMinify`/`swcMinifyHtml`/`swcMinifyCss` need @swc/* binaries that
# aren't available on Node 10/12; `htmlMinifierTerser` requires Node
# 14.13+; `esbuildMinify`/`esbuildMinifyCss` require Node 18+.
#
# `-u` is passed alongside the filter so Jest doesn't fail the CI run
# over the snapshots whose owning tests are skipped by `-t` (Jest
# treats them as obsolete when stdin isn't a TTY). The change is local
# to the runner and never committed, so strict snapshot validation
# still happens on the Node 18+ rows that run the full suite.
shell: bash
run: |
case "${{ matrix.node-version }}" in
10.x|12.x)
npm run test:coverage -- --ci -u -t '^(?!.*(swcMinify|esbuildMinify|htmlMinifierTerser)).*$'
;;
14.x|16.x)
npm run test:coverage -- --ci -u -t '^(?!.*esbuildMinify).*$'
;;
*)
npm run test:coverage -- --ci
;;
esac
- name: Submit coverage data to codecov
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0
with:
token: ${{ secrets.CODECOV_TOKEN }}