Skip to content

Commit 57be806

Browse files
committed
Added cache to build pages workflow
1 parent 40bb8af commit 57be806

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

.github/workflows/build-and-deploy-pages.yml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,43 @@ jobs:
4040
- uses: actions/checkout@v4
4141
with:
4242
ref: ${{ matrix.branch }}
43+
- name: Build cache key
44+
id: cache-key
45+
run: |
46+
HASH=$(git rev-parse --short HEAD)
47+
echo "CACHE_KEY=$(${{ matrix.branch }}-$HASH)" >> "$GITHUB_ENV"
48+
- name: Restore cached artifacts
49+
id: artifacts-restore
50+
uses: actions/cache/restore@v4
51+
with:
52+
path: ${{ matrix.branch }}
53+
key: CACHE_KEY
4354
- uses: actions/setup-node@v4
55+
if: steps.artifacts-restore.outputs.cache-hit != 'true'
4456
with:
4557
node-version: 23
4658
cache: npm
47-
- run: npm ci
48-
- run: git checkout ${{ matrix.branch }}
49-
- run: npm run build-compat
50-
- run: npm run bundle
59+
- name: Build
60+
if: steps.artifacts-restore.outputs.cache-hit != 'true'
61+
run: |
62+
npm ci
63+
npm run build-compat
64+
npm run bundle
5165
- name: Prepare build artifacts
66+
if: steps.artifacts-restore.outputs.cache-hit != 'true'
5267
run: |
5368
mkdir -p ${{ matrix.branch }}/compat
5469
cp tests/compat/index.html tests/compat/compat-data.js tests/compat/tests.js tests/compat/browsers-runner.js ${{ matrix.branch }}/compat
5570
mkdir -p ${{ matrix.branch }}/bundles
5671
cp tests/bundles/* ${{ matrix.branch }}/bundles
5772
mkdir -p ${{ matrix.branch }}/unit-browser
5873
cp tests/unit-browser/* ${{ matrix.branch }}/unit-browser
74+
- name: Save cached artifacts
75+
if: steps.artifacts-restore.outputs.cache-hit != 'true'
76+
uses: actions/cache/save@v4
77+
with:
78+
path: ${{ matrix.branch }}
79+
key: CACHE_KEY
5980
- name: Upload artifacts for branch ${{ matrix.branch }}
6081
uses: actions/upload-artifact@v4
6182
with:
@@ -74,7 +95,8 @@ jobs:
7495
uses: actions/download-artifact@v4
7596
with:
7697
path: pages
77-
- run: cp -r docs/ pages/
98+
- name: Add docs
99+
run: cp -r docs/ pages/
78100
- name: Setup Pages
79101
uses: actions/configure-pages@v5
80102
- name: Upload GitHub Pages artifact

0 commit comments

Comments
 (0)