-
Notifications
You must be signed in to change notification settings - Fork 74
224 lines (200 loc) · 7.29 KB
/
main.pr.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
name: Build pull request
concurrency:
group: pr-on-${{ github.event_name }}-from-${{ github.ref_name }}
cancel-in-progress: true
on:
pull_request:
branches:
- "master"
jobs:
lint-pull-request:
name: Lint
runs-on: ubuntu-22.04
steps:
- name: Setup node v20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Construct cache keys
run: |
echo node_modules_key='["${{ runner.os }}", "node_modules", "20.x", "${{ hashFiles('package.json', 'yarn.lock') }}"]' >> $GITHUB_ENV;
- name: Cache node_modules
uses: actions/cache@v4
with:
key: ${{ join(fromJSON(env.node_modules_key), '-') }}
path: node_modules
- name: Check if source or test files changed
id: files_changed
uses: tj-actions/changed-files@v44
with:
files: |
src/**/*
spec/**/*
- name: Lint files
if: ${{ steps.files_changed.outputs.any_modified == 'true' }}
run: |
yarn --ignore-engines --non-interactive
yarn lint:ci
build-and-test-pull-request:
needs:
- lint-pull-request
name: Test ${{ matrix.node }} ${{ join(fromJSON('["${{ matrix.target }}", "${{ matrix.module }}"]'), '/') }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
node: [16.x, 18.x, 20.x]
target: [es5, es2015, esnext]
module: [cjs, esm, umd]
include:
- {node: 16.x, target: ix}
- {node: 18.x, target: ix}
- {node: 20.x, target: ix}
- {node: 20.x, target: src, args: --coverage}
steps:
- name: Setup node v${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Construct cache keys
run: |
echo node_modules_key='["${{ runner.os }}", "node_modules", "${{ matrix.node }}", "${{ hashFiles('package.json', 'yarn.lock') }}"]' >> $GITHUB_ENV;
echo targets_key='["${{ runner.os }}", "targets", "${{ matrix.node }}", "${{ matrix.target }}", "${{ matrix.module }}", "${{ hashFiles('package.json', 'yarn.lock', 'tsconfig.json', 'src/**/*', 'tsconfigs/**/*') }}"]' >> $GITHUB_ENV;
- name: Cache targets
uses: actions/cache@v4
with:
key: ${{ join(fromJSON(env.targets_key), '-') }}
path: targets
- name: Cache node_modules
uses: actions/cache@v4
with:
key: ${{ join(fromJSON(env.node_modules_key), '-') }}
path: node_modules
- name: Check if test files changed
id: test_files_changed
uses: tj-actions/changed-files@v44
with:
files: |
spec/**/*
tsconfig.json
tsconfigs/**/*
jest.config.js
jestconfigs/**/*
- name: Check if source files changed
id: source_files_changed
uses: tj-actions/changed-files@v44
with:
files: |
.npmrc
yarn.lock
package.json
tsconfig.json
src/**/*
gulp/**/*
tsconfigs/**/*
integration/**/*
- name: Install dependencies
if: ${{ steps.source_files_changed.outputs.any_modified == 'true' || steps.test_files_changed.outputs.any_modified == 'true' }}
run: |
yarn --ignore-engines --non-interactive
- name: Build package
if: ${{ steps.source_files_changed.outputs.any_modified == 'true' && matrix.target != 'src' }}
env:
t: "${{ matrix.target }}"
m: "${{ matrix.module }}"
run: |
yarn build ${t:+-t ${t}} ${m:+-m ${m}}
- name: Test package
if: ${{ steps.source_files_changed.outputs.any_modified == 'true' || steps.test_files_changed.outputs.any_modified == 'true' }}
env:
t: "${{ matrix.target }}"
m: "${{ matrix.module }}"
run: |
yarn test ${t:+-t ${t}} ${m:+-m ${m}} ${{ matrix.args }}
- name: Test importing
if: ${{ steps.source_files_changed.outputs.any_modified == 'true' && matrix.target != 'src' }}
env:
t: "${{ matrix.target }}"
m: "${{ matrix.module }}"
run: |
targetdir="./targets${t:+/${t}}${m:+/${m}}";
pkg_name="$(jq -r '.name' "${targetdir}/package.json")";
pkg_type="$(jq -r '.type' "${targetdir}/package.json")";
# Install the package into a temp dir
_tmp="$(mktemp -d)";
mkdir -p "$(dirname "${_tmp}/node_modules/${pkg_name}")";
cp -ar "${targetdir}" "${_tmp}/node_modules/${pkg_name}";
cd "${_tmp}/node_modules/${pkg_name}";
npm i;
cd "${_tmp}/";
set -x;
if test "${pkg_type}" = "module"; then
# Test importing as ESModule
node --input-type=module -e "import '${pkg_name}'";
else
# Test importing as CommonJS
node --input-type=commonjs -e "require('${pkg_name}')";
# Test importing CommonJS module but allow it to fail
node --input-type=module -e "import '${pkg_name}'" || true;
fi
set +x;
cd /;
rm -rf "${_tmp}";
test-tree-shaking-pull-request:
needs:
- build-and-test-pull-request
name: Bundle ${{ matrix.bundler }} ${{ join(fromJSON(env.label_json), '/') }}
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
bundler: [esbuild, rollup, webpack]
target: [es5, es2015, esnext]
module: [cjs, esm, umd]
include:
- {bundler: esbuild, target: ix}
- {bundler: rollup, target: ix}
- {bundler: webpack, target: ix}
env:
label_json: '["${{ matrix.target }}", "${{ matrix.module }}"]'
steps:
- name: Setup node v20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Construct cache keys
run: |
echo node_modules_key='["${{ runner.os }}", "node_modules", "20.x", "${{ hashFiles('package.json', 'yarn.lock') }}"]' >> $GITHUB_ENV;
echo targets_key='["${{ runner.os }}", "targets", "20.x", "${{ matrix.target }}", "${{ matrix.module }}", "${{ hashFiles('package.json', 'yarn.lock', 'tsconfig.json', 'src/**/*', 'tsconfigs/**/*') }}"]' >> $GITHUB_ENV;
- name: Cache targets
uses: actions/cache@v4
with:
key: ${{ join(fromJSON(env.targets_key), '-') }}
path: targets
- name: Cache node_modules
uses: actions/cache@v4
with:
key: ${{ join(fromJSON(env.node_modules_key), '-') }}
path: node_modules
- name: Test ${{ matrix.bundler }} tree-shaking
env:
t: "${{ matrix.target }}"
m: "${{ matrix.module }}"
run: |
integration/make-files-to-bundle.sh
if test "${t}" != ix; then
yarn build ${t:+-t ${t}} ${m:+-m ${m}}
fi
yarn gulp bundle${t:+:${t}}${m:+:${m}}:${{ matrix.bundler }}