CD7: CI pipelines with GitHub Actions

Lesson 2 of 5 · reading 15–25 minutes; practice and project time is on the module page

Writing RouteRani's workflow

🎯You'll be able to

Write jobs with a database service, Terraform checks and alert-rule tests, connect them with needs, and limit the deploy job to main.

🏠The everyday picture

An exam has stages: the written paper first, the practical only for those who pass, and the certificate only after both. Nobody gets a certificate because the practical happened to be scheduled earlier.

📘What it really is

📝A worked example

Input: run the Project 2 workflow checks on your computer: cd tests, then node --test --test-name-pattern="workflow|action|deploy runs" pipeline.test.js.

Expected output: on the starter, tests 1 to 4 fail with messages such as pushes should trigger the workflow on main only and the deploy job must need the test job. After the changes in this module, all four pass. They read the YAML; they don't run it on GitHub.

🌍Where it's used

📝Case scenario

A food delivery company's deploy job had no needs, so build and deploy jobs started at the same moment. Usually the tests finished first, but one Friday a slow test run lost the race; the deploy shipped a change whose tests were still running and later failed. Orders from one city failed for twenty minutes. Adding needs: test made the order explicit.

🖱️Try it

In the starter's workflow, add needs: test and the if: condition to deploy, change on: to pull_request plus push to main, and run the Project 2 tests 1 and 4. Success: those two pass, and the messages from tests 2 and 3 tell you what's left.

⚠️Common mistakes

🛠️For your project

Project 2 test 4 checks the deploy job needs the test job, runs only for main, has an environment and a concurrency group.

✅Quick check

Why does RouteRani's deploy job use --skip-tests?

Show the answer

The test job already ran the tests, and needs makes deploy wait for it.

What does terraform init -backend=false allow?

Show the answer

Running validate without access to the real state.

← PreviousContinuous integration, and how GitHub Actions works
ProLearners Assist