|
12 | 12 | name: Build source distribution and wheels |
13 | 13 | uses: ./.github/workflows/build.yml |
14 | 14 | if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, ${{ vars.RELEASE_PR_BRANCH || 'create-pull-request' }}) && github.repository == 'darvid/python-hyperscan' |
| 15 | + permissions: |
| 16 | + contents: read |
| 17 | + actions: write |
15 | 18 | with: |
16 | 19 | force_build: true |
17 | 20 |
|
@@ -40,14 +43,42 @@ jobs: |
40 | 43 | - name: List artifacts |
41 | 44 | run: ls -R dist/ |
42 | 45 |
|
| 46 | + - name: Check if release is needed |
| 47 | + id: release_check |
| 48 | + run: | |
| 49 | + # Check if HEAD already has a release version tag (prevents redundant releases) |
| 50 | + if git describe --exact-match --tags HEAD --match "v*" 2>/dev/null; then |
| 51 | + EXISTING_TAG=$(git describe --exact-match --tags HEAD --match "v*" 2>/dev/null) |
| 52 | + echo "HEAD already tagged with release version $EXISTING_TAG, no release needed" |
| 53 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 54 | + else |
| 55 | + # Check if there are commits since last release |
| 56 | + LATEST_TAG=$(git describe --tags --abbrev=0 --match "v*" 2>/dev/null || echo "") |
| 57 | + if [[ -n "$LATEST_TAG" ]]; then |
| 58 | + COMMITS_COUNT=$(git rev-list ${LATEST_TAG}..HEAD --count 2>/dev/null || echo "1") |
| 59 | + if [[ "$COMMITS_COUNT" -eq 0 ]]; then |
| 60 | + echo "No commits since last release $LATEST_TAG, no new content to release" |
| 61 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 62 | + else |
| 63 | + echo "Found $COMMITS_COUNT commits since $LATEST_TAG, proceeding with release" |
| 64 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 65 | + fi |
| 66 | + else |
| 67 | + echo "No previous release found, proceeding with initial release" |
| 68 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 69 | + fi |
| 70 | + fi |
| 71 | +
|
43 | 72 | - name: Publish to GitHub Releases |
| 73 | + if: steps.release_check.outputs.should_release == 'true' |
44 | 74 | uses: python-semantic-release/publish-action@v9.21.1 |
45 | 75 | with: |
46 | 76 | inputs: ./dist |
47 | 77 | github_token: ${{ secrets.GITHUB_TOKEN }} |
48 | 78 | tag: latest |
49 | 79 |
|
50 | 80 | - name: Publish to PyPI |
| 81 | + if: steps.release_check.outputs.should_release == 'true' |
51 | 82 | uses: pypa/gh-action-pypi-publish@release/v1 |
52 | 83 | with: |
53 | 84 | skip-existing: true |
|
0 commit comments