File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : CI with Caching
2+
3+ on :
4+ push :
5+ branches : [ master, feature/github-actions-practice ]
6+ pull_request :
7+ branches : [ master ]
8+ workflow_dispatch :
9+
10+ jobs :
11+ build :
12+ runs-on : ubuntu-latest
13+
14+ steps :
15+ - name : Checkout code
16+ uses : actions/checkout@v4
17+
18+ - name : Setup Node.js
19+ uses : actions/setup-node@v4
20+ with :
21+ node-version : ' 22'
22+ cache : ' npm' # ✨ Built-in npm caching!
23+
24+ - name : Cache node_modules
25+ uses : actions/cache@v4
26+ with :
27+ path : ~/.npm
28+ key : ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
29+ restore-keys : |
30+ ${{ runner.os }}-node-
31+
32+ - name : Install dependencies
33+ run : npm ci
34+
35+ - name : Run tests
36+ run : npm test -- --passWithNoTests --watchAll=false --coverage
37+
38+ - name : Build project
39+ run : npm run build
40+
41+ - name : Upload coverage report
42+ uses : actions/upload-artifact@v4
43+ with :
44+ name : coverage-report
45+ path : coverage/
46+ retention-days : 7
Original file line number Diff line number Diff line change 1+ Next, we'll learn how to cache node_modules to make builds much faster!
Original file line number Diff line number Diff line change 11Example 2: Matrix Build - Test on Multiple Node Versions
22- Run tests on Node 18, 20, and 22 simultaneously
33- See 3 jobs running in parallel
4- - Understand matrix strategy
4+ - Understand matrix strategy
5+
6+ # Matrix Strategy creates multiple jobs from one definition:
7+
8+ - node-version: [ 18, 20, 22] → Creates 3 jobs
9+ - All run in parallel (at the same time)
10+ - Uses ${{ matrix.node-version }} to reference the current value
11+
12+ Real-world use cases:
13+
14+ - Test on multiple Node versions (like we just did)
15+ - Test on multiple OS (Ubuntu, Windows, macOS)
16+ - Test with different dependency versions
17+ - Test different configurations
18+
You can’t perform that action at this time.
0 commit comments