Error due exit code 1 in bash command

I need to compare some version numbers and I’m using dpkg --compare-versions

run: |
        dpkg --compare-versions "${{matrix.kernel_version}}" "ge" "5.17"
        if [ $? -eq "0" ];

When the versions are greater of equal to 5.17 is working fine, but when is lower, it returns exit code 1 and the next line (that evaluate $?) is ignored.

What is the correct way to evaluate the exit code of one shell command inside “run:”?

By default the shell in run steps runs with set -e, so it terminates as soon as any command returns an error (AKA a non-zero exit code).

Put the command directly into the if condition instead of relying on $?, like so:

run: |
  if dpkg --compare-versions "${{matrix.kernel_version}}" "ge" "5.17"; then
      # things to do if the dpkg call returns 0
      # things to do otherwise

That way a possible non-zero exit code is handled by the if and doesn’t make the shell exit. :slightly_smiling_face:


Thanks @airtower-luna
Your hint about “-e” was the key.
I have solved the issue with
shell: bash {0}