github-actions

In Github Actions, how can I make all steps run, but the job fail if one fails?


The reason I want this is because I want to see a complete list of static code failures. I could separate them into individual jobs and a job dependent on their completions, but I don't need them run in parallel and it seems like a lot of wasteful repeated identical setups.

What I have so far is this:

jobs:
  checks:
    name: Run Checks
    runs-on: ubuntu-22.04
    steps:

      # ... Various setup code...

      - name: Lint
        uses: borales/actions-yarn@v4
        continue-on-error: true
        with:
          cmd: lint --max-warnings=0

      - name: Run the type check
        uses: borales/actions-yarn@v4
        continue-on-error: true
        with:
          cmd: type-check

      - name: Run the unit tests
        uses: borales/actions-yarn@v4
        continue-on-error: true
        with:
          cmd: test

      - name: A step has failed
        if: failure()
        run: exit 1

As may be evident, this will not work. continue-on-error means the step is never marked as a failure, and without it I never see what else is going to fail. This means I need a different approach to the pipeline configuration to achieve the outcome.

Does anyone have any recommendations?


Solution

  • Make each check its own job, then write one job which needs all the check jobs. All the jobs will execute in parallel (bonus, this will be faster), but the top level job will only succeed if they all succeed.

    jobs:
      checks:
        name: Run Checks
        needs: [lint, type-checks, test]
      lint:
        - name: Lint
          uses: borales/actions-yarn@v4
          with:
            cmd: lint --max-warnings=0
      type-checks:
        - name: Run the type check
          uses: borales/actions-yarn@v4
          with:
            cmd: type-check
      test:
        - name: Run the unit tests
          uses: borales/actions-yarn@v4
          with:
            cmd: test