AI Hints
Home›CI/CD with GitHub Actions Tutorial›Matrix Options and Caching
CI/CD with GitHub Actions · Lesson 50 of 138

fail-fast

Stop early, or see everything.

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

By default, if one matrix job fails, GitHub cancels the others that are still running. That saves minutes. But sometimes you want to see every result, to know whether the problem happens everywhere, or only in one place.

fail-fast
From the video: fail-fast
  • One fails, others cancelled
  • Saves minutes
  • Or see every result

fail-fast false

Fail fast is true by default. Setting it to false lets every matrix job finish, even after one fails. Here, each job checks our total function with a different tax rate. The twenty five percent job will fail, because our code adds twenty percent.

.github/workflows/matrix.ymlyaml
name: Matrix
on: push
jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        tax: ["0.2", "0.25"]
    steps:
      - run: python3 -c "from app import total; assert total([10], ${{ matrix.tax }}) == 12.0"
      - run: echo "tax ${{ matrix.tax }} is fine"

Every result

Both jobs ran to the end. The twenty percent job passed. The twenty five percent job failed, with an assertion error. Because fail fast is off, we see both results, and know the problem is specific to one setting.

Terminal
run-steps .github/workflows/matrix.yml | grep -E "^Job|Job (succeeded|failed)|Error"
Job: test (0.2)
  Job succeeded
Job: test (0.25)
      AssertionError
      Error: Process completed with exit code 1.
  Job failed

Summary

Fail fast cancels the rest of a matrix after a failure. Turn it off when you need every result. Next, making installs faster with caching.

Key takeaways
  • fail-fast: true by default
  • false shows every result
  • Find where it fails
Next up: Caching Dependencies — faster installs