Skip to content

Commit 30700d7

Browse files
authored
Setup GitHub Action for publishing to PyPI and TestPyPI (icesat2py#174)
* Setup Github Action for publishing to PyPI and TestPyPI Publishing the icepyx package to PyPI on every tagged (published) release. Every push to the development branch is also published to TestPyPI for testing purposes. * Remove PyPI/TestPyPI deploying steps from .travis.yml * Trigger publishing to TestPyPI manually using workflow_dispatch
1 parent 756fc21 commit 30700d7

File tree

3 files changed

+65
-22
lines changed

3 files changed

+65
-22
lines changed

.github/workflows/publish_to_pypi.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Publish archives to PyPI and TestPyPI using GitHub Actions
2+
name: Publish to PyPI
3+
4+
# Only run for tagged releases and pushes to the development branch
5+
on:
6+
release:
7+
types:
8+
- published
9+
push:
10+
branches:
11+
- development
12+
# Trigger manually at https://github.com/icesat2py/icepyx/actions/workflows/publish_to_pypi.yml
13+
workflow_dispatch:
14+
15+
jobs:
16+
publish-pypi:
17+
name: Publish to PyPI
18+
runs-on: ubuntu-latest
19+
if: github.repository == 'icesat2py/icepyx'
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/[email protected]
24+
with:
25+
# fetch all history so that setuptools-scm works
26+
fetch-depth: 0
27+
28+
- name: Set up Python
29+
uses: actions/[email protected]
30+
with:
31+
python-version: 3.9
32+
33+
- name: Install dependencies
34+
run: python -m pip install setuptools wheel
35+
36+
# This step is only necessary for testing purposes and for TestPyPI
37+
- name: Fix up version string for TestPyPI
38+
if: ${{ !startsWith(github.ref, 'refs/tags') }}
39+
run: |
40+
# Change setuptools-scm local_scheme to "no-local-version" so the
41+
# local part of the version isn't included, making the version string
42+
# compatible with PyPI.
43+
sed --in-place "s/node-and-date/no-local-version/g" setup.py
44+
45+
- name: Build source and wheel distributions
46+
run: |
47+
python setup.py sdist bdist_wheel
48+
echo ""
49+
echo "Generated files:"
50+
ls -lh dist/
51+
52+
- name: Publish to Test PyPI
53+
uses: pypa/[email protected]
54+
with:
55+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
56+
repository_url: https://test.pypi.org/legacy/
57+
58+
- name: Publish to PyPI
59+
if: startsWith(github.ref, 'refs/tags')
60+
uses: pypa/[email protected]
61+
with:
62+
password: ${{ secrets.PYPI_API_TOKEN }}

.travis.yml

-21
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,3 @@ jobs:
2121
# script:
2222
# - export NSIDC_LOGIN=$NSIDC_LOGIN
2323
# - pytest icepyx/tests/behind_NSIDC_API_login.py
24-
25-
deploy:
26-
- provider: pypi
27-
server: https://test.pypi.org/legacy/
28-
username: "__token__"
29-
password: $test_PyPI_API_Token
30-
on:
31-
branch: development
32-
if: commit_message =~ test_pypi
33-
skip_existing: true
34-
distributions: "sdist bdist_wheel"
35-
36-
# NOTE: the API token on Travis must be set to ALL branches, because a tag build is not considered to be on the master branch: https://travis-ci.community/t/pypi-upload-with-api-token-not-working/5338/5
37-
- provider: pypi
38-
username: "__token__"
39-
password: $PyPI_API_Token
40-
on:
41-
branch: master
42-
tags: true
43-
skip_existing: true
44-
distributions: "sdist bdist_wheel"

setup.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
"Development Status :: 1 - Planning",
2828
],
2929
use_scm_version={
30+
"fallback_version": "unknown",
31+
"local_scheme": "node-and-date",
3032
"write_to": "_version.py",
3133
"write_to_template": 'version = "{version}"\n',
3234
},
33-
setup_requires=["setuptools>=30.3.0", "wheel", "setuptools_scm"]
35+
setup_requires=["setuptools>=30.3.0", "wheel", "setuptools_scm"],
3436
)

0 commit comments

Comments
 (0)