github-actions

"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.


Solution

  • 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.