From 2ac3af7a53327f55bf1dbe90649e83301e6c0615 Mon Sep 17 00:00:00 2001 From: Julian Mutter Date: Sat, 22 Mar 2025 08:42:55 +0100 Subject: [PATCH] workflow: first check if merge is necessary --- .gitea/workflows/update-flake.yaml | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/update-flake.yaml b/.gitea/workflows/update-flake.yaml index bfc6059..06f4c6e 100644 --- a/.gitea/workflows/update-flake.yaml +++ b/.gitea/workflows/update-flake.yaml @@ -23,11 +23,26 @@ jobs: git config user.email "actions@gitea.local" - name: Merge main branch + shell: bash run: | - git merge --squash origin/main - # solve merge conflict by taking flake.lock from main - git checkout origin/main -- flake.lock - git commit -m "Merge main branch squashed $(date -I)" + commits_ahead=$(git rev-list --count HEAD..origin/main) + echo "Commits ahead: $commits_ahead" + git log --oneline -5 + echo "----------" + git log --oneline -5 origin/main + + if [ $commits_ahead -ne 0 ] + then + git fetch origin + git merge --squash origin/main + git push --force-with-lease + + # solve potential merge conflict by taking flake.lock from main + git checkout origin/main -- flake.lock + git commit -m "Merge main branch squashed $(date -I)" + else + echo "Merge not necessary" + fi - name: Set up Nix uses: cachix/install-nix-action@v31 @@ -39,7 +54,7 @@ jobs: shell: bash run: | git add flake.lock - if git diff --cached --quiet; then + if git diff --quiet; then echo "No changes to commit." else git commit -m "Update flake.lock $(date -I)"