Skip to content

v4.2.1

v4.2.1 #22

Workflow file for this run

---
# This workflow will upload a Python Package using Twine
# 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:
check-version: # --------------------------------------------------------------------
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: get versions
id: get
run: |
echo "NEW_VERSION=$(echo '${{ github.ref_name }}' | cut -c2-)" | tee -a $GITHUB_OUTPUT
echo "OLD_VERSION=$(curl -s https://pypi.org/pypi/readchar/json |jq -r .info.version)" | tee -a $GITHUB_OUTPUT
- name: validate version
id: valid
shell: python
run: |
from sys import exit
from packaging import version
new_version = version.parse("${{ steps.get.outputs.NEW_VERSION }}")
old_version = version.parse("${{ steps.get.outputs.OLD_VERSION }}")
if not new_version > old_version:
print(f"::error::New version '{new_version}' not greatet than '{old_version}'")
exit(1)
outputs:
version: ${{ steps.get.outputs.NEW_VERSION }}
tag: # ------------------------------------------------------------------------------
runs-on: ubuntu-latest
needs: check-version
permissions:
contents: write
env:
VERSION: ${{ needs.check-version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: update pyproject.toml
run: sed -i -r "s/^(version = ).*$/\1\"$VERSION\"/" pyproject.toml
- name: commit version
env:
USER: github-actions[bot]
EMAIL: github-actions[bot]@users.noreply.github.com
run: git -c user.name="$USER" -c user.email="$EMAIL" commit --all -m "release v$VERSION"
- name: update tag
run: git tag -f "v$VERSION"
- name: push updates
run: git push --tags -f
deploy: # ---------------------------------------------------------------------------
runs-on: ubuntu-latest
needs: tag
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
cache: pip
- name: Install dependencies
run: pip install build twine
- name: Build sdist and bdist_wheel
run: python -m build
- name: publish to PyPi
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload dist/*
increment: # ------------------------------------------------------------------------
runs-on: ubuntu-latest
needs: deploy
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 3
- name: get versions
id: get
shell: python
run: |
from sys import exit
from os import environ
from packaging import version
ver = version.parse("${{ github.ref_name }}")
if ver.dev is not None:
new_ver = f"{ver.base_version}-dev{ver.dev +1}"
else:
new_ver = f"{ver.major}.{ver.minor}.{ver.micro +1}-dev0"
with open(environ.get("GITHUB_OUTPUT"), "a") as fp:
towrite = f"NEW_VERSION={new_ver}"
print(towrite)
fp.write(towrite + "\n")
- name: update pyproject.toml
env:
VERSION: ${{ steps.get.outputs.NEW_VERSION }}
run: sed -i -r "s/^(version = ).*$/\1\"$VERSION\"/" pyproject.toml
- name: commit version
env:
USER: github-actions[bot]
EMAIL: github-actions[bot]@users.noreply.github.com
run: git -c user.name="$USER" -c user.email="$EMAIL" commit --all -m "increment version after release"
- name: push updates
run: |
git fetch origin 'refs/heads/*:refs/remotes/origin/*'
git push origin "HEAD:$(git log --pretty='%D' | grep -oPm1 '(?<=origin/).*')"