Skip to content

Commit 9e8a063

Browse files
author
“Kirti
committed
caching ci
1 parent f59efa0 commit 9e8a063

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

.github/workflows/cache-ci.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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

Caching Dependencies.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Next, we'll learn how to cache node_modules to make builds much faster!

Matric.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
Example 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+

0 commit comments

Comments
 (0)