@@ -7,80 +7,133 @@ name: Upload Python Package
77
88on :
99 release :
10- types : [created]
10+ types : published
1111
1212
1313jobs :
1414
15- deploy :
15+ check-version : # --------------------------------------------------------------------
1616 runs-on : ubuntu-latest
17+ steps :
18+ - name : Checkout
19+ uses : actions/checkout@v4
20+
21+ - name : get versions
22+ id : get
23+ run : |
24+ echo "NEW_VERSION=$(echo '${{ github.ref_name }}' | cut -c2-)" | tee -a $GITHUB_OUTPUT
25+ echo "OLD_VERSION=$(curl -s https://pypi.org/pypi/readchar/json |jq -r .info.version)" | tee -a $GITHUB_OUTPUT
26+
27+ - name : validate version
28+ id : valid
29+ shell : python
30+ run : |
31+ from sys import exit
32+ from packaging import version
33+ new_version = version.parse("${{ steps.get.outputs.NEW_VERSION }}")
34+ old_version = version.parse("${{ steps.get.outputs.OLD_VERSION }}")
35+ if not new_version > old_version:
36+ print(f"::error::New version '{new_version}' not greatet than '{old_version}'")
37+ exit(1)
1738
39+ outputs :
40+ version : ${{ steps.get.outputs.NEW_VERSION }}
41+
42+
43+ tag : # ------------------------------------------------------------------------------
44+ runs-on : ubuntu-latest
45+ needs : check-version
46+ permissions :
47+ contents : write
48+ env :
49+ VERSION : ${{ needs.check-version.outputs.version }}
1850 steps :
1951 - name : Checkout
20- uses : actions/checkout@v3
52+ uses : actions/checkout@v4
53+
54+ - name : update pyproject.toml
55+ run : sed -i -r "s/^(version = ).*$/\1\"$VERSION\"/" pyproject.toml
56+
57+ - name : commit version
58+ env :
59+ USER : github-actions[bot]
60+ EMAIL : github-actions[bot]@users.noreply.github.com
61+ run : git -c user.name="$USER" -c user.email="$EMAIL" commit --all -m "release v$VERSION"
62+
63+ - name : update tag
64+ run : git tag -f "v$VERSION"
65+
66+ - name : push updates
67+ run : git push --tags -f
68+
69+
70+ deploy : # ---------------------------------------------------------------------------
71+ runs-on : ubuntu-latest
72+ needs : tag
73+ steps :
74+ - name : Checkout
75+ uses : actions/checkout@v4
2176 with :
22- fetch-depth : 0
23- - name : Set env
24- run : |
25- echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" | tee -a $GITHUB_ENV
26- echo "BRANCH=$( \
27- git branch -r --contains ${GITHUB_REF} \
28- | grep -v HEAD \
29- | sed -n 's/ *origin\/\(.*\)/\1/p' \
30- )" | tee -a $GITHUB_ENV
77+ ref : ${{ github.ref }}
78+
3179 - name : Set up Python
32- uses : actions/setup-python@v4
80+ uses : actions/setup-python@v5
3381 with :
3482 python-version : ' 3.x'
3583 cache : pip
84+
3685 - name : Install dependencies
37- run : |
38- pip install build twine
39- - name : get infos from Tag
40- run : |
41- echo "RELEASE_TAG=${RELEASE_TAG}"
42- if [[ $RELEASE_TAG =~ (([0-9]+)\.([0-9]+)\.([0-9]+))([-./]dev([0-9]+))?$ ]]
43- then
44- echo "VERSION=${BASH_REMATCH[0]}" | tee -a $GITHUB_ENV
45- echo "VERSION_MAJOR=${BASH_REMATCH[2]}" | tee -a $GITHUB_ENV
46- echo "VERSION_MINOR=${BASH_REMATCH[3]}" | tee -a $GITHUB_ENV
47- echo "VERSION_PATCH=${BASH_REMATCH[4]}" | tee -a $GITHUB_ENV
48- echo "VERSION_DEV=${BASH_REMATCH[6]}" | tee -a $GITHUB_ENV
49- else
50- echo "INVALID_TAG=True" | tee -a $GITHUB_ENV
51- fi
52- - name : Fail on invalid Tag
53- if : ${{ env.INVALID_TAG }}
54- uses : actions/github-script@v6
55- with :
56- script : core.setFailed('Invalid Tag name used with this release!')
86+ run : pip install build twine
5787
58- - name : Write Version to pyproject.toml
59- run : |
60- sed -i "s/version = \".*\"$/version = \"$VERSION\"/" pyproject.toml
6188 - name : Build sdist and bdist_wheel
62- run : |
63- python -m build
89+ run : python -m build
90+
6491 - name : publish to PyPi
6592 env :
6693 TWINE_USERNAME : __token__
6794 TWINE_PASSWORD : ${{ secrets.PYPI_API_TOKEN }}
68- run : |
69- twine upload dist/*
95+ run : twine upload dist/*
96+
97+
98+ increment : # ------------------------------------------------------------------------
99+ runs-on : ubuntu-latest
100+ needs : deploy
101+ steps :
102+ - name : Checkout
103+ uses : actions/checkout@v4
104+ with :
105+ ref : ${{ github.ref }}
106+ fetch-depth : 3
70107
71- - name : increment development version
72- if : ${{ env.VERSION_DEV }}
108+ - name : get versions
109+ id : get
110+ shell : python
73111 run : |
74- v=$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH-dev$((VERSION_DEV+1))
75- sed -i "s/version = \".*\"$/version = \"$v\"/" pyproject.toml
76- - name : increment patch version
77- if : ${{ !env.VERSION_DEV }}
112+ from sys import exit
113+ from os import environ
114+ from packaging import version
115+ ver = version.parse("${{ github.ref_name }}")
116+ if ver.dev is not None:
117+ new_ver = f"{ver.base_version}-dev{ver.dev +1}"
118+ else:
119+ new_ver = f"{ver.major}.{ver.minor}.{ver.micro +1}-dev0"
120+ with open(environ.get("GITHUB_OUTPUT"), "a") as fp:
121+ towrite = f"NEW_VERSION={new_ver}"
122+ print(towrite)
123+ fp.write(towrite + "\n")
124+
125+ - name : update pyproject.toml
126+ env :
127+ VERSION : ${{ steps.get.outputs.NEW_VERSION }}
128+ run : sed -i -r "s/^(version = ).*$/\1\"$VERSION\"/" pyproject.toml
129+
130+ - name : commit version
131+ env :
132+ USER : github-actions[bot]
133+ EMAIL : github-actions[bot]@users.noreply.github.com
134+ run : git -c user.name="$USER" -c user.email="$EMAIL" commit --all -m "increment version after release"
135+
136+ - name : push updates
78137 run : |
79- v=$VERSION_MAJOR.$VERSION_MINOR.$((VERSION_PATCH+1))-dev0
80- sed -i "s/version = \".*\"$/version = \"$v\"/" pyproject.toml
81- - name : commit new version-number
82- uses : stefanzweifel/git-auto-commit-action@v4
83- with :
84- branch : ${{ env.BRANCH }}
85- create_branch : true
86- commit_message : " increment version after release"
138+ git fetch origin 'refs/heads/*:refs/remotes/origin/*'
139+ git push origin "HEAD:$(git log --pretty='%D' | grep -oPm1 '(?<=origin/).*')"
0 commit comments