Skip to content

v1.22.33

v1.22.33 #151

name: Publish 🐍 📦 to PyPI
on:
release:
types: [created]
jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-latest
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
contents: write # allows the post-publish step to commit the version bump back to main
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history including tags
ref: ${{ github.ref }} # Explicitly checkout the tag
- name: Set up Python 3.10.18
uses: actions/setup-python@v5
with:
python-version: 3.10.18
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build wheel "setuptools>=45,<69" twine
python -m pip list
- name: Set version from GitHub Release tag
run: |
echo "Git information:"
git tag -l
git log -1 --oneline
git describe --tags --always
# When running from a release, extract version from tag
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
# Extract clean version number from tag (removes v prefix)
VERSION=${GITHUB_REF#refs/tags/v}
echo "Running from GitHub release tag: v$VERSION"
# Set environment variables for the build
echo "VERSION=$VERSION" >> $GITHUB_ENV
# Single source of truth: bump only _version.py. setup.py reads it at
# build time and vfbquery.__init__ imports it at runtime, so the wheel
# metadata, vfbquery.__version__ and the cache version stamp all follow.
echo "Updating version in src/vfbquery/_version.py to $VERSION"
sed -i "s/__version__ = \"[^\"]*\"/__version__ = \"$VERSION\"/" src/vfbquery/_version.py
echo "Updated version:"
grep "__version__" src/vfbquery/_version.py
else
# Not running from a tag, show current version
echo "Not running from a tag, using existing version from _version.py"
grep "__version__" src/vfbquery/_version.py
fi
- name: Build distributions
run: |
echo "Building distributions..."
python -m build
# Verify the source distribution metadata
if [[ -n "$VERSION" ]]; then
echo "Checking source distribution metadata:"
SDIST_NAME_BASE="vfbquery-${VERSION}"
SDIST_FILE="dist/${SDIST_NAME_BASE}.tar.gz"
PKG_INFO_PATH="${SDIST_NAME_BASE}/PKG-INFO"
echo "Extracting Version from PKG-INFO in ${SDIST_FILE} (path: ${PKG_INFO_PATH})"
tar -zxf "${SDIST_FILE}" -O "${PKG_INFO_PATH}" | grep "^Version:"
# Verify the wheel metadata
WHEEL_NAME="vfbquery-${VERSION}-py3-none-any.whl"
WHEEL_FILE="dist/${WHEEL_NAME}"
DIST_INFO_PATH="vfbquery-${VERSION}.dist-info/METADATA"
echo "Extracting Version from ${DIST_INFO_PATH} in ${WHEEL_FILE}"
unzip -p "${WHEEL_FILE}" "${DIST_INFO_PATH}" | grep "^Version:"
fi
- name: Verify metadata with twine
run: |
python -m twine check dist/*
- name: Install and verify wheel version
run: |
# Install the wheel
python -m pip install dist/*.whl
# Verify the installed version matches the expected version
if [[ -n "$VERSION" ]]; then
INSTALLED_VERSION=$(python -c "import vfbquery; print(getattr(vfbquery, '__version__', 'unknown'))" 2>/dev/null || echo "unknown")
echo "Expected version: $VERSION"
echo "Installed version: $INSTALLED_VERSION"
if [[ "$VERSION" != "$INSTALLED_VERSION" ]] && [[ "$INSTALLED_VERSION" != "unknown" ]]; then
echo "WARNING: Version mismatch detected, but proceeding with build"
fi
echo "Version verification completed"
else
echo "No explicit version set, skipping version verification"
python -c "import vfbquery; print(f'Package installed successfully')" 2>/dev/null || echo "Package verification completed"
fi
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@v1.12.2
- name: Commit version bump back to main
# Runs only after a successful publish from a release tag. The build above
# runs from a detached tag checkout, so here we switch to the live main
# branch, re-apply the released version to the single source file
# (_version.py) and push. [skip ci] keeps this housekeeping commit from
# retriggering the test/perf workflows.
if: success() && startsWith(github.ref, 'refs/tags/v')
run: |
set -e
if [[ -z "$VERSION" ]]; then
echo "VERSION not set; nothing to commit."
exit 0
fi
git config user.email "action@github.com"
git config user.name "GitHub Action"
git fetch origin main
git reset --hard origin/main
sed -i "s/__version__ = \"[^\"]*\"/__version__ = \"$VERSION\"/" src/vfbquery/_version.py
git add src/vfbquery/_version.py
if git diff --staged --quiet; then
echo "main already at version $VERSION; nothing to commit."
else
git commit -m "Bump version to $VERSION [skip ci]"
git push origin HEAD:main
fi
# - name: Publish package to TestPyPI
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
# repository_url: https://test.pypi.org/legacy/