1

I am writing a GitHub workflow to run some CI/CD pipelines.

In particular, I am running commands through a docker-compose build command. My command fails, but the workflow passes anyway. Is there an explanation for that?

Here is my yaml file:

name: complete build
on: [pull_request, workflow_call]
jobs:
  lintage-checks:
    runs-on: ubuntu-22.04
    env:
      SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
    container:
      image: lucasalt/act_base:latest # Use to get the docker-compose command
    steps:
      - uses: act10ns/slack@v2
        with:
          status: starting
          message: Pull request opened successfully by ${{ github.event.pull_request.user.login }}
        if: always()
      - uses: actions/checkout@v3 # Use to copy the files from current directory
      - name: Complexity
        run: |
          docker-compose -f scripts/docker_lintage/docker-compose.yaml up --build complexity
      
      - uses: act10ns/slack@v2
        with:
          status: ${{job.status}}
          steps: ${{toJson(steps)}}
        if: always()

However, when I create a pull request, what I get in github log is the following


Creating complexity ... done
Attaching to complexity
complexity       | scripts/lintage/complexity.sh
complexity       | SCORE : 1.3333333333333333 | Acceptable score : 2
complexity       | scripts/lintage/complexity.sh: line 5: bc: command not found
complexity       | Sorry, complexity score is not acceptable." 
complexity       | make: *** [Makefile:20: test_complexity] Error 1
complexity exited with code 2

but the workflow is considered passed as you can see from the screenshot.

enter image description here

If I do not build the image but simply run the bash commands, I get the failure as I expect.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Oscar
  • 460
  • 3
  • 18
  • 3
    The _container_ may exit 2, but apparently the `docker-compose` command you're running does not pass that to the shell. – jonrsharpe Mar 07 '23 at 18:20
  • 1
    Does this answer your question? [Using docker-compose with CI - how to deal with exit codes and daemonized linked containers?](https://stackoverflow.com/questions/29568352/using-docker-compose-with-ci-how-to-deal-with-exit-codes-and-daemonized-linked) – jonrsharpe Mar 07 '23 at 18:21

1 Answers1

1

Your workflow passes because you have if: always():

Causes the step to always execute, and returns true, even when canceled. The always expression is best used at the step level or on tasks that you expect to run even when a job is canceled. For example, you can use always to send logs even when a job is canceled.

And your docker-compose is failing because one of your containers is using bc which is not found/installed which explains the EXIT code 2.

If docker-compose is not exiting when that container fails, you can add --abort-on-container-exit, or --exit-code-from (see the documentation)

Fcmam5
  • 4,888
  • 1
  • 16
  • 33
  • 1
    the if: always() refers to the slack step to send a report message even when the job fails. In any case thank you, the reason why it does not fails is because docker-compose does not transfer the status to the shell, as @jonrsharpe pointed out correctly. Thanks both of you – Oscar Mar 07 '23 at 20:57