Skip to content

Commit c1d2372

Browse files
committed
ci: guard publish; only run on tags that point to main
1 parent febbee1 commit c1d2372

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

.github/workflows/publish.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,34 @@ permissions:
1010
id-token: write
1111

1212
jobs:
13+
guard:
14+
name: Guard (tag points to main?)
15+
runs-on: ubuntu-latest
16+
outputs:
17+
publish: ${{ steps.check.outputs.publish }}
18+
steps:
19+
- name: Checkout (shallow)
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
- name: Check if tag commit is on main
24+
id: check
25+
env:
26+
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
27+
run: |
28+
git fetch origin $DEFAULT_BRANCH --depth=1
29+
if git merge-base --is-ancestor "$GITHUB_SHA" "origin/$DEFAULT_BRANCH"; then
30+
echo "publish=true" >> "$GITHUB_OUTPUT"
31+
echo "Tag commit is on $DEFAULT_BRANCH; will publish."
32+
else
33+
echo "publish=false" >> "$GITHUB_OUTPUT"
34+
echo "Tag commit is NOT on $DEFAULT_BRANCH; skipping publish."
35+
fi
36+
1337
build-wheels:
1438
name: Build native wheels
39+
needs: guard
40+
if: needs.guard.outputs.publish == 'true'
1541
continue-on-error: ${{ matrix.allow-failure == true }}
1642
strategy:
1743
fail-fast: false
@@ -61,6 +87,8 @@ jobs:
6187

6288
build-sdist:
6389
name: Build sdist
90+
needs: guard
91+
if: needs.guard.outputs.publish == 'true'
6492
runs-on: ubuntu-latest
6593
steps:
6694
- name: Checkout repository
@@ -91,7 +119,8 @@ jobs:
91119

92120
publish:
93121
name: Publish to PyPI (Trusted Publishing)
94-
needs: [build-wheels, build-sdist]
122+
needs: [guard, build-wheels, build-sdist]
123+
if: needs.guard.outputs.publish == 'true'
95124
runs-on: ubuntu-latest
96125
steps:
97126
- name: Download all artifacts

0 commit comments

Comments
 (0)