Skip to content

Commit

Permalink
use trusted publishers to publish to PyPI (#261)
Browse files Browse the repository at this point in the history
* use trusted publishers to publish

* remove the redundant `black` hook
  • Loading branch information
keewis authored Jun 22, 2024
1 parent f615a3f commit 4244ca4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
61 changes: 48 additions & 13 deletions .github/workflows/pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,66 @@ name: Upload Package to PyPI

on:
release:
types: [created]
types:
- published

jobs:
deploy:
build-artifacts:
runs-on: ubuntu-latest
if: github.repository == 'xarray-contrib/pint-xarray'
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
fetch-depth: 0

- uses: actions/setup-python@v5
name: Install Python
with:
python-version: "3.x"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build twine
- name: Build
- name: Build tarball and wheels
run: |
python -m build --sdist --wheel --outdir dist/ .
- name: Check the built archives
git clean -xdf
git restore -SW .
python -m build --outdir dist/ .
- name: Check built artifacts
run: |
twine check dist/*
- name: Publish to PyPI
python -m twine check --strict dist/*
pwd
if [ -f dist/pint-xarray-0.0.0.tar.gz ]; then
echo "❌ INVALID VERSION NUMBER"
exit 1
else
echo "✅ Looks good"
fi
- uses: actions/upload-artifact@v4
with:
name: releases
path: dist

upload-to-pypi:
needs: build-artifacts
if: github.event_name == 'release'
runs-on: ubuntu-latest

environment:
name: pypi
url: https://pypi.org/p/pint-xarray
permissions:
id-token: write

steps:
- uses: actions/download-artifact@v4
with:
name: releases
path: dist
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@81e9d935c883d0b210363ab89cf05f3894778450
with:
user: __token__
password: ${{ secrets.pypi_password }}
repository_url: https://upload.pypi.org/legacy/
verbose: true
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ repos:
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
- id: black-jupyter
- repo: https://github.com/keewis/blackdoc
rev: v0.3.9
Expand Down

0 comments on commit 4244ca4

Please sign in to comment.