Skip to content

Commit 429708d

Browse files
authored
ci: refactor ci workflow to reduce number of jobs (#133)
* ci: refactor ci workflow to reduce number of jobs * fix(ci): pnpm has to be installed before using setup-node with pnpm cache * fix(ci): use correct matrix names and consistent ordering * fix(ci): adapt release workflow to changes in ci workflow so it keeps reusing the pnpm cache * test(ci): simulate lint and audit fails by explicitly exiting with 1 * test(ci): reenable default lint and audit status after simulation
1 parent 5ea82cb commit 429708d

File tree

2 files changed

+56
-192
lines changed

2 files changed

+56
-192
lines changed

.github/workflows/ci.yml

Lines changed: 40 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# build and test on linux, windows, mac with node 12, 14, 16
22
name: CI
33

4-
env:
5-
pnpm_store_path: ${{github.workspace}}/.pnpm-store
6-
74
on:
85
push:
96
branches:
@@ -13,159 +10,79 @@ on:
1310
- main
1411

1512
jobs:
16-
pnpmstore:
13+
# "checks" job runs on linux + node14 only and checks that install, build, lint and audit work
14+
# it also primes the pnpm store cache for linux, important for downstream tests
15+
checks:
1716
timeout-minutes: 5
1817
runs-on: ${{ matrix.os }}
19-
2018
strategy:
21-
fail-fast: false
2219
matrix:
23-
os: [ ubuntu-latest, windows-latest, macos-latest ]
24-
node: [ 14 ]
25-
20+
# pseudo-matrix for convenience, NEVER use more than a single combination
21+
node: [14]
22+
os: [ubuntu-latest]
23+
outputs:
24+
build_successful: ${{ steps.build.outcome == 'success' }}
2625
steps:
26+
- uses: actions/checkout@v2
2727
- uses: actions/setup-node@v2
2828
with:
2929
node-version: ${{ matrix.node }}
30-
31-
- name: checkout
32-
uses: actions/checkout@v2
33-
34-
- name: install pnpm
35-
run: npm i -g pnpm@6
36-
- name: set pnpm store-dir
37-
run: pnpm config set store-dir ${{ env.pnpm_store_path }}
38-
- name: pnpm-store
39-
uses: actions/cache@v2
40-
id: pnpm-store
41-
with:
42-
path: ${{ env.pnpm_store_path }}
43-
key: ${{ matrix.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
44-
45-
- name: pnpm-store-fallback
46-
if: steps.pnpm-store.outputs.cache-hit != 'true'
47-
uses: actions/cache@v2
48-
id: pnpm-store-fallback
49-
with:
50-
path: ${{ env.pnpm_store_path }}
51-
key: ${{ matrix.os }}-pnpm-store-fallback-${{ hashFiles('**/pnpm-lock.yaml') }}
52-
restore-keys: |
53-
${{ matrix.os }}-pnpm-store-fallback-
54-
${{ matrix.os }}-pnpm-store-
55-
56-
- name: install
57-
if: steps.pnpm-store.outputs.cache-hit != 'true'
58-
run: pnpm install --frozen-lockfile --prefer-offline --ignore-scripts
59-
- name: prune store
60-
if: steps.pnpm-store.outputs.cache-hit != 'true'
61-
run: pnpm store prune
62-
- name: check store
63-
if: steps.pnpm-store.outputs.cache-hit != 'true'
64-
run: pnpm store status
65-
66-
lint:
67-
needs: pnpmstore
68-
timeout-minutes: 5
69-
runs-on: ${{ matrix.os }}
70-
strategy:
71-
matrix:
72-
os: [ ubuntu-latest ]
73-
node: [ 14 ]
74-
steps:
30+
- run: npm i -g pnpm@6
7531
- uses: actions/setup-node@v2
7632
with:
7733
node-version: ${{ matrix.node }}
78-
79-
- name: checkout
80-
uses: actions/checkout@v2
81-
82-
- name: pnpm-store
83-
uses: actions/cache@v2
84-
id: pnpm-store
85-
with:
86-
path: ${{ env.pnpm_store_path }}
87-
key: ${{ matrix.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
88-
- name: install pnpm
89-
run: npm i -g pnpm@6
90-
- name: set pnpm store-dir
91-
run: pnpm config set store-dir ${{ env.pnpm_store_path }}
34+
cache: 'pnpm'
35+
cache-dependency-path: '**/pnpm-lock.yaml'
9236
- name: install
93-
run: pnpm install --frozen-lockfile --offline --ignore-scripts
94-
- name: install esbuild
95-
run: node node_modules/esbuild/install.js
37+
run: |
38+
pnpm install --frozen-lockfile --prefer-offline --ignore-scripts
39+
node node_modules/esbuild/install.js
9640
- name: build
97-
run: pnpm run build:ci
41+
id: build
42+
run: pnpm run build
9843
- name: lint
99-
run: pnpm lint
100-
101-
audit:
102-
needs: pnpmstore
103-
timeout-minutes: 5
104-
runs-on: ${{ matrix.os }}
105-
strategy:
106-
matrix:
107-
os: [ ubuntu-latest ]
108-
node: [ 14 ]
109-
steps:
110-
- uses: actions/setup-node@v2
111-
with:
112-
node-version: ${{ matrix.node }}
113-
114-
- name: checkout
115-
uses: actions/checkout@v2
116-
117-
- name: pnpm-store
118-
uses: actions/cache@v2
119-
id: pnpm-store
120-
with:
121-
path: ${{ env.pnpm_store_path }}
122-
key: ${{ matrix.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
123-
- name: install pnpm
124-
run: npm i -g pnpm@6
125-
- name: set pnpm store-dir
126-
run: pnpm config set store-dir ${{ env.pnpm_store_path }}
127-
- name: install
128-
run: pnpm install --frozen-lockfile --offline --ignore-scripts
44+
if: (${{ success() }} || ${{ failure() }})
45+
run: pnpm run lint
12946
- name: audit
47+
if: (${{ success() }} || ${{ failure() }})
13048
run: pnpm audit
13149

50+
# this is the test matrix, it runs with node14 on linux,windows,macos + node12,16 on linux
51+
# it is skipped if the build step of the checks job wasn't successful (still runs if lint or audit fail)
13252
test:
133-
needs: pnpmstore
53+
needs: checks
54+
if: (${{ success() }} || ${{ failure() }}) && (${{ needs.checks.output.build_successful }})
13455
timeout-minutes: 10
13556
runs-on: ${{ matrix.os }}
13657
strategy:
13758
fail-fast: false
13859
matrix:
139-
os: [ ubuntu-latest, windows-latest, macos-latest ]
140-
node: [ 12, 14, 16 ]
60+
node: [14]
61+
os: [ubuntu-latest, macos-latest, windows-latest]
62+
include:
63+
- node: 12
64+
os: ubuntu-latest
65+
- node: 16
66+
os: ubuntu-latest
14167
steps:
68+
- uses: actions/checkout@v2
14269
- uses: actions/setup-node@v2
14370
with:
14471
node-version: ${{ matrix.node }}
145-
146-
- name: checkout
147-
uses: actions/checkout@v2
148-
149-
- name: pnpm-store
150-
uses: actions/cache@v2
151-
id: pnpm-store
72+
- run: npm i -g pnpm@6
73+
- uses: actions/setup-node@v2
15274
with:
153-
path: ${{ env.pnpm_store_path }}
154-
key: ${{ matrix.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
155-
156-
- name: install pnpm
157-
run: npm i -g pnpm@6
158-
- name: set pnpm store-dir
159-
run: pnpm config set store-dir ${{ env.pnpm_store_path }}
75+
node-version: ${{ matrix.node }}
76+
cache: 'pnpm'
77+
cache-dependency-path: '**/pnpm-lock.yaml'
16078
- name: install
161-
run: pnpm install --frozen-lockfile --offline --ignore-scripts
162-
- name: install esbuild
163-
run: node node_modules/esbuild/install.js
79+
run: |
80+
pnpm install --frozen-lockfile --prefer-offline --ignore-scripts
81+
node node_modules/esbuild/install.js
16482
- name: build
16583
run: pnpm run build:ci
16684
- name: run tests
16785
run: pnpm test:ci
168-
16986
- name: archive tests temp directory
17087
if: failure()
17188
shell: bash
@@ -190,36 +107,3 @@ jobs:
190107
temp/serve/junit.xml
191108
temp/build/jest-results.json
192109
temp/build/junit.xml
193-
194-
build:
195-
needs: pnpmstore
196-
timeout-minutes: 5
197-
runs-on: ${{ matrix.os }}
198-
strategy:
199-
matrix:
200-
os: [ ubuntu-latest ]
201-
node: [ 14 ]
202-
steps:
203-
- uses: actions/setup-node@v2
204-
with:
205-
node-version: ${{ matrix.node }}
206-
207-
- name: checkout
208-
uses: actions/checkout@v2
209-
210-
- name: pnpm-store
211-
uses: actions/cache@v2
212-
id: pnpm-store
213-
with:
214-
path: ${{ env.pnpm_store_path }}
215-
key: ${{ matrix.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
216-
- name: install pnpm
217-
run: npm i -g pnpm@6
218-
- name: set pnpm store-dir
219-
run: pnpm config set store-dir ${{ env.pnpm_store_path }}
220-
- name: install
221-
run: pnpm install --frozen-lockfile --offline --ignore-scripts
222-
- name: install esbuild
223-
run: node node_modules/esbuild/install.js
224-
- name: build
225-
run: pnpm run build

.github/workflows/release.yml

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: Release
22

3-
env:
4-
pnpm_store_path: ${{github.workspace}}/.pnpm-store
5-
63
on:
74
push:
85
branches:
@@ -13,48 +10,31 @@ jobs:
1310
# prevents this action from running on forks
1411
if: github.repository == 'sveltejs/vite-plugin-svelte'
1512
name: Release
16-
runs-on: ubuntu-latest
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
# pseudo-matrix for convenience, NEVER use more than a single combination
17+
node: [14]
18+
os: [ubuntu-latest]
1719
steps:
1820
- name: checkout
1921
uses: actions/checkout@v2
2022
with:
2123
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
2224
fetch-depth: 0
23-
- name: setup node
24-
uses: actions/setup-node@v2
25-
with:
26-
node-version: 14
27-
# install pnpm and try to reuse cache from ci action by using same cache keys
28-
- name: install pnpm
29-
run: npm i -g pnpm@6
30-
- name: set pnpm store-dir
31-
run: pnpm config set store-dir ${{ env.pnpm_store_path }}
32-
- name: pnpm-store
33-
uses: actions/cache@v2
34-
id: pnpm-store
25+
- uses: actions/setup-node@v2
3526
with:
36-
path: ${{ env.pnpm_store_path }}
37-
key: ubuntu-latest-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
38-
39-
- name: pnpm-store-fallback
40-
if: steps.pnpm-store.outputs.cache-hit != 'true'
41-
uses: actions/cache@v2
42-
id: pnpm-store-fallback
27+
node-version: ${{ matrix.node }}
28+
- run: npm i -g pnpm@6
29+
- uses: actions/setup-node@v2
4330
with:
44-
path: ${{ env.pnpm_store_path }}
45-
key: ubuntu-latest-pnpm-store-fallback-${{ hashFiles('**/pnpm-lock.yaml') }}
46-
restore-keys: |
47-
ubuntu-latest-pnpm-store-fallback-
48-
ubuntu-latest-pnpm-store-
49-
31+
node-version: ${{ matrix.node }}
32+
cache: 'pnpm'
33+
cache-dependency-path: '**/pnpm-lock.yaml'
5034
- name: install
51-
# install but don't run scripts, they could be evil
52-
run: pnpm install --frozen-lockfile --prefer-offline --ignore-scripts
53-
- name: check store
54-
run: pnpm store status
55-
- name: install esbuild
56-
# manually install esbuild because we deactivated postinstall scripts above
57-
run: node node_modules/esbuild/install.js
35+
run: |
36+
pnpm install --frozen-lockfile --prefer-offline --ignore-scripts
37+
node node_modules/esbuild/install.js
5838
5939
- name: Creating .npmrc
6040
run: |

0 commit comments

Comments
 (0)