AI Hints
Home›CI/CD with GitHub Actions Tutorial›Fixing Builds and the Test Pyramid
CI/CD with GitHub Actions · Lesson 76 of 138

Practice: Fix the Red Build

Read, find, fix.

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

Someone pushed a small tidy up, and now main is red. Your job is to find out why, and fix it. Use the log, then use git to see what changed.

Practice: Fix the Red Build
From the video: Practice: Fix the Red Build
  • Main is red
  • Read the log
  • Find what changed

Reading the failure

Our helper runs the CI workflow. The run tests step fails. The log shows that the discount test expected forty five, but got zero. So the discount function is broken.

Terminal
run-steps .github/workflows/ci.yml | grep -E "✗|assert|FAILED"
  ✗ Run tests
      >       assert discount(50, 10) == 45.0
      E       assert 0.0 == 45.0
      FAILED test_app.py::test_discount - assert 0.0 == 45.0

Finding and fixing it

Git log shows the last commit, called tidy discount. Git diff shows exactly what it changed. A hundred became ten. Sed puts it back, and the workflow is green again. Then you'd push the fix, and maybe add a test case that makes the mistake obvious.

Terminal
git log --oneline -2
57795df Tidy discount
c0fd447 First version of the shop
git diff HEAD~1 | grep "^[-+] "
-    return round(price * (1 - percent / 100), 2)
+    return round(price * (1 - percent / 10), 2)
sed -i 's#percent / 10)#percent / 100)#' app.py
run-steps .github/workflows/ci.yml | tail -2
      3 passed in 0.01s
  Job succeeded

When main is red

Treat a red main branch as the team's top priority, because everyone builds on it. If the fix isn't quick, revert the bad commit first, and fix it calmly on a branch. And say so in the team chat, so nobody wastes time wondering why their pull request is red.

keyvalue
Top priorityeveryone builds on main
Not quick?revert first
Tell the teamsave confusion
Add a teststop it coming back

Summary

Read the failing step, use git log and git diff to find the change, then fix or revert. Next, how many of each kind of test to write.

Key takeaways
  • Read the log
  • git log, git diff
  • Fix or revert
Next up: The Test Pyramid — fast at the bottom