|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 | ''' |
3 | | -Run [[file:scripts/release][scripts/release]] to deploy Python package onto [[https://pypi.org][PyPi]] and [[https://test.pypi.org][test PyPi]]. |
| 3 | +Deploys Python package onto [[https://pypi.org][PyPi]] or [[https://test.pypi.org][test PyPi]]. |
4 | 4 |
|
5 | | -The script expects =TWINE_PASSWORD= environment variable to contain the [[https://pypi.org/help/#apitoken][PyPi token]] (not the password!). |
| 5 | +- running manually |
6 | 6 |
|
7 | | -The script can be run manually. |
8 | | -It's also running as =pypi= job in [[file:.github/workflows/main.yml][Github Actions config]]. Packages are deployed on: |
9 | | -- every master commit, onto test pypi |
10 | | -- every new tag, onto production pypi |
| 7 | + You'll need =UV_PUBLISH_TOKEN= env variable |
11 | 8 |
|
12 | | -You'll need to set =TWINE_PASSWORD= and =TWINE_PASSWORD_TEST= in [[https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets#creating-encrypted-secrets][secrets]] |
13 | | -for Github Actions deployment to work. |
| 9 | +- running on Github Actions |
| 10 | +
|
| 11 | + Instead of env variable, relies on configuring github as Trusted publisher (https://docs.pypi.org/trusted-publishers/) -- both for test and regular pypi |
| 12 | +
|
| 13 | + It's running as =pypi= job in [[file:.github/workflows/main.yml][Github Actions config]]. |
| 14 | + Packages are deployed on: |
| 15 | + - every master commit, onto test pypi |
| 16 | + - every new tag, onto production pypi |
14 | 17 | ''' |
15 | 18 |
|
| 19 | +UV_PUBLISH_TOKEN = 'UV_PUBLISH_TOKEN' |
| 20 | + |
| 21 | +import argparse |
16 | 22 | import os |
17 | | -import sys |
18 | 23 | from pathlib import Path |
19 | 24 | from subprocess import check_call |
20 | | -import shutil |
21 | 25 |
|
22 | 26 | is_ci = os.environ.get('CI') is not None |
23 | 27 |
|
| 28 | + |
24 | 29 | def main() -> None: |
25 | | - import argparse |
26 | 30 | p = argparse.ArgumentParser() |
27 | | - p.add_argument('--test', action='store_true', help='use test pypi') |
| 31 | + p.add_argument('--use-test-pypi', action='store_true') |
28 | 32 | args = p.parse_args() |
29 | 33 |
|
30 | | - extra = [] |
31 | | - if args.test: |
32 | | - extra.extend(['--repository', 'testpypi']) |
| 34 | + publish_url = ['--publish-url', 'https://test.pypi.org/legacy/'] if args.use_test_pypi else [] |
33 | 35 |
|
34 | 36 | root = Path(__file__).absolute().parent.parent |
35 | | - os.chdir(root) # just in case |
36 | | - |
37 | | - if is_ci: |
38 | | - # see https://github.com/actions/checkout/issues/217 |
39 | | - check_call('git fetch --prune --unshallow'.split()) |
40 | | - |
41 | | - dist = root / 'dist' |
42 | | - if dist.exists(): |
43 | | - shutil.rmtree(dist) |
44 | | - |
45 | | - check_call(['python3', '-m', 'build']) |
46 | | - |
47 | | - TP = 'TWINE_PASSWORD' |
48 | | - password = os.environ.get(TP) |
49 | | - if password is None: |
50 | | - print(f"WARNING: no {TP} passed", file=sys.stderr) |
51 | | - import pip_secrets |
52 | | - password = pip_secrets.token_test if args.test else pip_secrets.token # meh |
53 | | - |
54 | | - check_call([ |
55 | | - 'python3', '-m', 'twine', |
56 | | - 'upload', *dist.iterdir(), |
57 | | - *extra, |
58 | | - ], env={ |
59 | | - 'TWINE_USERNAME': '__token__', |
60 | | - TP: password, |
61 | | - **os.environ, |
62 | | - }) |
| 37 | + os.chdir(root) # just in case |
| 38 | + |
| 39 | + check_call(['uv', 'build', '--clear']) |
| 40 | + |
| 41 | + if not is_ci: |
| 42 | + # CI relies on trusted publishers so doesn't need env variable |
| 43 | + assert UV_PUBLISH_TOKEN in os.environ, f'no {UV_PUBLISH_TOKEN} passed' |
| 44 | + |
| 45 | + check_call(['uv', 'publish', *publish_url]) |
63 | 46 |
|
64 | 47 |
|
65 | 48 | if __name__ == '__main__': |
|
0 commit comments