Skip to content

Commit

Permalink
Refactor GitHub Actions workflow for PyPI publishing: improve version…
Browse files Browse the repository at this point in the history
… comparison logic and remove Python 3.13 support
  • Loading branch information
fox-techniques committed Jan 10, 2025
1 parent 59d82f1 commit 07ca8de
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,28 @@ jobs:
run: |
response=$(curl -s https://pypi.org/pypi/${{ env.PACKAGE_NAME }}/json || echo "{}")
latest_previous_version=$(echo "$response" | jq -r '.releases | keys_unsorted | sort | .[-1]' || echo "0.0.0")
if [ -z "$latest_previous_version" ] || [ "$latest_previous_version" == "null" ]; then
if [ "$latest_previous_version" == "null" ] || [ -z "$latest_previous_version" ]; then
latest_previous_version="0.0.0"
fi
echo "latest_previous_version=$latest_previous_version" >> $GITHUB_ENV
- name: Compare Versions
run: |
NEW_VERSION=${{ steps.extract_tag.outputs.new_version }}
LATEST_VERSION=$latest_previous_version
if [ "$(printf '%s\n' "$LATEST_VERSION" "$NEW_VERSION" | sort -rV | head -n 1)" != "$NEW_VERSION" ] || [ "$NEW_VERSION" == "$LATEST_VERSION" ]; then
echo "The new version $NEW_VERSION is not greater than the latest version $LATEST_VERSION on PyPI."
exit 1
else
echo "The new version $NEW_VERSION is greater than the latest version $LATEST_VERSION on PyPI."
fi
python -c "
from packaging.version import parse
new_version = parse('${{ steps.extract_tag.outputs.new_version }}')
latest_version = parse('${{ env.latest_previous_version }}')
if not new_version > latest_version:
raise ValueError(f'New version {new_version} is not greater than latest {latest_version}')
"
test_backward_compatibility:
name: Test Backward Compatibility
needs: details
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4

Expand All @@ -84,15 +83,17 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Ensure Python Dependencies
run: |
sudo apt-get update
sudo apt-get install -y python3-venv python3-pip
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH
export PATH="$HOME/.local/bin:$PATH"
poetry --version
- name: Set Project Version
run: poetry version ${{ needs.details.outputs.new_version }}
Expand All @@ -103,6 +104,13 @@ jobs:
- name: Build Distribution
run: poetry build

- name: Verify Build Artifacts
run: |
if [ ! -d "dist/" ]; then
echo "Distribution artifacts are missing."
exit 1
fi
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
Expand Down

0 comments on commit 07ca8de

Please sign in to comment.