Skip to content

How to trigger a GitHub action only when the response of a script is different and it changes a particular file #24919

Discussion options

You must be logged in to vote

Close, but you can’t use a shell command directly in the if condition. You’ll have to use an extra step to set an output or environment variable, e.g.:

- name: Check diff
  run: |
    if git diff --exit-code; then
        echo "CHANGED=false" >>${GITHUB_ENV}
    else
        echo "CHANGED=true" >>${GITHUB_ENV}
    fi
  • name: Create pull request
    if: env.CHANGED == 'true'

    ...

Replies: 8 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants