Typorithm · medium

Build, Test, Deploy Stages

cicd-stagesdevopsstagesneedsdeploy
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Build, Test, Deploy Stages

0%

CI/CD

Stage a pipeline so deploy only runs after tests pass (needs: test) and only on the right branch (if:). This gates releases, fails fast on a bad commit, and keeps broken code from shipping. Jobs run in parallel unless a needs dependency orders them.

A pipeline is staged: build, then test, then deploy. Each stage is a job, and a later stage should only proceed when the earlier one succeeds.

needs: test makes the deploy job wait for the test job and run only if it passed. This fails fast — a broken commit stops at the test stage and never reaches deploy.

The if: condition narrows deploy further to a single branch (github.ref == 'refs/heads/main'), so feature branches run tests but only main ships. Jobs run in parallel unless a needs dependency orders them.

01

needs: test makes deploy wait for tests to pass.

02

if: gates a job on a condition like the branch.

03

Jobs are parallel unless needs creates an order.

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - run: npm test
  deploy:
    needs: test
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps:
      - run: ./deploy.sh

Read the implementation

Connect each part of the code to the concept before you type.

1. Test job

The test job runs first and gates everything after it.

test:
    runs-on: ubuntu-latest

2. Run tests

The test stage runs the suite; a failure stops the deploy.

- run: npm test

3. Deploy job

The deploy job ships the app once it is allowed to run.

deploy:

4. Job dependency

needs makes deploy wait for test to finish successfully.

needs: test

5. Branch guard

if restricts deploy to runs on the main branch.

if: github.ref == 'refs/heads/main'

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Build, Test, Deploy Stages: Lesson & Practice · Typorithm | ApplyDjinn