Skip to content

Instantly share code, notes, and snippets.

@kevbost
Last active July 27, 2025 02:36
Show Gist options
  • Save kevbost/f86d71a4b06f5af12846e08a23e5bb04 to your computer and use it in GitHub Desktop.
Save kevbost/f86d71a4b06f5af12846e08a23e5bb04 to your computer and use it in GitHub Desktop.
npm_ci_if_cache_miss github workflow example
name: CI Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
npm_ci_if_cache_miss:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Restore npm cache
uses: actions/cache@v4
with:
path: node_modules
key: npm-ci-v1-${{ hashFiles('package-lock.json') }}
restore-keys: |
npm-ci-v1-
- name: Run npm ci if cache miss
run: |
if [ -f node_modules/.package-lock.json ]; then
echo "node_modules is not empty, so assuming there was a cache hit and skipping 'npm ci'"
else
npm ci --ignore-scripts --no-fund --no-audit
fi
- name: Run tests
run: npm test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment