Skip to content

Commit 4244ca4

Browse files
authored
use trusted publishers to publish to PyPI (#261)
* use trusted publishers to publish * remove the redundant `black` hook
1 parent f615a3f commit 4244ca4

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-14
lines changed

Diff for: .github/workflows/pypi.yaml

+48-13
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,66 @@ name: Upload Package to PyPI
22

33
on:
44
release:
5-
types: [created]
5+
types:
6+
- published
67

78
jobs:
8-
deploy:
9+
build-artifacts:
910
runs-on: ubuntu-latest
1011
if: github.repository == 'xarray-contrib/pint-xarray'
1112
steps:
1213
- uses: actions/checkout@v4
13-
- name: Set up Python
14-
uses: actions/setup-python@v5
1514
with:
16-
python-version: '3.x'
15+
fetch-depth: 0
16+
17+
- uses: actions/setup-python@v5
18+
name: Install Python
19+
with:
20+
python-version: "3.x"
21+
1722
- name: Install dependencies
1823
run: |
1924
python -m pip install --upgrade pip
2025
python -m pip install build twine
21-
- name: Build
26+
27+
- name: Build tarball and wheels
2228
run: |
23-
python -m build --sdist --wheel --outdir dist/ .
24-
- name: Check the built archives
29+
git clean -xdf
30+
git restore -SW .
31+
python -m build --outdir dist/ .
32+
33+
- name: Check built artifacts
2534
run: |
26-
twine check dist/*
27-
- name: Publish to PyPI
35+
python -m twine check --strict dist/*
36+
pwd
37+
if [ -f dist/pint-xarray-0.0.0.tar.gz ]; then
38+
echo "❌ INVALID VERSION NUMBER"
39+
exit 1
40+
else
41+
echo "✅ Looks good"
42+
fi
43+
- uses: actions/upload-artifact@v4
44+
with:
45+
name: releases
46+
path: dist
47+
48+
upload-to-pypi:
49+
needs: build-artifacts
50+
if: github.event_name == 'release'
51+
runs-on: ubuntu-latest
52+
53+
environment:
54+
name: pypi
55+
url: https://pypi.org/p/pint-xarray
56+
permissions:
57+
id-token: write
58+
59+
steps:
60+
- uses: actions/download-artifact@v4
61+
with:
62+
name: releases
63+
path: dist
64+
- name: Publish package to PyPI
2865
uses: pypa/gh-action-pypi-publish@81e9d935c883d0b210363ab89cf05f3894778450
2966
with:
30-
user: __token__
31-
password: ${{ secrets.pypi_password }}
32-
repository_url: https://upload.pypi.org/legacy/
67+
verbose: true

Diff for: .pre-commit-config.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ repos:
1919
- repo: https://github.com/psf/black
2020
rev: 24.4.2
2121
hooks:
22-
- id: black
2322
- id: black-jupyter
2423
- repo: https://github.com/keewis/blackdoc
2524
rev: v0.3.9

0 commit comments

Comments
 (0)