Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 4507f25

Browse files
committed
Update deploy script
1 parent 5924a06 commit 4507f25

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

tasks.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
import datetime
2+
3+
import toml
14
from invoke import Context, task
5+
from invoke.exceptions import UnexpectedExit
26

37
import monkey_patch_invoke as _
48

@@ -9,7 +13,37 @@ def test(context: Context) -> None:
913
context.run('pytest . ', pty=True)
1014

1115

16+
def _get_today_timestamp() -> str:
17+
return datetime.datetime.utcnow().strftime('%Y.%m.%d')
18+
19+
1220
@task
1321
def publish(context: Context) -> None:
1422
"""Publish to PyPI."""
15-
context.run('poetry publish --build', pty=True)
23+
24+
# load pyproject
25+
pyproject_path = 'pyproject.toml'
26+
pyproject_string = ''
27+
with open(pyproject_path, 'r', encoding='utf-8') as pyproject_file:
28+
pyproject_string = pyproject_file.read()
29+
pyproject = toml.loads(pyproject_string)
30+
# change version to today datetime
31+
pyproject['tool']['poetry']['version'] = _get_today_timestamp()
32+
with open(pyproject_path, 'w', encoding='utf-8') as pyproject_file:
33+
toml.dump(pyproject, pyproject_file)
34+
35+
# build & publish
36+
try:
37+
context.run(
38+
'''
39+
poetry build --no-interaction
40+
poetry publish --no-interaction
41+
''',
42+
pty=True,
43+
)
44+
except UnexpectedExit:
45+
pass
46+
47+
# recover to original
48+
with open(pyproject_path, 'w', encoding='utf-8') as pyproject_file:
49+
pyproject_file.write(pyproject_string)

0 commit comments

Comments
 (0)