Module 4 · Project 04 · Build Your First CI Pipeline · Lesson 16 of 48

Fast and safe CI: caching, parallel jobs, secrets and gates

Speed pipelines up with caching and parallelism, keep secrets safe, add test reports and scanning, and protect the main branch.

In this lesson · about 25 minutes

  • Use caching, parallel jobs and a matrix to speed up CI
  • Store and use secrets safely
  • Add test reports, notifications, dependency scanning and branch protection

Make it fast

Developers wait for CI, so minutes matter. Three big wins:

  • Caching: reuse downloaded dependencies between runs (cache: npm or actions/cache, keyed on the lockfile's hash).
  • Parallel jobs: lint and test don't depend on each other, so run them as separate jobs at the same time. Use needs: only where order matters.
  • A matrix: run the same job across versions or split tests into shards.
jobs:
  lint:
    runs-on: ubuntu-latest
    steps: [ … checkout, setup-node, npm ci, npm run lint … ]

  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node: [20, 22]
        shard: [1, 2, 3]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with: { node-version: "${{ matrix.node }}", cache: npm }
      - run: npm ci
      - run: npm test -- --shard=${{ matrix.shard }}/3 --reporter=junit --output=report.xml
      - uses: actions/upload-artifact@v4
        if: always()                       # keep the report even if tests fail
        with: { name: "tests-${{ matrix.node }}-${{ matrix.shard }}", path: report.xml }

  build:
    needs: [lint, test]                    # only if both passed
    runs-on: ubuntu-latest
    steps: [ … ]

Keep it safe

  • Secrets: store tokens and passwords in the repository's Settings → Secrets, and use them as ${{ secrets.REGISTRY_TOKEN }}. GitHub hides them in logs. Never echo them, and never put them in the workflow file.
  • Least privilege: add permissions: contents: read at the top so the workflow's built-in token can't do more than it needs.
  • Dependency scanning: npm audit --audit-level=high, or GitHub's Dependabot, flags packages with known vulnerabilities. (Project 11 builds a full security gate.)
  • Notifications: post failures on main to the team chat, using the same webhook idea as Project 01.
  • Branch protection: in the repo settings, require the CI checks to pass (and a review) before anything merges into main.

Whiteboard · watch and try

Sequential vs parallel

Press Play to work out the run time both ways.

5 steps
Press Play and the tutor will talk you through it while writing on the board. Pause any time to write on the board yourself.

Tip: press Pause, then use the pen to work along on the board. Space plays and pauses; Ctrl+Z undoes your last mark.

Sorting drill

Safe or risky?

Sort each pipeline habit.

  • Token stored in repository secrets and read with secrets.TOKEN
  • Password pasted into ci.yml
  • run: echo $DEPLOY_KEY to debug
  • permissions: contents: read
  • Main branch requires passing checks before merge
  • Third-party action pinned to a commit SHA
  • Skipping tests to make the pipeline green

0 of 7 sorted

Check your understanding0 of 3 correct

Question 1

1.What does needs: [lint, test] on the build job do?

Question 2

2.Why use if: always() on the step that uploads test reports?

Question 3

3.What should a cache key for npm dependencies be based on?

Key terms

Say the meaning to yourself, then tap a card to check.

Quiz score: 0 of 3

Tip: answer every quiz question correctly first.

Written by Noviq Academy in its own words. The labs are simulations: no real servers are touched. When you build the projects yourself, use a practice virtual machine or a free-tier cloud account you control, watch your cloud spending, and never run cleanup or delete commands on a machine you care about. Tool names belong to their owners; versions and output are shown for learning and may differ slightly from yours. Read-aloud and the whiteboard voice use your device's built-in voices.