-
Notifications
You must be signed in to change notification settings - Fork 52
139 lines (113 loc) · 4.18 KB
/
publish.yaml
File metadata and controls
139 lines (113 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
---
# 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:
release:
types: published
jobs:
check-version: # --------------------------------------------------------------------
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: get versions
id: get
run: |
echo "NEW_VERSION=$(echo '${{ github.ref_name }}' | cut -c2-)" | tee -a $GITHUB_OUTPUT
echo "OLD_VERSION=$(curl -s https://pypi.org/pypi/readchar/json |jq -r .info.version)" | tee -a $GITHUB_OUTPUT
- name: validate version
id: valid
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 }}
tag: # ------------------------------------------------------------------------------
runs-on: ubuntu-latest
needs: check-version
permissions:
contents: write
env:
VERSION: ${{ needs.check-version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: update pyproject.toml
run: sed -i -r "s/^(version = ).*$/\1\"$VERSION\"/" pyproject.toml
- name: commit version
env:
USER: github-actions[bot]
EMAIL: github-actions[bot]@users.noreply.github.com
run: git -c user.name="$USER" -c user.email="$EMAIL" 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
needs: tag
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
cache: pip
- name: Install dependencies
run: pip install build twine
- 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/*
increment: # ------------------------------------------------------------------------
runs-on: ubuntu-latest
needs: deploy
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
fetch-depth: 3
- name: get versions
id: get
shell: python
run: |
from sys import exit
from os import environ
from packaging import version
ver = version.parse("${{ github.ref_name }}")
if ver.dev is not None:
new_ver = f"{ver.base_version}-dev{ver.dev +1}"
else:
new_ver = f"{ver.major}.{ver.minor}.{ver.micro +1}-dev0"
with open(environ.get("GITHUB_OUTPUT"), "a") as fp:
towrite = f"NEW_VERSION={new_ver}"
print(towrite)
fp.write(towrite + "\n")
- name: update pyproject.toml
env:
VERSION: ${{ steps.get.outputs.NEW_VERSION }}
run: sed -i -r "s/^(version = ).*$/\1\"$VERSION\"/" pyproject.toml
- name: commit version
env:
USER: github-actions[bot]
EMAIL: github-actions[bot]@users.noreply.github.com
run: git -c user.name="$USER" -c user.email="$EMAIL" commit --all -m "increment version after release"
- name: push updates
run: |
git fetch origin 'refs/heads/*:refs/remotes/origin/*'
git push origin "HEAD:$(git log --pretty='%D' | grep -oPm1 '(?<=origin/).*')"