Skip to content

Commit 0896838

Browse files
authored
Merge pull request #668 from planetlabs/automate-release
create noxfile session and github action for publishing to testpypi
2 parents 0286d0f + 4b23f1d commit 0896838

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Autopublish to TestPyPi
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
publish:
10+
name: Build, verify, & upload package
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
- name: Set up Python
17+
uses: actions/setup-python@v3
18+
with:
19+
python-version: 3.7
20+
21+
- name: Pip cache
22+
uses: actions/cache@v2
23+
with:
24+
path: ~/.cache/pip
25+
key: ${{ runner.os }}-pip
26+
restore-keys: |
27+
${{ runner.os }}-pip
28+
29+
- name: Build, verify, and upload to TestPyPI
30+
run: |
31+
pip install --upgrade nox
32+
nox -s build publish
33+
env:
34+
TWINE_USERNAME: __token__
35+
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}

noxfile.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from pathlib import Path
2+
import shutil
3+
14
import nox
25

36
nox.options.stop_on_first_error = True
@@ -7,6 +10,8 @@
710

811
source_files = ("planet", "examples", "tests", "setup.py", "noxfile.py")
912

13+
BUILD_DIRS = ['build', 'dist']
14+
1015

1116
@nox.session
1217
def analyze(session):
@@ -91,3 +96,40 @@ def examples(session):
9196
# Because these example scripts can be long-running, output the
9297
# example's stdout so we know what's happening
9398
session.run('pytest', '--no-cov', 'examples/', '-s', *options)
99+
100+
101+
@nox.session
102+
def build(session):
103+
# check preexisting
104+
exist_but_should_not = [p for p in BUILD_DIRS if Path(p).is_dir()]
105+
if exist_but_should_not:
106+
session.error(
107+
f"Pre-existing {', '.join(exist_but_should_not)}. Run clean session and try again"
108+
)
109+
110+
session.install('build', 'twine', 'check-wheel-contents')
111+
112+
session.run(*'python -m build --sdist --wheel'.split())
113+
session.run('check-wheel-contents', 'dist')
114+
115+
116+
@nox.session
117+
def clean(session):
118+
to_remove = [Path(d) for d in BUILD_DIRS if Path(d).is_dir()]
119+
for p in to_remove:
120+
shutil.rmtree(p)
121+
122+
123+
@nox.session
124+
def publish(session):
125+
missing = [p for p in BUILD_DIRS if not Path(p).is_dir()]
126+
if missing:
127+
session.error(
128+
f"Missing one or more build directories: {', '.join(missing)}. Run build session and try again"
129+
)
130+
131+
session.install('twine')
132+
133+
files = [str(f) for f in Path('dist').iterdir()]
134+
session.run("twine", "check", *files)
135+
session.run("twine", "upload", "--repository=testpypi", *files)

0 commit comments

Comments
 (0)