Skip to content

Commit 51fc917

Browse files
committed
Add automated publishing workflows
1 parent fdfcad2 commit 51fc917

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Publish PyPI Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-python@v4
14+
with:
15+
python-version: "3.11"
16+
17+
- run: python -m pip install build
18+
- run: python -m build .
19+
20+
- name: Publish to PyPI
21+
uses: pypa/gh-action-pypi-publish@release/v1
22+
with:
23+
password: ${{ secrets.PYPI_API_TOKEN }}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Publish Test PyPI Release
2+
3+
on:
4+
push:
5+
tags: ["*"]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-python@v4
14+
with:
15+
python-version: "3.11"
16+
17+
- run: python -m pip install build
18+
19+
- name: Set dev version prior to upload
20+
run: python ./scripts/set-dev-version.py
21+
22+
- run: python -m build .
23+
24+
- name: Publish to TestPyPI
25+
uses: pypa/gh-action-pypi-publish@release/v1
26+
with:
27+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
28+
repository_url: https://test.pypi.org/legacy/

scripts/set-dev-version.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python
2+
import argparse
3+
import re
4+
5+
6+
def get_old_version():
7+
with open("setup.cfg") as fp:
8+
content = fp.read()
9+
match = re.search(r"^version = (\d+\.\d+\.\d+)$", content, flags=re.MULTILINE)
10+
assert match
11+
return match.group(1)
12+
13+
14+
def replace_version(old_version, new_version):
15+
print(f"updating setup.cfg version to {new_version}")
16+
with open("setup.cfg") as fp:
17+
content = fp.read()
18+
old_str = f"version = {old_version}"
19+
new_str = f"version = {new_version}"
20+
content = content.replace(old_str, new_str)
21+
with open("setup.cfg", "w") as fp:
22+
fp.write(content)
23+
24+
25+
def main():
26+
parser = argparse.ArgumentParser()
27+
parser.add_argument(
28+
"-n", "--number", help="dev number to use, defaults to 1", type=int, default=1
29+
)
30+
args = parser.parse_args()
31+
32+
old_version = get_old_version()
33+
new_version = old_version + f".dev{args.number}"
34+
35+
replace_version(old_version, new_version)
36+
print("done")
37+
38+
39+
if __name__ == "__main__":
40+
main()

0 commit comments

Comments
 (0)