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"
0 commit comments