Skip to content

Commit 8621181

Browse files
Max Jonesweiji14
andauthored
Add GitHub workflow for PyPI releases (#108)
* Add GitHub workflow for PyPI releases * Comment verbose setting * Omit direct invocation code from coverage * Apply suggestions from code review Co-authored-by: Wei Ji <[email protected]> * Use consistent file extension * Document workflow * Test workflow * Specify readme in project metadata * Upload to TestPyPI on PR * Fix test command * Update token name * Apply suggestions from code review Co-authored-by: Wei Ji <[email protected]>
1 parent d409930 commit 8621181

File tree

4 files changed

+123
-14
lines changed

4 files changed

+123
-14
lines changed

.github/workflows/pypi-release.yaml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: Build and Upload xbatcher to PyPI
2+
on:
3+
release:
4+
types:
5+
- published
6+
# Runs for pull requests should be disabled other than for testing purposes
7+
#pull_request:
8+
# branches:
9+
# - main
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
build-artifacts:
16+
runs-on: ubuntu-latest
17+
if: github.repository == 'xarray-contrib/xbatcher'
18+
steps:
19+
- uses: actions/checkout@v3
20+
with:
21+
fetch-depth: 0
22+
- uses: actions/setup-python@v4
23+
name: Install Python
24+
with:
25+
python-version: 3.8
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
python -m pip install build twine
31+
32+
# This step is only necessary for testing purposes and for TestPyPI
33+
- name: Fix up version string for TestPyPI
34+
if: ${{ !startsWith(github.ref, 'refs/tags') }}
35+
run: |
36+
# Change setuptools-scm local_scheme to "no-local-version" so the
37+
# local part of the version isn't included, making the version string
38+
# compatible with PyPI.
39+
sed --in-place "s/dirty-tag/no-local-version/g" pyproject.toml
40+
41+
- name: Build tarball and wheels
42+
run: |
43+
git clean -xdf
44+
git restore -SW .
45+
python -m build
46+
- name: Check built artifacts
47+
run: |
48+
python -m twine check --strict dist/*
49+
pwd
50+
if [ -f dist/xbatcher-0.0.0.tar.gz ]; then
51+
echo "❌ INVALID VERSION NUMBER"
52+
exit 1
53+
else
54+
echo "✅ Looks good"
55+
fi
56+
- uses: actions/upload-artifact@v3
57+
with:
58+
name: releases
59+
path: dist
60+
61+
test-built-dist:
62+
needs: build-artifacts
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/setup-python@v4
66+
name: Install Python
67+
with:
68+
python-version: 3.8
69+
- uses: actions/download-artifact@v3
70+
with:
71+
name: releases
72+
path: dist
73+
- name: List contents of built dist
74+
run: |
75+
ls -ltrh
76+
ls -ltrh dist
77+
- name: Verify the built dist/wheel is valid
78+
run: |
79+
python -m pip install --upgrade pip
80+
python -m pip install dist/xbatcher*.whl
81+
python -m xbatcher.util.print_versions
82+
- name: Publish package to TestPyPI
83+
uses: pypa/[email protected]
84+
with:
85+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
86+
repository_url: https://test.pypi.org/legacy/
87+
# verbose: true
88+
89+
upload-to-pypi:
90+
needs: test-built-dist
91+
if: github.event_name == 'release'
92+
runs-on: ubuntu-latest
93+
steps:
94+
- uses: actions/download-artifact@v3
95+
with:
96+
name: releases
97+
path: dist
98+
- name: Publish package to PyPI
99+
uses: pypa/[email protected]
100+
with:
101+
password: ${{ secrets.PYPI_API_TOKEN }}
102+
# verbose: true

doc/contributing.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,5 @@ Continuous integration is done with `GitHub Actions <https://docs.github.com/en/
246246
There is currently 1 workflow configured:
247247

248248
- `main.yaml <https://github.com/xarray-contrib/xbatcher/blob/main/.github/workflows/main.yaml>`_ - Run test suite with pytest.
249+
- `pypi-release.yaml <https://github.com/xarray-contrib/xbatcher/blob/main/.github/workflows/pypi-release.yaml>`_ - Publish
250+
wheels to TestPyPI and PyPI on a tagged release. The pull request trigger can be uncommented to test a release using Test PyPI.

pyproject.toml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,23 @@ requires = [
66
build-backend = "setuptools.build_meta"
77

88
[project]
9-
name = 'xbatcher'
10-
description = 'Batch generation from Xarray objects'
9+
name = "xbatcher"
10+
description = "Batch generation from Xarray objects"
11+
readme = "README.rst"
1112
license = {text = "Apache"}
1213
authors = [{name = "xbatcher Developers", email = "[email protected]"}]
1314
requires-python = ">=3.8"
1415
classifiers = [
15-
'Development Status :: 4 - Beta',
16+
"Development Status :: 4 - Beta",
1617
"License :: OSI Approved :: Apache Software License",
17-
'Operating System :: OS Independent',
18-
'Intended Audience :: Science/Research',
19-
'Programming Language :: Python',
20-
'Programming Language :: Python :: 3',
21-
'Programming Language :: Python :: 3.8',
22-
'Programming Language :: Python :: 3.9',
23-
'Programming Language :: Python :: 3.10',
24-
'Topic :: Scientific/Engineering',
18+
"Operating System :: OS Independent",
19+
"Intended Audience :: Science/Research",
20+
"Programming Language :: Python",
21+
"Programming Language :: Python :: 3",
22+
"Programming Language :: Python :: 3.8",
23+
"Programming Language :: Python :: 3.9",
24+
"Programming Language :: Python :: 3.10",
25+
"Topic :: Scientific/Engineering",
2526
]
2627
dynamic = ["version"]
2728
dependencies = [
@@ -53,12 +54,12 @@ repository = "https://github.com/xarray-contrib/xbatcher"
5354
include = ["xbatcher*"]
5455

5556
[tool.setuptools_scm]
56-
version_scheme = 'post-release'
57-
local_scheme = 'dirty-tag'
57+
version_scheme = "post-release"
58+
local_scheme = "dirty-tag"
5859
fallback_version = "999"
5960

6061
[tool.isort]
61-
profile = 'black'
62+
profile = "black"
6263
known_third_party = ["numpy", "pytest", "setuptools", "sphinx_autosummary_accessors", "torch", "xarray"]
6364

6465
[tool.pytest.ini_options]

xbatcher/util/print_versions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,7 @@ def _get_module_version(modname):
6363
print("Dependency information:", file=file)
6464
for modname in deps:
6565
print(f" {modname}: {_get_module_version(modname)}", file=file)
66+
67+
68+
if __name__ == "__main__": # pragma: no cover
69+
show_versions()

0 commit comments

Comments
 (0)