Skip to content

Commit 830a1f3

Browse files
committed
Add release script
1 parent d17d29e commit 830a1f3

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

.github/workflows/release.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release Package to PyPI
2+
on:
3+
release:
4+
types: [created]
5+
jobs:
6+
release:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
with:
11+
fetch-depth: 0
12+
- name: Set up Python 3.9
13+
uses: actions/setup-python@v4
14+
with:
15+
python-version: 3.9
16+
17+
- uses: snok/[email protected]
18+
with:
19+
virtualenvs-create: true
20+
virtualenvs-in-project: true
21+
22+
- name: Cache Dependencies
23+
uses: actions/cache@v2
24+
id: cache-dependencies
25+
with:
26+
path: .venv
27+
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
28+
29+
- name: Install Dependencies if cache doesn't hit
30+
if: steps.cache-dependencies.cache-hit != 'true'
31+
run: poetry install
32+
33+
- name: Publish to PyPI
34+
run:
35+
poetry config http-basic.pypi ${{ secrets.PYPI_USERNAME }} ${{ secrets.PYPI_PASSWORD }};
36+
poetry run invoke release ${{ github.event.release.name }}

tasks.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import toml
55
from invoke import Context, task
6+
from invoke.exceptions import UnexpectedExit
67

78
import monkey_patch_invoke as _ # noqa: F401
89

@@ -78,3 +79,37 @@ def rename_project(_context: Context, project_name: str):
7879

7980
with open('pyproject.toml', 'w', encoding='utf-8') as file:
8081
toml.dump(data, file)
82+
83+
84+
@task
85+
def release(context: Context, version: str) -> None:
86+
'''Build & Publish to PyPI.'''
87+
88+
# load pyproject
89+
pyproject_path = 'pyproject.toml'
90+
pyproject_string = ''
91+
with open(pyproject_path, 'r', encoding='utf-8') as pyproject_file:
92+
pyproject_string = pyproject_file.read()
93+
pyproject = toml.loads(pyproject_string)
94+
# change version to today datetime
95+
pyproject['tool']['poetry']['version'] = version
96+
with open(pyproject_path, 'w', encoding='utf-8') as pyproject_file:
97+
toml.dump(pyproject, pyproject_file)
98+
99+
# build & publish
100+
try:
101+
context.run(
102+
'''
103+
poetry build --no-interaction
104+
poetry publish --no-interaction
105+
''',
106+
pty=True,
107+
)
108+
except UnexpectedExit as exception:
109+
with open(pyproject_path, 'w', encoding='utf-8') as pyproject_file:
110+
pyproject_file.write(pyproject_string)
111+
raise exception from exception
112+
113+
# recover to original
114+
with open(pyproject_path, 'w', encoding='utf-8') as pyproject_file:
115+
pyproject_file.write(pyproject_string)

0 commit comments

Comments
 (0)