Skip to content

Commit dc04560

Browse files
committed
Add npm package cache optimization for CI
- Add new cache-npm-packages GitHub Action for caching test packages - Update test workflow to use npm package caching for better performance - Add registry package tarball for deployment
1 parent 9b40851 commit dc04560

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: 'Cache NPM Test Packages'
2+
description: 'Cache npm test packages to speed up subsequent CI runs'
3+
4+
# Dependencies:
5+
# - actions/cache@6c4d0c5a42fb47aea2ce2de7ed5a0b70b23ee3e1 # v4.3.0
6+
7+
inputs:
8+
path:
9+
description: 'Path to cache directory'
10+
required: false
11+
default: '~/.socket-npm-test-cache'
12+
key-prefix:
13+
description: 'Cache key prefix'
14+
required: false
15+
default: 'npm-test-packages'
16+
restore-keys:
17+
description: 'Restore keys for fallback'
18+
required: false
19+
default: ''
20+
21+
outputs:
22+
cache-hit:
23+
description: 'Whether cache was hit'
24+
value: ${{ steps.cache.outputs.cache-hit }}
25+
26+
runs:
27+
using: 'composite'
28+
steps:
29+
- name: Determine cache path
30+
id: cache-path
31+
shell: bash
32+
run: |
33+
if [ "${{ runner.os }}" = "Windows" ]; then
34+
# On Windows, expand ~ to home directory
35+
CACHE_PATH="${USERPROFILE}/.socket-npm-test-cache"
36+
CACHE_PATH=$(echo "$CACHE_PATH" | sed 's|\\|/|g')
37+
else
38+
# On Unix-like systems
39+
CACHE_PATH="${HOME}/.socket-npm-test-cache"
40+
fi
41+
echo "cache-path=$CACHE_PATH" >> $GITHUB_OUTPUT
42+
echo "Using cache path: $CACHE_PATH"
43+
44+
- name: Cache npm test packages
45+
id: cache
46+
uses: actions/cache@6c4d0c5a42fb47aea2ce2de7ed5a0b70b23ee3e1 # v4.3.0
47+
with:
48+
path: ${{ steps.cache-path.outputs.cache-path }}
49+
# Use package manifest hash and OS in cache key for specificity
50+
key: ${{ inputs.key-prefix }}-${{ runner.os }}-${{ hashFiles('packages/npm/*/package.json') }}
51+
restore-keys: |
52+
${{ inputs.key-prefix }}-${{ runner.os }}-
53+
${{ inputs.key-prefix }}-
54+
55+
- name: Create cache directory if missing
56+
if: steps.cache.outputs.cache-hit != 'true'
57+
shell: bash
58+
run: |
59+
CACHE_DIR="${{ steps.cache-path.outputs.cache-path }}"
60+
mkdir -p "$CACHE_DIR"
61+
echo "Cache directory created at $CACHE_DIR"

.github/workflows/test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: ⚡ Test
22

33
# Dependencies:
44
# - SocketDev/socket-registry/.github/actions/setup-and-install@main
5+
# - SocketDev/socket-registry/.github/actions/cache-npm-packages@main
56
# - SocketDev/socket-registry/.github/actions/run-script@main
67
# - SocketDev/socket-registry/.github/actions/artifacts@main
78

@@ -107,6 +108,12 @@ jobs:
107108
node-version: ${{ matrix.node-version }}
108109
working-directory: ${{ inputs.working-directory }}
109110

111+
- name: Cache npm test packages
112+
uses: SocketDev/socket-registry/.github/actions/cache-npm-packages@main
113+
with:
114+
path: ~/.socket-npm-test-cache
115+
key-prefix: npm-test-packages
116+
110117
- uses: SocketDev/socket-registry/.github/actions/run-script@main
111118
with:
112119
main-script: ${{ inputs.test-script }}

0 commit comments

Comments
 (0)