AI Hints
Home›CI/CD with GitHub Actions Tutorial›Projects: CI and Delivery
CI/CD with GitHub Actions · Lesson 119 of 138

Project: Node CI

The JavaScript version.

⏱ 2 min read▶ Video at 2:19:03🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Second project. ACI pipeline for the Node cart library, tested on two Node versions. Then we'll break the code, and watch the tests catch it.

Project: Node CI
From the video: Project: Node CI
  • Node cart library
  • Two Node versions
  • Break it, catch it

node.yml

The matrix runs Node twenty and twenty two. Setup node installs each version, and caches NPM downloads. Then NPMCI installs from the lock file, and the lint and test scripts run.

.github/workflows/node.ymlyaml
name: Node CI
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix: { node: [20, 22] }
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: "${{ matrix.node }}", cache: npm }
      - run: npm ci
      - run: npm run lint
      - run: npm test

Catching a bug

Both jobs pass. Now someone edits the total, and forgets to multiply by the quantity. The lint still passes, because the syntax is fine. But the tests fail, in both jobs.

Terminal
run-steps .github/workflows/node.yml | grep -E "^Job|succeeded"
Job: test (20)
  Job succeeded
Job: test (22)
  Job succeeded
sed -i 's/i.price \* i.qty/i.price/' cart.js
run-steps .github/workflows/node.yml | grep -E "^Job|✓ Run npm run|✗|failed"
Job: test (20)
  ✓ Run npm run lint
  ✗ Run npm test
  Job failed
Job: test (22)
  ✓ Run npm run lint
  ✗ Run npm test
  Job failed

Fixing it

Git diff shows the change that broke the tests. Git checkout puts the file back the way it was in the last commit. And our helper runs both jobs again. They both succeed.

Terminal
git diff --stat
 cart.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
git checkout -- cart.js
run-steps .github/workflows/node.yml | grep -E "^Job|succeeded"
Job: test (20)
  Job succeeded
Job: test (22)
  Job succeeded

Summary

Same pipeline shape, different tools. Install from the lock file, lint, and test on each Node version. Next, a project that delivers a Docker image.

Key takeaways
  • setup-node + cache
  • npm ci, lint, test
  • Matrix of versions
Next up: Project: Docker Delivery — test, then ship an image