AI Hints
CI/CD with GitHub Actions · Lesson 27 of 138

A Failing Build

Red means stop.

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

CI is only useful if it catches mistakes. So let's make one. A teammate changes the tax rate by mistake, and pushes. Let's watch the pipeline catch it, before it reaches users.

A Failing Build
From the video: A Failing Build
  • CI must catch mistakes
  • A wrong tax rate
  • Caught before users

The mistake

Sed changes the tax from twenty percent to thirty percent, and the change is committed. Git show, with stat, confirms that only app dot py changed. On GitHub, this push starts the CI workflow.

Terminal
sed -i 's/tax=0.2/tax=0.3/' app.py
git commit -qam "Update tax"
git show --stat --oneline
66a6c8a Update tax
 app.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

The pipeline catches it

The run steps log shows the install step passing, then the tests failing. Pytest says the total was thirty nine, not thirty six. The step exits with code one, and the job fails. On GitHub, this commit gets a red cross, and the author gets an email.

Terminal
run-steps .github/workflows/ci.yml 2>&1 | grep -E 'Job|✓|✗|assert|exit code|passed|failed'
Job: test
  ✓ Install dependencies
  ✗ Run tests
      >       assert total([10, 20]) == 36.0
      E       assert 39.0 == 36.0
      FAILED test_app.py::test_total_adds_tax - assert 39.0 == 36.0
      1 failed, 2 passed in 0.01s
      Error: Process completed with exit code 1.
  Job failed

Summary

A broken change gives a red run, with the reason in the log. The mistake was caught in minutes. Next, fixing the build.

Key takeaways
  • Red run = stop
  • The log says why
  • Caught in minutes
Next up: Fixing the Build — back to green