Skip to content

Commit 820fb88

Browse files
authored
Github Actions | Cypress caching (#1125)
* update CI workflow name * Cypress cache key uses proper parameter name * add gha caching
1 parent fae2476 commit 820fb88

File tree

1 file changed

+138
-45
lines changed

1 file changed

+138
-45
lines changed

.github/workflows/ci-website.yml

Lines changed: 138 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Website
1+
name: Website Build
22

33
on:
44
pull_request:
@@ -15,62 +15,100 @@ on:
1515
- '.github/**'
1616
- 'package.json'
1717
- 'yarn.lock'
18+
1819
jobs:
1920
build:
2021
runs-on: ubuntu-latest
2122
steps:
2223
- uses: actions/checkout@v4
24+
2325
- uses: volta-cli/action@v4
26+
27+
# Add yarn cache
28+
- name: Get yarn cache directory path
29+
id: yarn-cache-dir-path
30+
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
31+
32+
- name: Restore yarn cache
33+
uses: actions/cache@v3
34+
id: yarn-cache
35+
with:
36+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
37+
key: ${{ runner.os }}-node-${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }}
38+
restore-keys: |
39+
${{ runner.os }}-node-${{ matrix.node-version }}-yarn-
40+
${{ runner.os }}-node-${{ matrix.node-version }}-
41+
${{ runner.os }}-
42+
43+
# Add build cache
44+
- name: Cache build output
45+
uses: actions/cache@v3
46+
with:
47+
path: |
48+
**/dist
49+
**/build
50+
**/.cache
51+
**/public
52+
key: ${{ runner.os }}-node-${{ matrix.node-version }}-build-${{ github.sha }}
53+
restore-keys: |
54+
${{ runner.os }}-node-${{ matrix.node-version }}-build-
55+
${{ runner.os }}-node-${{ matrix.node-version }}-
56+
${{ runner.os }}-
57+
2458
- run: yarn
59+
2560
- name: Build
2661
run: yarn build
62+
2763
- name: Lint
2864
run: yarn lint
65+
2966
- name: Test
3067
run: yarn test
68+
3169
- name: Cypress
3270
uses: cypress-io/github-action@v6
3371
with:
3472
working-directory: packages/website
3573
start: yarn test-cypress
36-
key: cypress-${{ runner.os }}-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
3774
install-command: yarn install
3875
browser: chrome
3976
wait-on: 'http://localhost:8000'
4077
wait-on-timeout: 120
78+
cache-key: cypress-${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
4179
env:
4280
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43-
os-compatibility:
44-
needs: build
45-
runs-on: ${{ matrix.os }}
46-
strategy:
47-
matrix:
48-
os:
49-
# - macos-latest
50-
- windows-latest
51-
steps:
52-
- uses: actions/checkout@v4
53-
- uses: volta-cli/action@v4
54-
- run: yarn
55-
- name: Build
56-
run: yarn build
57-
- name: Test
58-
run: yarn test
5981

6082
node-compatibility:
6183
needs: build
6284
runs-on: ubuntu-latest
63-
6485
strategy:
86+
fail-fast: false
6587
matrix:
66-
node-version: [20]
67-
# node-version: [16.x, 18.x, 20.x]
88+
node-version: [16.x, 18.x, 20.x]
6889
steps:
6990
- uses: actions/checkout@v4
7091
- uses: volta-cli/action@v4
7192
with:
7293
node-version: ${{ matrix.node-version }}
7394
yarn-version: 3.6.4
95+
96+
# Add yarn cache
97+
- name: Get yarn cache directory path
98+
id: yarn-cache-dir-path
99+
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
100+
101+
- name: Restore yarn cache
102+
uses: actions/cache@v3
103+
id: yarn-cache
104+
with:
105+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
106+
key: ${{ runner.os }}-node-${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }}
107+
restore-keys: |
108+
${{ runner.os }}-node-${{ matrix.node-version }}-yarn-
109+
${{ runner.os }}-node-${{ matrix.node-version }}-
110+
${{ runner.os }}-
111+
74112
- run: yarn
75113
- name: Build
76114
run: yarn build
@@ -81,19 +119,56 @@ jobs:
81119
with:
82120
working-directory: packages/website
83121
start: yarn test-cypress
84-
key: cypress-${{ runner.os }}-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
85122
install-command: yarn install
86123
browser: chrome
87124
wait-on: 'http://localhost:8000'
88125
wait-on-timeout: 120
126+
cache-key: cypress-${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
89127
env:
90128
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
129+
130+
os-compatibility:
131+
needs: build
132+
runs-on: ${{ matrix.os }}
133+
strategy:
134+
fail-fast: false
135+
matrix:
136+
include:
137+
- os: windows-latest
138+
node-version: 20
139+
- os: ubuntu-latest
140+
node-version: 20
141+
steps:
142+
- uses: actions/checkout@v4
143+
- uses: volta-cli/action@v4
144+
with:
145+
node-version: ${{ matrix.node-version }}
146+
yarn-version: 3.6.4
147+
148+
# Add yarn cache
149+
- name: Get yarn cache directory path
150+
id: yarn-cache-dir-path
151+
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
152+
153+
- name: Restore yarn cache
154+
uses: actions/cache@v3
155+
id: yarn-cache
156+
with:
157+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
158+
key: ${{ matrix.os }}-node-${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }}
159+
restore-keys: |
160+
${{ matrix.os }}-node-${{ matrix.node-version }}-yarn-
161+
${{ matrix.os }}-node-${{ matrix.node-version }}-
162+
${{ matrix.os }}-
163+
91164
ts-compatibility:
92165
needs: build
93166
runs-on: ubuntu-latest
94167
continue-on-error: ${{ matrix.experimental }}
95168
strategy:
169+
fail-fast: false
96170
matrix:
171+
node-version: [20.x]
97172
typescript-version: [beta, next]
98173
include:
99174
- typescript-version: beta
@@ -102,32 +177,29 @@ jobs:
102177
- typescript-version: next
103178
experimental: true
104179
name: 'ts-canary'
105-
106-
107180
steps:
108181
- uses: actions/checkout@v4
109182
- uses: volta-cli/action@v4
110-
- run: yarn
111-
- name: Installing TypeScript ${{ matrix.typescript-version }}
112-
run: yarn workspaces foreach --exclude hello-ts --exclude '@mike-north/typescript-courses' -vpi add -D typescript@${{ matrix.typescript-version}}
113-
- name: Build
114-
run: yarn build
115-
- name: Type-check website
116-
run: yarn postinstall && yarn typecheck
117-
- name: Test
118-
run: yarn test
119-
- name: Cypress
120-
uses: cypress-io/github-action@v6
121183
with:
122-
working-directory: packages/website
123-
start: yarn test-cypress
124-
key: cypress-${{ runner.os }}-${{ matrix.node-version }}-${{ hashFiles('**/yarn.lock') }}
125-
install-command: yarn install
126-
browser: chrome
127-
wait-on: 'http://localhost:8000'
128-
wait-on-timeout: 120
129-
env:
130-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
184+
node-version: ${{ matrix.node-version }}
185+
yarn-version: 3.6.4
186+
187+
# Add yarn cache
188+
- name: Get yarn cache directory path
189+
id: yarn-cache-dir-path
190+
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
191+
192+
- name: Restore yarn cache
193+
uses: actions/cache@v3
194+
id: yarn-cache
195+
with:
196+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
197+
key: ${{ runner.os }}-node-${{ matrix.node-version }}-ts-${{ matrix.typescript-version }}-yarn-${{ hashFiles('**/yarn.lock') }}
198+
restore-keys: |
199+
${{ runner.os }}-node-${{ matrix.node-version }}-ts-${{ matrix.typescript-version }}-yarn-
200+
${{ runner.os }}-node-${{ matrix.node-version }}-ts-${{ matrix.typescript-version }}-
201+
${{ runner.os }}-node-${{ matrix.node-version }}-
202+
${{ runner.os }}-
131203
132204
publish:
133205
needs: [build, os-compatibility, node-compatibility, ts-compatibility]
@@ -136,12 +208,33 @@ jobs:
136208
steps:
137209
- uses: actions/checkout@v4
138210
- uses: volta-cli/action@v4
211+
with:
212+
node-version: 20.x
213+
yarn-version: 3.6.4
214+
215+
# Add yarn cache
216+
- name: Get yarn cache directory path
217+
id: yarn-cache-dir-path
218+
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
219+
220+
- name: Restore yarn cache
221+
uses: actions/cache@v3
222+
id: yarn-cache
223+
with:
224+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
225+
key: ${{ runner.os }}-node-20-yarn-${{ hashFiles('**/yarn.lock') }}
226+
restore-keys: |
227+
${{ runner.os }}-node-20-yarn-
228+
${{ runner.os }}-node-20-
229+
${{ runner.os }}-
230+
139231
- run: yarn
232+
140233
- name: Build
141234
run: yarn workspace website run build-prod
235+
142236
- uses: peaceiris/actions-gh-pages@v3
143237
with:
144238
github_token: ${{ secrets.ACCESS_TOKEN }}
145239
publish_dir: ./packages/website/public
146240
cname: www.typescript-training.com
147-

0 commit comments

Comments
 (0)