Merge pull request #2166 from networkupstools/jimklimov-patch-1 #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish PyNUT client bindings for NUT 🐍 distributions 📦 to PyPI | |
# based on https://medium.com/@VersuS_/automate-pypi-releases-with-github-actions-4c5a9cfe947d | |
# and https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ | |
on: | |
push: | |
tags: | |
- '*' | |
branches: | |
- 'master' | |
permissions: | |
id-token: write | |
jobs: | |
build-n-publish: | |
if: github.repository_owner == 'networkupstools' | |
name: Build and publish Python 🐍 distributions 📦 to PyPI | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@master | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v3 | |
with: | |
python-version: '3.10' | |
- name: Install pypa/setuptools | |
run: >- | |
python -m | |
pip install wheel build | |
- name: Extract tag name | |
id: tag | |
# Note: this is all a single shell line in the end, | |
# so we need semicolons between commands! | |
run: >- | |
TAG_NAME="$(echo $GITHUB_REF | cut -d / -f 3)" ; | |
if [ x"$TAG_NAME" = xmaster ]; then | |
TAG_NAME="$(git describe --tags --match 'v[0-9]*.[0-9]*.[0-9]' --exclude '*-signed' --exclude '*rc*' --exclude '*alpha*' --exclude '*beta*' 2>/dev/null || git describe --tags --exclude '*rc*' --exclude '*alpha*' --exclude '*beta*' --exclude '*Windows*' --exclude '*IPM*' 2>/dev/null ) | sed -e 's/^v\([0-9]\)/\1/' -e 's,^.*/,,')" \ | |
&& test -n "${TAG_NAME}" \ | |
|| TAG_NAME="2.8.1-`TZ=UTC date +%s`" ; | |
fi ; | |
TAG_NAME="$(echo "$TAG_NAME" | sed -e 's/^v//' -e 's/-g.*$//' -e 's/-/./g')" ; | |
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_OUTPUT | |
- name: Update version in setup.py | |
run: >- | |
if [ ! -s scripts/python/module/setup.py ] ; then | |
sed -e "s/@NUT_SOURCE_GITREV_NUMERIC@/${{ steps.tag.outputs.TAG_NAME }}/g" < scripts/python/module/setup.py.in > scripts/python/module/setup.py ; | |
fi | |
- name: Prepare source layout | |
run: >- | |
set -e ; | |
cd scripts/python/module ; | |
mkdir src ; | |
for F in *.py.in ; do sed -e "s,@PYTHON@,$(command -v python)," < "$F" > "src/`basename "$F" .in`" ; done ; | |
cp README.adoc README.txt ; | |
chmod +x src/test*.py ; | |
- name: Build a binary wheel | |
run: >- | |
cd scripts/python/module ; | |
python -m build --skip-dependency-check --no-isolation | |
|| { rm -rf build dist *egg* ; python setup.py sdist bdist_wheel ; } | |
|| { rm -rf build dist *egg* ; python -m pip wheel . -w dist --no-deps ; } ; | |
find . -ls | |
- name: Publish master distribution 📦 to Test PyPI | |
# https://github.com/pypa/gh-action-pypi-publish | |
if: ${{ !startsWith(github.ref, 'refs/tags') }} | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
packages-dir: scripts/python/module/dist | |
password: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
repository-url: https://test.pypi.org/legacy/ | |
- name: Publish tagged release distribution 📦 to PyPI | |
if: startsWith(github.ref, 'refs/tags') | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
packages-dir: scripts/python/module/dist | |
password: ${{ secrets.PYPI_API_TOKEN }} |