Skip to content

Commit 57ce4d4

Browse files
committed
workflows: auto publish to pypi for every release
the new workflow changes the sourcecode to actually contain the correct verison number befor building the distros. This ensures clean metadata. The workflow also auto-increments the version number and commits the new version to the repo. This means that the repos version is alway the next developmentversion from the most recent release.
1 parent 8146750 commit 57ce4d4

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

.github/workflows/publish.yml

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
2-
# This workflow will upload a Python Package using Twine when a release is
3-
# created
2+
# This workflow will upload a Python Package using Twine
43
# For more information see:
54
# https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries
65

@@ -10,25 +9,67 @@ on:
109
release:
1110
types: [created]
1211

12+
1313
jobs:
14-
deploy:
1514

15+
deploy:
1616
runs-on: ubuntu-latest
1717

1818
steps:
19-
- uses: actions/checkout@v2
19+
- name: Checkout
20+
uses: actions/checkout@v3
21+
with:
22+
ref: master
2023
- name: Set up Python
21-
uses: actions/setup-python@v2
24+
uses: actions/setup-python@v4
2225
with:
23-
python-version: 3.x
26+
python-version: '3.x'
27+
cache: pip
2428
- name: Install dependencies
2529
run: |
26-
python -m pip install --upgrade pip
2730
pip install setuptools wheel twine
28-
- name: Build and publish
31+
- name: get infos from Tag
32+
run: |
33+
if [[ $GITHUB_REF =~ (([0-9]+)\.([0-9]+)\.([0-9]+))([-./]dev([0-9]+))? ]]
34+
then
35+
echo "VERSION=${BASH_REMATCH[0]}" >> $GITHUB_ENV
36+
echo "VERSION_MAJOR=${BASH_REMATCH[2]}" >> $GITHUB_ENV
37+
echo "VERSION_MINOR=${BASH_REMATCH[3]}" >> $GITHUB_ENV
38+
echo "VERSION_PATCH=${BASH_REMATCH[4]}" >> $GITHUB_ENV
39+
echo "VERSION_DEV=${BASH_REMATCH[6]}" >> $GITHUB_ENV
40+
else
41+
echo "INVALID_TAG=True" >> $GITHUB_ENV
42+
fi
43+
- name: Fail on invalid Tag
44+
if: ${{ env.INVALID_TAG }}
45+
uses: actions/github-script@v6
46+
with:
47+
script: core.setFailed('Invalid Tag name used with this release!')
48+
49+
- name: Write Version to __init__
50+
run: |
51+
sed -i "s/__version__ = .*/__version__ = '$VERSION'/" readchar/__init__.py
52+
- name: Build sdist and bdist_wheel
53+
run: |
54+
python setup.py sdist bdist_wheel
55+
- name: publish to PyPi
2956
env:
3057
TWINE_USERNAME: __token__
3158
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
3259
run: |
33-
python setup.py sdist bdist_wheel
3460
twine upload dist/*
61+
62+
- name: increment development version
63+
if: ${{ env.VERSION_DEV }}
64+
run: |
65+
v=$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH-dev$((VERSION_DEV+1))
66+
sed -i "s/__version__ = .*/__version__ = \"$v\"/" readchar/__init__.py
67+
- name: increment patch version
68+
if: ${{ !env.VERSION_DEV }}
69+
run: |
70+
v=$VERSION_MAJOR.$VERSION_MINOR.$((VERSION_PATCH+1))-dev0
71+
sed -i "s/__version__ = .*/__version__ = \"$v\"/" readchar/__init__.py
72+
- name: commit new version-number
73+
uses: stefanzweifel/git-auto-commit-action@v4
74+
with:
75+
commit_message: "increment version after release"

.yamllint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ ignore: |
66
rules:
77
indentation:
88
spaces: 2
9+
line-length:
10+
max: 120
911
new-lines:
1012
type: platform

0 commit comments

Comments
 (0)