Skip to content

Commit 615ce38

Browse files
committed
ci: run node.js esm tests on commit
1 parent f86083d commit 615ce38

File tree

1 file changed

+36
-55
lines changed

1 file changed

+36
-55
lines changed

.github/workflows/reusable-test.yml

Lines changed: 36 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ on:
1616
default: false
1717

1818
jobs:
19-
node-modules-cache:
19+
# This job is used to cache node_modules and build output
20+
# 1. Install latest dependencies
21+
# 2. Cache node_modules
22+
# 3. Build package
23+
# 4. Cache build output
24+
install-and-build:
2025
if: ${{ inputs.use-matrix == true }}
2126
runs-on: ubuntu-latest
2227
steps:
@@ -63,55 +68,6 @@ jobs:
6368
name: modern-node-modules-${{ hashFiles('**/package-lock.json') }}
6469
path: node_modules
6570

66-
node-modules-legacy-cache:
67-
if: ${{ inputs.use-matrix == true }}
68-
runs-on: ubuntu-latest
69-
steps:
70-
- uses: actions/checkout@v4
71-
72-
- name: Use Node.js ${{ vars.DEFAULT_NODE_VERSION }}
73-
uses: actions/setup-node@v4
74-
with:
75-
node-version: ${{ vars.DEFAULT_NODE_VERSION }}
76-
77-
- name: Try to restore legacy node_modules cache
78-
id: node_modules_cache
79-
uses: actions/cache@v4
80-
with:
81-
path: node_modules
82-
key: ${{ runner.os }}-legacy-node-modules-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/package-legacy-node.json') }}
83-
84-
- name: Downgrade package.json legacy dependencies
85-
if: steps.node_modules_cache.outputs.cache-hit != 'true'
86-
run: npm run prepare-legacy-node
87-
88-
- name: Install dependencies
89-
if: steps.node_modules_cache.outputs.cache-hit != 'true'
90-
run: npm install --legacy-peer-deps --ignore-scripts --no-package-lock
91-
92-
# This job is used to run tests on modern Node.js versions
93-
# 1. Use default Node.js
94-
# 2. Install latest dependencies
95-
# 3. Cache node_modules
96-
build-for-node-modern:
97-
if: ${{ inputs.use-matrix == true }}
98-
runs-on: ubuntu-latest
99-
needs: node-modules-cache
100-
steps:
101-
- uses: actions/checkout@v4
102-
103-
- name: Use Node.js ${{ vars.DEFAULT_NODE_VERSION }}
104-
uses: actions/setup-node@v4
105-
with:
106-
node-version: ${{ vars.DEFAULT_NODE_VERSION }}
107-
108-
- name: Restore modern node_modules cache
109-
id: node_modules_cache
110-
uses: actions/cache@v4
111-
with:
112-
path: node_modules
113-
key: ${{ runner.os }}-modern-node-modules-${{ hashFiles('**/package-lock.json') }}
114-
11571
- name: Build package
11672
run: npm run build
11773

@@ -138,12 +94,37 @@ jobs:
13894
es
13995
es-legacy
14096
umd
97+
node-modules-legacy-cache:
98+
if: ${{ inputs.use-matrix == true }}
99+
runs-on: ubuntu-latest
100+
steps:
101+
- uses: actions/checkout@v4
102+
103+
- name: Use Node.js ${{ vars.DEFAULT_NODE_VERSION }}
104+
uses: actions/setup-node@v4
105+
with:
106+
node-version: ${{ vars.DEFAULT_NODE_VERSION }}
107+
108+
- name: Try to restore legacy node_modules cache
109+
id: node_modules_cache
110+
uses: actions/cache@v4
111+
with:
112+
path: node_modules
113+
key: ${{ runner.os }}-legacy-node-modules-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/package-legacy-node.json') }}
114+
115+
- name: Downgrade package.json legacy dependencies
116+
if: steps.node_modules_cache.outputs.cache-hit != 'true'
117+
run: npm run prepare-legacy-node
118+
119+
- name: Install dependencies
120+
if: steps.node_modules_cache.outputs.cache-hit != 'true'
121+
run: npm install --legacy-peer-deps --ignore-scripts --no-package-lock
141122

142123
# Run ts-tests on default Node.js version
143124
run-jest-ts:
144125
if: ${{ inputs.use-matrix == true }}
145126
runs-on: ubuntu-latest
146-
needs: build-for-node-modern
127+
needs: install-and-build
147128
steps:
148129
- uses: actions/checkout@v4
149130

@@ -166,7 +147,7 @@ jobs:
166147
run-jest-cjs:
167148
if: ${{ inputs.use-matrix == true }}
168149
runs-on: ubuntu-latest
169-
needs: build-for-node-modern
150+
needs: install-and-build
170151
strategy:
171152
matrix:
172153
node-version: [16.x, 17.x, 18.x, 19.x, 20.x, 21.x, 22.x, 23.x, 24.x]
@@ -204,7 +185,7 @@ jobs:
204185
run-jest-cjs-legacy:
205186
if: ${{ inputs.use-matrix == true }}
206187
runs-on: ubuntu-latest
207-
needs: [build-for-node-modern, node-modules-legacy-cache]
188+
needs: [install-and-build, node-modules-legacy-cache]
208189
strategy:
209190
matrix:
210191
node-version: [7.x, 8.x, 9.x, 10.x, 11.x, 12.x, 13.x, 14.x, 15.x]
@@ -242,7 +223,7 @@ jobs:
242223
run-jest-esm:
243224
if: ${{ inputs.use-matrix == true }}
244225
runs-on: ubuntu-latest
245-
needs: build-for-node-modern
226+
needs: install-and-build
246227
strategy:
247228
matrix:
248229
node-version: [16.x, 17.x, 18.x, 19.x, 20.x, 21.x, 22.x, 23.x, 24.x]
@@ -280,7 +261,7 @@ jobs:
280261
run-e2e:
281262
if: ${{ inputs.use-matrix == true }}
282263
runs-on: ubuntu-latest
283-
needs: [build-for-node-modern, node-modules-cache]
264+
needs: [install-and-build]
284265
steps:
285266
- uses: actions/checkout@v4
286267

0 commit comments

Comments
 (0)