vmactions / freebsd-vm

Use FreeBSD in github actions
https://vmactions.org
MIT License
243 stars 20 forks source link

Raise error on command failure #72

Open animetosho opened 1 year ago

animetosho commented 1 year ago

Firstly, thanks for building this action!

Is there any way to cause the action to fail if a command in run fails?
This would be useful for identifying test failures; currently everything seems to pass, even if something actually failed.

Jihadist commented 1 year ago

Hi @Neilpang, sorry for ping. Is there any solution for this issue?

daniel-mohr commented 9 months ago

I'm not a developer here. But I can share my solution:

...
  freebsd_test:
    runs-on: ubuntu-22.04
    name: run tests on FreeBSD
    steps:
    - uses: actions/checkout@v4
    - name: Test in FreeBSD
      id: test
      uses: vmactions/freebsd-vm@v1
      with:
        usesh: true
        run: |
          set -e -x
...

The flag usesh: true is documented in the README.md as The default shell in FreeBSD is csh, if you want to use sh to execute the run script, please set usesh to true.. This way you can use the posix set command or a similar command (I believe set from sh -- see section Argument List Processing). With the flag -e you get your desired behavior 'exit immediately on fail'. The -x flag is not necessary, but it will cause an echo of each command immediately before execution -- this helps to find out at which command an error occurred.