Git commands as if condition of a step in workflow #27148
-
Hello, I want to only run the ‘Commit and Push’ step if there are some changes in the repo.
But it gives error (I tried to search online whether an git command can be used as condition or not, I know it works in linux terminal but as error suggests github action does not seem to support it):
If this is not the correct way, please recommend any other option to achieve the same? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Also keep in mind that indentation is part of YAML syntax, uneven indentation like in your example might cause additional errors. |
Beta Was this translation helpful? Give feedback.
-
Hi Luna, Thanks for the approach. I tried but still getting error:
I tried many permutations and in one of those the step was actually skipped but job failed. What am I missing here? Thanks |
Beta Was this translation helpful? Give feedback.
-
Sorry, I put So the check should be:
I hope this works, at least the mixup explains why you got “nothing to commit” in the first screenshot. |
Beta Was this translation helpful? Give feedback.
-
No, dont be sorry. Programming with such things is confusing. Thanks a lot, it worked. |
Beta Was this translation helpful? Give feedback.
Sorry, I put
true
andfalse
the wrong way around in my example. According to the documentationgit diff --exit-code
will return 0 if there are no changes, and in Bash 0 means true, contrary to C… 😅So the check should be:
I hope this works, at least the mixup explains why you got “nothing to commit” in the first screenshot.