0
votes

I have a workflow that constists of 3 jobs - "Start self-hosted EC2 runner", "Run Integration Tests" and "Stop self-hosted EC2 runner". A Github Action that I used as a source for my implementation can be found at this link. In practice when Tests are failing and its job looks "red", workflow still looks "green" and I need to fix that (= make it look "red"). However, it is mandatory that "Stop self-hosted EC2 runner" job must execute even if "Run Integration test" job fails, so I can not fail the workflow from within "Run Integration Tests" job.

enter image description here

I suspect I can add yet another job dependent on all three, which then checks the status of all the Jobs and fail the workflow. How can I do that or otherwise make workflow "red" while always executing "Start.." and "Stop..." jobs regardless of tests success or failure?

1
Could you share your workflow .yml file implementation please? - GuiFalourd
It seems you use the needs syntax in your workflow to execute jobs in sequence. You can use the if: always() syntax with it to force execute other jobs even if a previous one failed. Reference - GuiFalourd
@GuiFalourd correct, jobs run in sequence because of "needs". You can check the job setup in github.com/machulav/ec2-github-runner#example. My workflow is based on this closely and uses this great action. - Askar Ibragimov
@GuiFalourd the problem is that after test fail, Workflow is still green so for instance if this is run as part of Pull Request checks, it is considered OK, contrary to what is intended. - Askar Ibragimov
I believe this is exactly the idea of this workflow (not failing the workflow when the 2nd job fails). Currently, for what I saw and looked for, it doesn't seem to have a native syntax to perform what you want. However, the workaround you talked about (another job to check the previous ones success or failure) should work (it could even be an action!). - GuiFalourd

1 Answers

0
votes

The cause of workflow not failing is that 2nd job has to have continue-on-error: true attribute.

I ended up adding another job at the end like so:

// Last job:

  fail-on-job2:
    # Without this step workflow remains "green" if job2 does fail.
    name: Job2 Status -> Workflow Status
    needs:
      - job1
      - job2
      - job3
    runs-on: ubuntu-latest
    if: always()
    steps:
      - uses: technote-space/workflow-conclusion-action@v2
      - name: Check Job Status status and fail if they are red
        if: env.WORKFLOW_CONCLUSION == 'failure'
        run: exit 1