Skip to content

1.0.4

1.0.4 #12

Workflow file for this run

# This workflow will upload a Python package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
name: Upload Python Package
on:
release:
types: [published]
jobs:
details:
runs-on: ubuntu-latest
outputs:
new_version: ${{ steps.release.outputs.new_version }}
suffix: ${{ steps.release.outputs.suffix }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
- uses: actions/checkout@v3
- name: Extract tag and Details
id: release
run: |
if [ "${{ github.ref_type }}" = "tag" ]; then
TAG_NAME=${GITHUB_REF#refs/tags/}
NEW_VERSION=$(echo $TAG_NAME | awk -F'-' '{print $1}')
SUFFIX=$(echo $TAG_NAME | grep -oP '[a-z]+[0-9]+' || echo "")
echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
echo "suffix=$SUFFIX" >> "$GITHUB_OUTPUT"
echo "tag_name=$TAG_NAME" >> "$GITHUB_OUTPUT"
echo "Version is $NEW_VERSION"
echo "Suffix is $SUFFIX"
echo "Tag name is $TAG_NAME"
else
echo "No tag found"
exit 1
fi
check_pypi:
needs: details
runs-on: ubuntu-latest
steps:
- name: Fetch information from PyPI
run: |
response=$(curl -s https://pypi.org/pypi/kapital/json || echo "{}")
latest_version=$(echo "$response" | grep -oP '"version": *"\K[^"]+')
if [ -z "$latest_version" ]; then
echo "Package not found on PyPI."
latest_version="0.0.0"
fi
echo "Latest version on PyPI: $latest_version"
echo "latest_version=$latest_version" >> $GITHUB_ENV
- name: Compare versions and exit if not newer
run: |
NEW_VERSION=${{ needs.details.outputs.new_version }}
LATEST_VERSION=$latest_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
deploy:
needs: [details, check_pypi]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Update VERSION file with the new version
run: |
NEW_VERSION=${{ needs.details.outputs.new_version }}
echo "$NEW_VERSION" > VERSION
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install twine setuptools wheel
- name: Build package
run: |
python setup.py sdist bdist_wheel
- name: Upload to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload dist/*
- name: Save dist files as artifact
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
update_release:
name: Update GithHub Release with Dist files
needs: [deploy, details]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: Upload artifacts to release
env:
GH_TOKEN: ${{ secrets.GIT_TOKEN }}
run: |
TAG_NAME=${{ needs.details.outputs.tag_name }}
gh release upload "$TAG_NAME" dist/* --clobber