Browse Source

ci: improved tagged commit detection

Thomas Waldmann 2 days ago
parent
commit
815aa560ac
1 changed files with 10 additions and 8 deletions
  1. 10 8
      .github/workflows/ci.yml

+ 10 - 8
.github/workflows/ci.yml

@@ -84,11 +84,13 @@ jobs:
     - name: Detect if commit is tagged
       id: detect_tag
       run: |
-        if git describe --exact-match --tags HEAD >/dev/null 2>&1; then
-          echo "tagged=true" >> "$GITHUB_OUTPUT"
-        else
-          echo "tagged=false" >> "$GITHUB_OUTPUT"
+        tag="$(git describe --exact-match --tags HEAD 2>/dev/null || true)"
+        # If HEAD is a merge commit, the PR head is usually the second parent (HEAD^2).
+        if [ -z "$tag" ] && git rev-parse -q --verify HEAD^2 >/dev/null 2>&1; then
+          tag="$(git describe --exact-match --tags HEAD^2 2>/dev/null || true)"
         fi
+        echo "Found tag: ${tag}"
+        echo "tagged=$tag" >> "$GITHUB_OUTPUT"
 
     - name: Set up Python ${{ matrix.python-version }}
       uses: actions/setup-python@v5
@@ -142,14 +144,14 @@ jobs:
         env_vars: OS, python
 
     - name: Build Borg fat binaries (${{ matrix.binary }})
-      if: ${{ matrix.binary && steps.detect_tag.outputs.tagged == 'true' }}
+      if: ${{ matrix.binary && steps.detect_tag.outputs.tagged }}
       run: |
         pip install 'pyinstaller==6.14.2'
         mkdir -p dist/binary
         pyinstaller --clean --distpath=dist/binary scripts/borg.exe.spec
 
     - name: Smoke-test the built binary (${{ matrix.binary }})
-      if: ${{ matrix.binary && steps.detect_tag.outputs.tagged == 'true' }}
+      if: ${{ matrix.binary && steps.detect_tag.outputs.tagged }}
       run: |
         pushd dist/binary
         echo "single-file binary"
@@ -162,7 +164,7 @@ jobs:
         popd
 
     - name: Prepare binaries (${{ matrix.binary }})
-      if: ${{ matrix.binary && steps.detect_tag.outputs.tagged == 'true' }}
+      if: ${{ matrix.binary && steps.detect_tag.outputs.tagged }}
       run: |
         mkdir -p artifacts
         if [ -f dist/binary/borg.exe ]; then
@@ -175,7 +177,7 @@ jobs:
         ls -l artifacts/
 
     - name: Upload binaries (${{ matrix.binary }})
-      if: ${{ matrix.binary && steps.detect_tag.outputs.tagged == 'true' }}
+      if: ${{ matrix.binary && steps.detect_tag.outputs.tagged }}
       uses: actions/upload-artifact@v4
       with:
         name: ${{ matrix.binary }}