Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,46 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # to get tags

- name: Pre-flight checks
id: tag
run: |
fail() {
{
echo "## Release pre-flight FAILED"
echo ""
echo "**Reason:** $1"
} >> "$GITHUB_STEP_SUMMARY"
echo "::error::$1"
exit 1
}

if [ "${GITHUB_REF}" != "refs/heads/main" ]; then
fail "Workflow must be dispatched from 'main' (got '${GITHUB_REF}')."
fi

TAG=$(git tag --points-at HEAD | grep '^v' | sort -V | tail -n1)
if [ -z "$TAG" ]; then
fail "main HEAD ($(git rev-parse --short HEAD)) has no version tag (vX.Y.Z)."
fi

VERSION="${TAG#v}"
STATUS=$(curl -sS -o /dev/null -w "%{http_code}" "https://pypi.org/pypi/dhapi/${VERSION}/json")
case "$STATUS" in
404) ;;
200) fail "dhapi==${VERSION} is already published on PyPI." ;;
*) fail "Unexpected PyPI response: HTTP ${STATUS} when querying dhapi==${VERSION}." ;;
esac

echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
{
echo "## Release pre-flight OK"
echo ""
echo "- tag: \`$TAG\`"
echo "- version: \`$VERSION\`"
} >> "$GITHUB_STEP_SUMMARY"

- uses: actions/setup-python@v5
with:
python-version: '3.10'
Expand Down
Loading