Fix the update.sh workflow action to handle no changes
authorPablo Zmdl <redacted>
Thu, 5 Dec 2024 15:45:49 +0000 (16:45 +0100)
committerPablo Zmdl <redacted>
Thu, 5 Dec 2024 15:45:49 +0000 (16:45 +0100)
Previously the branch was created and pushed no matter if changes were
committed, which made subsequent runs fail. This is fixed by using
distinctly named branches, and by exiting early if no changes are to be
committed.

.github/workflows/update-sh.yml

index be8810db42781e9811cd4001536d219cc992f407..a8c6ff3e9f1019ff55448e64973a5e96c91560a4 100644 (file)
@@ -24,16 +24,17 @@ jobs:
     - name: Run update.sh script
       run: ./update.sh
     - name: Commit files
+      env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
       run: |
-        BRANCH="changes-from-update.sh-$(date +'%Y-%m-%d')"
-        git show-ref --quiet "$BRANCH" && { "ERROR: Branch $BRANCH already exists";  exit 1; }
+        # Exit early if no changes are present.
+        test $(git status --porcelain | wc -l) -gt 0 || { echo "No changes to commit, happily cancelling this script."; exit 0; }
+        # Use a distinct branch-name (nano-seconds should be good enough).
+        BRANCH="changes-from-update.sh-$(date -I ns)"
         git switch -C "$BRANCH"
         git config --local user.email "workflow@github.com"
         git config --local user.name "GitHub Workflow"
         git add -A
-        git commit -m "Update roundcube version (via update.sh)" || echo "Nothing to update"
+        git commit -m "Update roundcube version (via update.sh)"
         git push --set-upstream origin "$BRANCH"
-    - name: Create Pull Request
-      run: gh pr create -B master -H changes-from-update.sh --title 'Changes from update.sh' --body "These are the changes of the automated run of ./update.sh" --assignee pabzm
-      env:
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        gh pr create -B master -H changes-from-update.sh --title 'Changes from update.sh' --body "These are the changes of the automated run of ./update.sh" --assignee pabzm
git clone https://git.99rst.org/PROJECT