Skip to content

Commit d21f90d

Browse files
authored
ci(publish): fix release check order (#241)
1 parent eac281e commit d21f90d

1 file changed

Lines changed: 73 additions & 55 deletions

File tree

.github/workflows/publish.yml

Lines changed: 73 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,78 @@ jobs:
3434
with:
3535
fetch-depth: 0
3636

37+
- name: Check if release is needed
38+
id: release_check
39+
env:
40+
EVENT_NAME: ${{ github.event_name }}
41+
PR_MERGED: ${{ github.event.pull_request.merged }}
42+
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
43+
RELEASE_PR_BRANCH: ${{ vars.RELEASE_PR_BRANCH || 'create-pull-request/patch' }}
44+
REPOSITORY: ${{ github.repository }}
45+
run: |
46+
if [[ "${REPOSITORY}" != "darvid/python-hyperscan" ]]; then
47+
echo "Repository ${REPOSITORY} is not eligible for release automation"
48+
echo "should_release=false" >> "$GITHUB_OUTPUT"
49+
exit 0
50+
fi
51+
52+
# For workflow_dispatch, skip PR checks - just verify PyPI status
53+
if [[ "${EVENT_NAME}" != "workflow_dispatch" ]]; then
54+
if [[ "${PR_MERGED}" != "true" ]]; then
55+
echo "Pull request not merged, skipping release"
56+
echo "should_release=false" >> "$GITHUB_OUTPUT"
57+
exit 0
58+
fi
59+
60+
if [[ -n "${RELEASE_PR_BRANCH}" ]]; then
61+
case "${PR_HEAD_REF}" in
62+
"${RELEASE_PR_BRANCH}"*)
63+
;;
64+
*)
65+
echo "Head ref ${PR_HEAD_REF} does not match expected release branch prefix ${RELEASE_PR_BRANCH}"
66+
echo "should_release=false" >> "$GITHUB_OUTPUT"
67+
exit 0
68+
;;
69+
esac
70+
fi
71+
else
72+
echo "workflow_dispatch triggered - skipping PR checks"
73+
fi
74+
75+
# Get the version we're about to release
76+
CURRENT_VERSION=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
77+
TAG_NAME="v${CURRENT_VERSION}"
78+
79+
# Check if this exact version has already been published to PyPI
80+
# This is the real check - if PyPI has it, we don't need to publish again
81+
if curl -s --head "https://pypi.org/pypi/hyperscan/${CURRENT_VERSION}/json" | head -n 1 | grep -q "200"; then
82+
echo "Version ${CURRENT_VERSION} already published to PyPI, skipping release"
83+
echo "should_release=false" >> "$GITHUB_OUTPUT"
84+
exit 0
85+
fi
86+
87+
# Check if there are commits since last release (excluding the current release commit pattern)
88+
LATEST_TAG=$(git describe --tags --abbrev=0 --match "v*" 2>/dev/null || echo "")
89+
if [[ -n "$LATEST_TAG" && "$LATEST_TAG" == "$TAG_NAME" ]]; then
90+
# Tag exists but PyPI doesn't have it - this is the case where we need to publish
91+
echo "Tag ${TAG_NAME} exists but not yet on PyPI, proceeding with release"
92+
echo "should_release=true" >> "$GITHUB_OUTPUT"
93+
elif [[ -n "$LATEST_TAG" ]]; then
94+
COMMITS_COUNT=$(git rev-list "${LATEST_TAG}"..HEAD --count 2>/dev/null || echo "1")
95+
if [[ "$COMMITS_COUNT" -eq 0 ]]; then
96+
echo "No commits since last release ${LATEST_TAG}, no new content to release"
97+
echo "should_release=false" >> "$GITHUB_OUTPUT"
98+
else
99+
echo "Found ${COMMITS_COUNT} commits since ${LATEST_TAG}, proceeding with release"
100+
echo "should_release=true" >> "$GITHUB_OUTPUT"
101+
fi
102+
else
103+
echo "No previous release found, proceeding with initial release"
104+
echo "should_release=true" >> "$GITHUB_OUTPUT"
105+
fi
106+
37107
- name: Move release tag to merge commit
108+
if: steps.release_check.outputs.should_release == 'true'
38109
run: |
39110
set -euo pipefail
40111
@@ -76,69 +147,16 @@ jobs:
76147
fi
77148
78149
- name: Download artifacts
150+
if: steps.release_check.outputs.should_release == 'true'
79151
uses: actions/download-artifact@v4
80152
with:
81153
path: dist
82154
merge-multiple: true
83155

84156
- name: List artifacts
157+
if: steps.release_check.outputs.should_release == 'true'
85158
run: ls -R dist/
86159

87-
- name: Check if release is needed
88-
id: release_check
89-
env:
90-
PR_MERGED: ${{ github.event.pull_request.merged }}
91-
PR_HEAD_REF: ${{ github.event.pull_request.head.ref }}
92-
RELEASE_PR_BRANCH: ${{ vars.RELEASE_PR_BRANCH || 'create-pull-request/patch' }}
93-
REPOSITORY: ${{ github.repository }}
94-
run: |
95-
if [[ "${REPOSITORY}" != "darvid/python-hyperscan" ]]; then
96-
echo "Repository ${REPOSITORY} is not eligible for release automation"
97-
echo "should_release=false" >> "$GITHUB_OUTPUT"
98-
exit 0
99-
fi
100-
101-
if [[ "${PR_MERGED}" != "true" ]]; then
102-
echo "Pull request not merged, skipping release"
103-
echo "should_release=false" >> "$GITHUB_OUTPUT"
104-
exit 0
105-
fi
106-
107-
if [[ -n "${RELEASE_PR_BRANCH}" ]]; then
108-
case "${PR_HEAD_REF}" in
109-
"${RELEASE_PR_BRANCH}"*)
110-
;;
111-
*)
112-
echo "Head ref ${PR_HEAD_REF} does not match expected release branch prefix ${RELEASE_PR_BRANCH}"
113-
echo "should_release=false" >> "$GITHUB_OUTPUT"
114-
exit 0
115-
;;
116-
esac
117-
fi
118-
119-
# Check if HEAD already has a release version tag (prevents redundant releases)
120-
if git describe --exact-match --tags HEAD --match "v*" 2>/dev/null; then
121-
EXISTING_TAG=$(git describe --exact-match --tags HEAD --match "v*" 2>/dev/null)
122-
echo "HEAD already tagged with release version ${EXISTING_TAG}, no release needed"
123-
echo "should_release=false" >> "$GITHUB_OUTPUT"
124-
else
125-
# Check if there are commits since last release
126-
LATEST_TAG=$(git describe --tags --abbrev=0 --match "v*" 2>/dev/null || echo "")
127-
if [[ -n "$LATEST_TAG" ]]; then
128-
COMMITS_COUNT=$(git rev-list "${LATEST_TAG}"..HEAD --count 2>/dev/null || echo "1")
129-
if [[ "$COMMITS_COUNT" -eq 0 ]]; then
130-
echo "No commits since last release ${LATEST_TAG}, no new content to release"
131-
echo "should_release=false" >> "$GITHUB_OUTPUT"
132-
else
133-
echo "Found ${COMMITS_COUNT} commits since ${LATEST_TAG}, proceeding with release"
134-
echo "should_release=true" >> "$GITHUB_OUTPUT"
135-
fi
136-
else
137-
echo "No previous release found, proceeding with initial release"
138-
echo "should_release=true" >> "$GITHUB_OUTPUT"
139-
fi
140-
fi
141-
142160
- name: Install git-cliff
143161
if: steps.release_check.outputs.should_release == 'true'
144162
uses: taiki-e/install-action@v2

0 commit comments

Comments
 (0)