Don't do the same work twice
Downloading dependencies on every run is slow. A cache keeps files between runs, keyed by something like a hash of the lockfile. An artifact keeps a job's output — a build, a test report — so a later job (or a human) can download it.
cache, upload, download
name: Build
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: ~/.npm
key: npm-${{ hashFiles('package-lock.json') }}
- run: npm ci
- run: npm run build
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist
smoke-test:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist
- run: node dist/server.js