File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,8 +10,34 @@ permissions:
1010 id-token : write
1111
1212jobs :
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
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
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
You can’t perform that action at this time.
0 commit comments