Skip to content

Commit 591393d

Browse files
committed
ci: improve ci scripts
1 parent 348d06d commit 591393d

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

.github/workflows/npm-publish.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,27 @@ jobs:
2727
with:
2828
node-version: ${{ vars.DEFAULT_NODE_VERSION }}
2929
cache: 'npm'
30-
cache-dependency-path: |
31-
'**/package-lock.json'
32-
'**/package-legacy-node.json'
30+
cache-dependency-path: '**/package-lock.json'
31+
32+
- name: Try to restore modern node_modules cache
33+
id: node_modules_cache
34+
uses: actions/cache@v4
35+
with:
36+
path: node_modules
37+
key: ${{ runner.os }}-modern-node-modules-${{ hashFiles('**/package-lock.json') }}
3338

3439
- name: Install dependencies
40+
if: steps.node_modules_cache.outputs.cache-hit != 'true'
3541
run: npm ci
3642

43+
- name: Cache modern node_modules
44+
if: steps.node_modules_cache.outputs.cache-hit != 'true'
45+
uses: actions/cache@v4
46+
with:
47+
path: |
48+
node_modules
49+
key: ${{ runner.os }}-modern-node-modules-${{ hashFiles('**/package-lock.json') }}
50+
3751
- name: Build package
3852
run: npm run build
3953

.github/workflows/reusable-test.yml

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

1818
jobs:
19-
# This job is used to run tests on modern Node.js versions
20-
# 1. Use default Node.js
21-
# 2. Install latest dependencies
22-
# 3. Cache node_modules
23-
build-modern-node:
24-
if: ${{ inputs.use-matrix == true }}
19+
node-modules-cache:
2520
runs-on: ubuntu-latest
2621
steps:
2722
- uses: actions/checkout@v4
@@ -52,6 +47,29 @@ jobs:
5247
node_modules
5348
key: ${{ runner.os }}-modern-node-modules-${{ hashFiles('**/package-lock.json') }}
5449

50+
# This job is used to run tests on modern Node.js versions
51+
# 1. Use default Node.js
52+
# 2. Install latest dependencies
53+
# 3. Cache node_modules
54+
build-modern-node:
55+
if: ${{ inputs.use-matrix == true }}
56+
runs-on: ubuntu-latest
57+
needs: node-modules-cache
58+
steps:
59+
- uses: actions/checkout@v4
60+
61+
- name: Use Node.js ${{ vars.DEFAULT_NODE_VERSION }}
62+
uses: actions/setup-node@v4
63+
with:
64+
node-version: ${{ vars.DEFAULT_NODE_VERSION }}
65+
66+
- name: Restore modern node_modules cache
67+
id: node_modules_cache
68+
uses: actions/cache@v4
69+
with:
70+
path: node_modules
71+
key: ${{ runner.os }}-modern-node-modules-${{ hashFiles('**/package-lock.json') }}
72+
5573
- name: Build package
5674
run: npm run build
5775

@@ -83,7 +101,6 @@ jobs:
83101
with:
84102
path: node_modules
85103
key: ${{ runner.os }}-legacy-node-modules-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/package-legacy-node.json') }}
86-
lookup-only: true
87104

88105
- name: Downgrade package.json legacy dependencies
89106
if: steps.node_modules_cache.outputs.cache-hit != 'true'
@@ -116,8 +133,6 @@ jobs:
116133
uses: actions/setup-node@v4
117134
with:
118135
node-version: ${{ matrix.node-version }}
119-
cache: 'npm'
120-
cache-dependency-path: '**/package-lock.json'
121136

122137
- name: Restore modern node_modules cache
123138
uses: actions/cache@v4
@@ -155,8 +170,6 @@ jobs:
155170
uses: actions/setup-node@v4
156171
with:
157172
node-version: ${{ matrix.node-version }}
158-
cache: 'npm'
159-
cache-dependency-path: '**/package-lock.json'
160173

161174
- name: Restore legacy node_modules cache
162175
uses: actions/cache@v4
@@ -191,8 +204,6 @@ jobs:
191204
uses: actions/setup-node@v4
192205
with:
193206
node-version: ${{ vars.DEFAULT_NODE_VERSION }}
194-
cache: 'npm'
195-
cache-dependency-path: '**/package-lock.json'
196207

197208
- name: Restore modern node_modules cache
198209
uses: actions/cache@v4
@@ -235,18 +246,21 @@ jobs:
235246
run-jest-single:
236247
if: ${{ inputs.use-matrix == false }}
237248
runs-on: ubuntu-latest
249+
needs: node-modules-cache
238250
steps:
239251
- uses: actions/checkout@v4
240252

241253
- name: Use Node.js ${{ inputs.node-version }}
242254
uses: actions/setup-node@v4
243255
with:
244256
node-version: ${{ inputs.node-version || vars.DEFAULT_NODE_VERSION }}
245-
cache: 'npm'
246-
cache-dependency-path: '**/package-lock.json'
247257

248-
- name: Install dependencies
249-
run: npm ci
258+
- name: Restore modern node_modules cache
259+
uses: actions/cache@v4
260+
with:
261+
path: |
262+
node_modules
263+
key: ${{ runner.os }}-modern-node-modules-${{ hashFiles('**/package-lock.json') }}
250264

251265
- name: Run modern jest tests
252266
run: npm test

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "enum-plus",
3-
"version": "3.0.0-alpha.1",
3+
"version": "3.0.0-alpha.2",
44
"description": "A drop-in replacement for native enum. Like native enum but much better!",
55
"keywords": [
66
"enum",

0 commit comments

Comments
 (0)