Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish library to pypi with OIDC #763

Merged
merged 2 commits into from
Mar 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 48 additions & 8 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ on:
required: true

jobs:
deploy:

release-build:
runs-on: ubuntu-latest

permissions:
issues: write
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -40,13 +40,15 @@ jobs:
VERSION=${VERSION#v}
echo "VERSION=$VERSION" >> $GITHUB_ENV
python tools/update_version.py $VERSION
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_API_USER }}
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
- name: Build
run: |
python setup.py sdist bdist_wheel
twine upload dist/*

- name: upload artifact
uses: actions/upload-artifact@v4
with:
name: release-dists
path: dist/

- name: Create GitHub Issue on Failure
if: failure()
Expand All @@ -66,3 +68,41 @@ jobs:
body: issueBody,
assignees
});

pypi-publish:
runs-on: ubuntu-latest
needs:
- release-build
environment:
name: release
permissions:
id-token: write
issues: write

steps:
- name: Retrieve release distributions
uses: actions/download-artifact@v4
with:
name: release-dists
path: dist/

- name: Publish release distributions to PyPI
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4

- name: Create GitHub Issue on Failure
if: failure()
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const issueTitle = `Release job for failed`;
const issueBody = `The release job failed. Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details.`;
const assignees = [context.actor];

await github.rest.issues.create({
owner,
repo,
title: issueTitle,
body: issueBody,
assignees
});