Skip to content

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:
push:
release:
types: published
jobs:
check-version:
name: check version
runs-on: linux
steps:
- name: Checkout
uses: actions/checkout@v3
- name: get versions
id: get
env:
RELEASE_TAG: ${{ github.ref_name }}
run: |
echo "NEW_VERSION=${RELEASE_TAG#v*}" | tee -a $GITHUB_ENV
OLD_VERISON=$(curl -s https://pypi.org/pypi/readchar/json | jq -r .info.version)
echo "OLD_VERISON=${OLD_VERISON}" | tee -a $GITHUB_ENV
- name: validate version
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 }}
commit:
name: write version and tag
runs-on: linux
needs: check-version
permissions:
contents: write
env:
VERSION: ${{ needs.check-version.outputs.version }}
steps:
- name: update pyproject.toml
run: sed -i "s/version = \".*\"$/version = \"$VERSION\"/" pyproject.toml
- name: commit version
run: git 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
# steps:
# - name: Checkout
# uses: actions/checkout@v3
# with:
# fetch-depth: 0
# - name: Set env
# run: |
# echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" | tee -a $GITHUB_ENV
# echo "BRANCH=$( \
# git branch -r --contains ${GITHUB_REF} \
# | grep -v HEAD \
# | sed -n 's/ *origin\/\(.*\)/\1/p' \
# )" | tee -a $GITHUB_ENV
# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: '3.x'
# cache: pip
# - name: Install dependencies
# run: |
# pip install build twine
# - name: get infos from Tag
# run: |
# echo "RELEASE_TAG=${RELEASE_TAG}"
# if [[ $RELEASE_TAG =~ (([0-9]+)\.([0-9]+)\.([0-9]+))([-./]dev([0-9]+))?$ ]]
# then
# echo "VERSION=${BASH_REMATCH[0]}" | tee -a $GITHUB_ENV
# echo "VERSION_MAJOR=${BASH_REMATCH[2]}" | tee -a $GITHUB_ENV
# echo "VERSION_MINOR=${BASH_REMATCH[3]}" | tee -a $GITHUB_ENV
# echo "VERSION_PATCH=${BASH_REMATCH[4]}" | tee -a $GITHUB_ENV
# echo "VERSION_DEV=${BASH_REMATCH[6]}" | tee -a $GITHUB_ENV
# else
# echo "INVALID_TAG=True" | tee -a $GITHUB_ENV
# fi
# - name: Fail on invalid Tag
# if: ${{ env.INVALID_TAG }}
# uses: actions/github-script@v6
# with:
# script: core.setFailed('Invalid Tag name used with this release!')
# - name: Write Version to pyproject.toml
# run: |
# sed -i "s/version = \".*\"$/version = \"$VERSION\"/" pyproject.toml
# - 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/*
# - name: increment development version
# if: ${{ env.VERSION_DEV }}
# run: |
# v=$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH-dev$((VERSION_DEV+1))
# sed -i "s/version = \".*\"$/version = \"$v\"/" pyproject.toml
# - name: increment patch version
# if: ${{ !env.VERSION_DEV }}
# run: |
# v=$VERSION_MAJOR.$VERSION_MINOR.$((VERSION_PATCH+1))-dev0
# sed -i "s/version = \".*\"$/version = \"$v\"/" pyproject.toml
# - name: commit new version-number
# uses: stefanzweifel/git-auto-commit-action@v4
# with:
# branch: ${{ env.BRANCH }}
# create_branch: true
# commit_message: "increment version after release"