Skip to content

Commit e32e274

Browse files
authored
ci: only fetch dependencies once (#10961)
1 parent e5a84d9 commit e32e274

File tree

1 file changed

+49
-20
lines changed

1 file changed

+49
-20
lines changed

.github/workflows/nodejs.yml

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,55 @@ jobs:
1717
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1818
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'"
1919

20-
lint-and-typecheck:
21-
name: Running TypeScript compiler & ESLint
20+
prepare-yarn-cache:
21+
name: Prepare yarn cache
2222
runs-on: ubuntu-latest
2323

2424
steps:
2525
- uses: actions/checkout@v2
26+
27+
- uses: actions/[email protected]
28+
with:
29+
node-version: 14.x
30+
2631
- name: Get yarn cache
2732
id: yarn-cache
2833
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
34+
2935
- uses: actions/cache@v2
3036
with:
3137
path: ${{ steps.yarn-cache.outputs.dir }}
32-
key: ubuntu-latest-node-12.x-yarn-${{ hashFiles('**/yarn.lock') }}
38+
key: yarn2-${{ hashFiles('yarn.lock') }}
3339
restore-keys: |
34-
ubuntu-latest-node-12.x-yarn-
40+
yarn2-
41+
42+
- name: Validate cache
43+
env:
44+
# Use PnP and disable postinstall scripts as this just needs to
45+
# populate the cache for the other jobs
46+
YARN_NODE_LINKER: pnp
47+
YARN_ENABLE_SCRIPTS: false
48+
run: yarn --immutable
49+
50+
lint-and-typecheck:
51+
name: Running TypeScript compiler & ESLint
52+
runs-on: ubuntu-latest
53+
needs: prepare-yarn-cache
54+
55+
steps:
56+
- uses: actions/checkout@v2
3557
- uses: actions/[email protected]
3658
with:
3759
node-version: 12.x
60+
- name: Get yarn cache
61+
id: yarn-cache
62+
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
63+
- uses: actions/cache@v2
64+
with:
65+
path: ${{ steps.yarn-cache.outputs.dir }}
66+
key: yarn2-${{ hashFiles('yarn.lock') }}
67+
restore-keys: |
68+
yarn2-
3869
- name: install
3970
run: yarn --immutable
4071
- name: build
@@ -57,6 +88,7 @@ jobs:
5788
node-version: [10.x, 12.x, 14.x, 15.x]
5889
os: [ubuntu-latest, macOS-latest, windows-latest]
5990
runs-on: ${{ matrix.os }}
91+
needs: prepare-yarn-cache
6092

6193
steps:
6294
- name: Set git config
@@ -66,19 +98,19 @@ jobs:
6698
git config --global core.symlinks true
6799
if: runner.os == 'Windows'
68100
- uses: actions/checkout@v2
101+
- name: Use Node.js ${{ matrix.node-version }}
102+
uses: actions/[email protected]
103+
with:
104+
node-version: ${{ matrix.node-version }}
69105
- name: Get yarn cache
70106
id: yarn-cache
71107
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
72108
- uses: actions/cache@v2
73109
with:
74110
path: ${{ steps.yarn-cache.outputs.dir }}
75-
key: ${{ runner.os }}-node-${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }}
111+
key: yarn2-${{ hashFiles('yarn.lock') }}
76112
restore-keys: |
77-
${{ runner.os }}-node-${{ matrix.node-version }}-yarn-
78-
- name: Use Node.js ${{ matrix.node-version }}
79-
uses: actions/[email protected]
80-
with:
81-
node-version: ${{ matrix.node-version }}
113+
yarn2-
82114
- name: install
83115
run: yarn --immutable
84116
- name: build
@@ -88,8 +120,6 @@ jobs:
88120
uses: SimenB/github-actions-cpu-cores@v1
89121
- name: run tests
90122
run: yarn test-ci-partial:parallel --max-workers ${{ steps.cpu-cores.outputs.count }}
91-
env:
92-
CI: true
93123

94124
test-jasmine:
95125
name: Node LTS on ${{ matrix.os }} using jest-jasmine2
@@ -98,6 +128,7 @@ jobs:
98128
matrix:
99129
os: [ubuntu-latest, macOS-latest, windows-latest]
100130
runs-on: ${{ matrix.os }}
131+
needs: prepare-yarn-cache
101132

102133
steps:
103134
- name: Set git config
@@ -107,19 +138,19 @@ jobs:
107138
git config --global core.symlinks true
108139
if: runner.os == 'Windows'
109140
- uses: actions/checkout@v2
141+
- name: Use Node.js 14.x
142+
uses: actions/[email protected]
143+
with:
144+
node-version: 14.x
110145
- name: Get yarn cache
111146
id: yarn-cache
112147
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
113148
- uses: actions/cache@v2
114149
with:
115150
path: ${{ steps.yarn-cache.outputs.dir }}
116-
key: ${{ runner.os }}-node-14.x-yarn-${{ hashFiles('**/yarn.lock') }}
151+
key: yarn2-${{ hashFiles('yarn.lock') }}
117152
restore-keys: |
118-
${{ runner.os }}-node-14.x-yarn-
119-
- name: Use Node.js 14.x
120-
uses: actions/[email protected]
121-
with:
122-
node-version: 14.x
153+
yarn2-
123154
- name: install
124155
run: yarn --immutable
125156
- name: build
@@ -129,5 +160,3 @@ jobs:
129160
uses: SimenB/github-actions-cpu-cores@v1
130161
- name: run tests using jest-jasmine
131162
run: yarn jest-jasmine-ci --max-workers ${{ steps.cpu-cores.outputs.count }}
132-
env:
133-
CI: true

0 commit comments

Comments
 (0)