Last active
July 27, 2025 02:36
-
-
Save kevbost/f86d71a4b06f5af12846e08a23e5bb04 to your computer and use it in GitHub Desktop.
npm_ci_if_cache_miss github workflow example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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