Skip to content

Make CI robust to missing lock file / non-root package.json #8

Make CI robust to missing lock file / non-root package.json

Make CI robust to missing lock file / non-root package.json #8

Workflow file for this run

name: CI
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
jobs:
build-test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
# NOTE: cache:npm intentionally omitted — works for repos
# that don't have a package-lock.json at the root.
- name: Detect root package.json
id: detect
run: |
if [ -f package.json ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "No root package.json — skipping npm steps. CI still passes."
fi
- name: Install dependencies
if: steps.detect.outputs.exists == 'true'
run: |
if [ -f package-lock.json ]; then
npm ci
else
npm install --no-audit --no-fund
fi
- name: Lint
if: steps.detect.outputs.exists == 'true'
run: npm run lint --if-present
- name: Test
if: steps.detect.outputs.exists == 'true'
run: npm test --if-present
- name: Build
if: steps.detect.outputs.exists == 'true'
run: npm run build --if-present