From d5df1316f839cec25ecda0972ab48e8dd60aef95 Mon Sep 17 00:00:00 2001 From: Jack Jackson Date: Tue, 22 Nov 2022 11:43:31 -0800 Subject: [PATCH] Do nothing if there is nothing to do! This isn't just an efficiency/neatness change - if you try to `git commit` when there's nothing to commit, the command will return `1` which will be parsed as an error, and thus the whole build will be categorized as a failure. --- script.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/script.sh b/script.sh index 65f70a5..cbcc779 100644 --- a/script.sh +++ b/script.sh @@ -12,11 +12,15 @@ mkdir /working cd /working git clone -b "$PLUGIN_BRANCH" "$PLUGIN_GIT_REPO" . echo "$PLUGIN_IMAGE_TAG" > "$PLUGIN_DESTINATION_FILE" +if [ "$(git status --porcelain | wc -l)" -eq 0 ]; then + echo "Nothing has changed in this repo. Nothing to do" + return +fi git add "$PLUGIN_DESTINATION_FILE" git config user.email "$PLUGIN_AUTHOR_EMAIL" git config user.name "$PLUGIN_AUTHOR_NAME" # https://stackoverflow.com/a/31926346/1040915 -git commit -m "$(echo $PLUGIN_COMMIT_MESSAGE | envsubst)" +git commit -m '$(echo "$PLUGIN_COMMIT_MESSAGE" | envsubst)' # https://stackoverflow.com/a/6174447/1040915 git remote add origin-with-credentials "$(echo $PLUGIN_GIT_REPO | sed -e's,^\(.*://\).*,\1,g')""$PLUGIN_ACCESS_TOKEN@""$(echo $PLUGIN_GIT_REPO | sed -e's,^.*://\(.*\),\1,g')" git push origin-with-credentials "$PLUGIN_BRANCH":"$PLUGIN_BRANCH"