11name : publish-pypi
22
33on :
4+ release :
5+ types :
6+ - published
47 workflow_dispatch :
58 inputs :
69 upload :
@@ -22,19 +25,33 @@ jobs:
2225
2326 - name : Check package version
2427 run : |
25- # Ensure the version in pyproject.toml is equivalent to the latest git tag
28+ set -euo pipefail
29+
30+ # Ensure the version in pyproject.toml matches the release tag being
31+ # published. For manual runs, fall back to the latest published
32+ # release tag.
2633 # Read version from pyproject.toml
2734 PACKAGE_VERSION=$(python -c "import tomllib; f = open('pyproject.toml', 'rb'); data = tomllib.load(f); f.close(); print(data['project']['version'])")
2835 echo "Package version: $PACKAGE_VERSION"
2936
30- # Go to github releases to get latest tag
31- LATEST_TAG=$(curl -s https://api.github.com/repos/httpdss/structkit/releases/latest | grep 'tag_name' | cut -d\" -f4)
32- # Remove leading 'v' if present
33- LATEST_TAG=${LATEST_TAG#v}
34- echo "Latest tag: $LATEST_TAG"
37+ if [ "${GITHUB_EVENT_NAME}" = "release" ]; then
38+ RELEASE_TAG="${GITHUB_REF_NAME}"
39+ else
40+ RELEASE_TAG=$(python - <<'PY'
41+ import json
42+ import urllib.request
43+
44+ with urllib.request.urlopen("https://api.github.com/repos/httpdss/structkit/releases/latest") as response:
45+ print(json.load(response)["tag_name"])
46+ PY
47+ )
48+ fi
49+
50+ RELEASE_VERSION=${RELEASE_TAG#v}
51+ echo "Release version: $RELEASE_VERSION"
3552
36- if [ "$PACKAGE_VERSION" != "$LATEST_TAG " ]; then
37- echo "Error: Package version ($PACKAGE_VERSION) does not match latest git tag ($LATEST_TAG )"
53+ if [ "$PACKAGE_VERSION" != "$RELEASE_VERSION " ]; then
54+ echo "Error: Package version ($PACKAGE_VERSION) does not match release version ($RELEASE_VERSION )"
3855 exit 1
3956 fi
4057
0 commit comments