Skip to content

Commit d3bc645

Browse files
authored
Merge pull request #18 from python/build_release
Add GH Action to publish to PyPI
2 parents 290e73e + 29a1a71 commit d3bc645

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

.github/workflows/publish.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This workflow is triggered two ways:
2+
#
3+
# 1. When a tag is created, the workflow will upload the package to
4+
# test.pypi.org.
5+
# 2. When a release is made, the workflow will upload the package to pypi.org.
6+
#
7+
# It is done this way until PyPI has draft reviews, to allow for a two-stage
8+
# upload with a chance for manual intervention before the final publication.
9+
name: Upload package
10+
11+
on:
12+
release:
13+
types: [created]
14+
push:
15+
tags:
16+
- '*'
17+
18+
jobs:
19+
deploy:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Set up Python
24+
uses: actions/setup-python@v2
25+
with:
26+
python-version: '3.x'
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install -U tox
31+
- name: Create tox environments
32+
run: |
33+
tox -p -e py,build,release --notest
34+
- name: Run tests
35+
run: |
36+
tox -e py
37+
- name: Build package
38+
run: |
39+
tox -e build
40+
- name: Publish package
41+
env:
42+
TWINE_USERNAME: "__token__"
43+
run: |
44+
if [[ "$GITHUB_EVENT_NAME" == "push" ]]; then
45+
export TWINE_REPOSITORY_URL="https://test.pypi.org/legacy/"
46+
export TWINE_PASSWORD="${{ secrets.TEST_PYPI_UPLOAD_TOKEN }}"
47+
elif [[ "$GITHUB_EVENT_NAME" == "release" ]]; then
48+
export TWINE_REPOSITORY="pypi"
49+
export TWINE_PASSWORD="${{ secrets.PYPI_UPLOAD_TOKEN }}"
50+
else
51+
echo "Unknown event name: ${GITHUB_EVENT_NAME}"
52+
exit 1
53+
fi
54+
55+
tox -e release

tox.ini

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,21 @@ deps =
4848
pep517
4949
twine
5050
commands =
51+
python -c "from pathlib import Path; \
52+
[x.unlink(missing_ok=True) for x in Path('{toxinidir}/dist').glob('*')]"
5153
python -m pep517.build -s -b {toxinidir} -o {toxinidir}/dist
5254
twine check {toxinidir}/dist/*
55+
56+
[testenv:release]
57+
description = Make a release; must be called after "build"
58+
skip_install = True
59+
deps =
60+
twine
61+
depends =
62+
build
63+
passenv =
64+
TWINE_*
65+
commands =
66+
twine check {toxinidir}/dist/*
67+
twine upload {toxinidir}/dist/* \
68+
{posargs:-r testpypi --non-interactive}

0 commit comments

Comments
 (0)