Skip to content

Commit f63a08f

Browse files
committed
Add test PyPi action
1 parent fbf148f commit f63a08f

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Test PyPI build and upload
2+
on:
3+
pull_request:
4+
types: [opened, reopened, synchronize, labeled]
5+
workflow_dispatch:
6+
7+
jobs:
8+
build-artifacts:
9+
runs-on: ubuntu-latest
10+
if: ${{ contains( github.event.pull_request.labels.*.name, 'Release') && github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'}}
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
- uses: actions/setup-python@v5
16+
name: Install Python
17+
with:
18+
python-version: "3.12"
19+
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
python -m pip install build twine
24+
25+
- name: Build tarball and wheels
26+
run: |
27+
git clean -xdf
28+
git restore -SW .
29+
python -m build
30+
31+
- name: Check built artifacts
32+
run: |
33+
python -m twine check --strict dist/*
34+
pwd
35+
if [ -f dist/xarray-0.0.0.tar.gz ]; then
36+
echo "❌ INVALID VERSION NUMBER"
37+
exit 1
38+
else
39+
echo "✅ Looks good"
40+
fi
41+
- uses: actions/upload-artifact@v4
42+
with:
43+
name: releases
44+
path: dist
45+
46+
test-built-dist:
47+
needs: build-artifacts
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/setup-python@v5
51+
name: Install Python
52+
with:
53+
python-version: "3.12"
54+
- uses: actions/download-artifact@v4
55+
with:
56+
name: releases
57+
path: dist
58+
- name: List contents of built dist
59+
run: |
60+
ls -ltrh
61+
ls -ltrh dist
62+
63+
- name: Verify the built dist/wheel is valid
64+
if: github.event_name == 'push'
65+
run: |
66+
python -m pip install --upgrade pip
67+
python -m pip install dist/xarray*.whl
68+
python -m xarray.util.print_versions
69+
70+
upload-to-test-pypi:
71+
needs: test-built-dist
72+
runs-on: ubuntu-latest
73+
74+
environment:
75+
name: pypi
76+
url: https://test.pypi.org/p/xarray
77+
permissions:
78+
id-token: write
79+
80+
steps:
81+
- uses: actions/download-artifact@v4
82+
with:
83+
name: releases
84+
path: dist
85+
- name: Publish package to TestPyPI
86+
if: github.event_name == 'push'
87+
uses: pypa/[email protected]
88+
with:
89+
repository_url: https://test.pypi.org/legacy/
90+
verbose: true

0 commit comments

Comments
 (0)