Skip to content

Commit 036edb1

Browse files
authored
Add release workflow (#329)
* Add release workflow * Use GitHub env and OIDC * Test on 3.11
1 parent 0d652b4 commit 036edb1

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

.github/workflows/main.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
strategy:
2323
fail-fast: false
2424
matrix:
25-
python-version: ['3.9', '3.10'] #TODO: add 3.11 once sparse/numba support it
25+
python-version: ['3.9', '3.10', '3.11']
2626
timeout-minutes: 20
2727
defaults:
2828
run:

.github/workflows/pypi-release.yaml

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: Build and Upload cmip6_dowscaling 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 == 'carbonplan/cmip6-downscaling'
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
- uses: actions/[email protected]
23+
name: Install Python
24+
with:
25+
python-version: '3.11'
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
python -m pip install build twine
31+
git clean -xdf
32+
git restore -SW .
33+
34+
# This step is only necessary for testing purposes and for TestPyPI
35+
- name: Fix up version string for TestPyPI
36+
if: ${{ !startsWith(github.ref, 'refs/tags') }}
37+
run: |
38+
# Change setuptools-scm local_scheme to "no-local-version" so the
39+
# local part of the version isn't included, making the version string
40+
# compatible with PyPI.
41+
sed --in-place "s/node-and-date/no-local-version/g" pyproject.toml
42+
43+
- name: Build tarball and wheels
44+
run: |
45+
python -m build
46+
- name: Check built artifacts
47+
run: |
48+
python -m twine check --strict dist/*
49+
pwd
50+
if [ -f dist/cmip6_downscaling-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@v4
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/[email protected]
66+
name: Install Python
67+
with:
68+
python-version: '3.11'
69+
- uses: actions/download-artifact@v4
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/cmip6_downscaling*.whl
81+
python -c "import cmip6_downscaling; print(cmip6_downscaling.__version__)"
82+
- name: Publish package to TestPyPI
83+
uses: pypa/[email protected]
84+
with:
85+
password: ${{ secrets.TEST_PYPI_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+
environment: release
94+
steps:
95+
- uses: actions/download-artifact@v4
96+
with:
97+
name: releases
98+
path: dist
99+
- name: Publish package to PyPI
100+
uses: pypa/[email protected]

0 commit comments

Comments
 (0)