Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"sh: 1: !: not found" in GitHub Actions

I have the following in my Github Actions YAML. It runs fine when the first check evaluates true,

    - name: Check version is up to date
      run: sh -c "
        (git diff --quiet HEAD^ VERSION && git diff --quiet HEAD^ src/**) || \
          ! git diff --quiet HEAD^ src/VERSION
        "

but when it evaluates false, the later sections gives me

sh: 1:  !: not found

only in GitHub Actions. The command starting (and including) sh -c doesn't error on my computer. I don't understand how that could be since I very explicitly mention the shell.

like image 446
joel Avatar asked Apr 23 '26 04:04

joel


1 Answers

I think this is a formatting error/quirk. If I add a new line before the command, with the | syntax, as

      run: |
        sh -c "
        (git diff --quiet HEAD^ VERSION && git diff --quiet HEAD^ src/**) || \
          ! git diff --quiet HEAD^ src/VERSION
        "

it works.

like image 177
joel Avatar answered Apr 30 '26 00:04

joel