-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy path04-advanced-features--03-caching.yaml
More file actions
65 lines (59 loc) · 2.58 KB
/
Copy path04-advanced-features--03-caching.yaml
File metadata and controls
65 lines (59 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: Caching
on:
workflow_dispatch:
jobs:
# ──────────────────────────────────────────────
# 2) Generic cache with actions/cache
# ──────────────────────────────────────────────
actions-cache:
name: Prime demo cache
runs-on: ubuntu-24.04
steps:
# Attempt to restore (misses on first run)
- name: Restore cache
id: demo-cache
uses: actions/cache@638ed79f9dc94c1de1baef91bcab5edaa19451f4 # v4.2.4
with:
path: demo-cache
# For info on constructing an appropriate cache key see:
# https://github.com/actions/cache?tab=readme-ov-file#creating-a-cache-key
key: demo-cache-v1
# Populate directory only on miss
- name: Populate cache directory
if: steps.demo-cache.outputs.cache-hit != 'true'
run: |
echo "Cache miss – generating contents"
mkdir -p demo-cache
date > demo-cache/timestamp.txt
# Save cache only if we generated new content
- name: Save cache
if: steps.demo-cache.outputs.cache-hit != 'true'
uses: actions/cache@638ed79f9dc94c1de1baef91bcab5edaa19451f4 # v4.2.4
with:
path: demo-cache
key: demo-cache-v1
- name: Verify cache status
run: |
echo "cache-hit? -> ${{ steps.demo-cache.outputs.cache-hit }}"
cat demo-cache/timestamp.txt
# ──────────────────────────────────────────────
# 3) Cache via actions/setup-node
# ──────────────────────────────────────────────
node-cache:
name: npm dependency cache (setup-node)
runs-on: ubuntu-24.04
defaults:
run:
working-directory: 04-advanced-features/caching/minimal-node-project
steps:
- uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493 # v5.0.0
- uses: actions/setup-node@d7a11313b581b306c961b506cfc8971208bb03f6 # v4.4.0
with:
node-version: 20
cache: npm
# Point cache action at the specific lock-file path
cache-dependency-path: 04-advanced-features/caching/minimal-node-project/package-lock.json
- name: Install dependencies
run: npm ci --prefer-offline --no-audit
- name: List first few modules
run: ls -R node_modules | head