Skip to content

Commit 38d1680

Browse files
committed
test
1 parent facdc47 commit 38d1680

File tree

1 file changed

+121
-65
lines changed

1 file changed

+121
-65
lines changed

.github/workflows/publish.yaml

Lines changed: 121 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -6,81 +6,137 @@
66
name: Upload Python Package
77

88
on:
9+
push:
10+
911
release:
10-
types: [created]
12+
types: published
1113

1214

1315
jobs:
1416

15-
deploy:
16-
runs-on: ubuntu-latest
17+
check-version:
18+
name: check version
19+
runs-on: linux
1720

1821
steps:
1922
- name: Checkout
2023
uses: actions/checkout@v3
21-
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
31-
- name: Set up Python
32-
uses: actions/setup-python@v4
33-
with:
34-
python-version: '3.x'
35-
cache: pip
36-
- 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!')
57-
58-
- name: Write Version to pyproject.toml
59-
run: |
60-
sed -i "s/version = \".*\"$/version = \"$VERSION\"/" pyproject.toml
61-
- name: Build sdist and bdist_wheel
62-
run: |
63-
python -m build
64-
- name: publish to PyPi
24+
25+
- name: get versions
26+
id: get
6527
env:
66-
TWINE_USERNAME: __token__
67-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
28+
RELEASE_TAG: ${{ github.ref_name }}
6829
run: |
69-
twine upload dist/*
30+
echo "NEW_VERSION=${RELEASE_TAG#v*}" | tee -a $GITHUB_ENV
31+
OLD_VERISON=$(curl -s https://pypi.org/pypi/readchar/json | jq -r .info.version)
32+
echo "OLD_VERISON=${OLD_VERISON}" | tee -a $GITHUB_ENV
7033
71-
- name: increment development version
72-
if: ${{ env.VERSION_DEV }}
73-
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 }}
34+
- name: validate version
35+
shell: python
7836
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"
37+
from sys import exit
38+
from packaging import version
39+
40+
new_version = version.parse("${{ steps.get.outputs.NEW_VERSION }}")
41+
old_version = version.parse("${{ steps.get.outputs.OLD_VERSION }}")
42+
43+
if not new_version > old_version:
44+
print(f"::error::New version '{new_version}' not greatet than '{old_version}'")
45+
exit(1)
46+
47+
outputs:
48+
version: ${{ steps.get.outputs.NEW_VERSION }}
49+
50+
51+
commit:
52+
name: write version and tag
53+
runs-on: linux
54+
needs: check-version
55+
permissions:
56+
contents: write
57+
58+
env:
59+
VERSION: ${{ needs.check-version.outputs.version }}
60+
steps:
61+
- name: update pyproject.toml
62+
run: sed -i "s/version = \".*\"$/version = \"$VERSION\"/" pyproject.toml
63+
- name: commit version
64+
run: git commit --all -m "release v$Version"
65+
- name: update tag
66+
run: git tag -f "v$VERSION"
67+
- name: push updates
68+
run: git push --tags -f
69+
70+
71+
# deploy:
72+
# runs-on: ubuntu-latest
73+
74+
# steps:
75+
# - name: Checkout
76+
# uses: actions/checkout@v3
77+
# with:
78+
# fetch-depth: 0
79+
# - name: Set env
80+
# run: |
81+
# echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" | tee -a $GITHUB_ENV
82+
# echo "BRANCH=$( \
83+
# git branch -r --contains ${GITHUB_REF} \
84+
# | grep -v HEAD \
85+
# | sed -n 's/ *origin\/\(.*\)/\1/p' \
86+
# )" | tee -a $GITHUB_ENV
87+
# - name: Set up Python
88+
# uses: actions/setup-python@v4
89+
# with:
90+
# python-version: '3.x'
91+
# cache: pip
92+
# - name: Install dependencies
93+
# run: |
94+
# pip install build twine
95+
# - name: get infos from Tag
96+
# run: |
97+
# echo "RELEASE_TAG=${RELEASE_TAG}"
98+
# if [[ $RELEASE_TAG =~ (([0-9]+)\.([0-9]+)\.([0-9]+))([-./]dev([0-9]+))?$ ]]
99+
# then
100+
# echo "VERSION=${BASH_REMATCH[0]}" | tee -a $GITHUB_ENV
101+
# echo "VERSION_MAJOR=${BASH_REMATCH[2]}" | tee -a $GITHUB_ENV
102+
# echo "VERSION_MINOR=${BASH_REMATCH[3]}" | tee -a $GITHUB_ENV
103+
# echo "VERSION_PATCH=${BASH_REMATCH[4]}" | tee -a $GITHUB_ENV
104+
# echo "VERSION_DEV=${BASH_REMATCH[6]}" | tee -a $GITHUB_ENV
105+
# else
106+
# echo "INVALID_TAG=True" | tee -a $GITHUB_ENV
107+
# fi
108+
# - name: Fail on invalid Tag
109+
# if: ${{ env.INVALID_TAG }}
110+
# uses: actions/github-script@v6
111+
# with:
112+
# script: core.setFailed('Invalid Tag name used with this release!')
113+
114+
# - name: Write Version to pyproject.toml
115+
# run: |
116+
# sed -i "s/version = \".*\"$/version = \"$VERSION\"/" pyproject.toml
117+
# - name: Build sdist and bdist_wheel
118+
# run: |
119+
# python -m build
120+
# - name: publish to PyPi
121+
# env:
122+
# TWINE_USERNAME: __token__
123+
# TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
124+
# run: |
125+
# twine upload dist/*
126+
127+
# - name: increment development version
128+
# if: ${{ env.VERSION_DEV }}
129+
# run: |
130+
# v=$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH-dev$((VERSION_DEV+1))
131+
# sed -i "s/version = \".*\"$/version = \"$v\"/" pyproject.toml
132+
# - name: increment patch version
133+
# if: ${{ !env.VERSION_DEV }}
134+
# run: |
135+
# v=$VERSION_MAJOR.$VERSION_MINOR.$((VERSION_PATCH+1))-dev0
136+
# sed -i "s/version = \".*\"$/version = \"$v\"/" pyproject.toml
137+
# - name: commit new version-number
138+
# uses: stefanzweifel/git-auto-commit-action@v4
139+
# with:
140+
# branch: ${{ env.BRANCH }}
141+
# create_branch: true
142+
# commit_message: "increment version after release"

0 commit comments

Comments
 (0)