Skip to content

Commit 440f657

Browse files
committed
NO-ISSUE Use OIDC to publish library to pypi
1 parent 7e52a51 commit 440f657

File tree

1 file changed

+49
-8
lines changed

1 file changed

+49
-8
lines changed

.github/workflows/publish-to-pypi.yml

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ on:
1313
required: true
1414

1515
jobs:
16-
deploy:
17-
16+
release-build:
1817
runs-on: ubuntu-latest
19-
18+
permissions:
19+
issues: write
2020
steps:
2121
- uses: actions/checkout@v4
2222
with:
@@ -40,13 +40,15 @@ jobs:
4040
VERSION=${VERSION#v}
4141
echo "VERSION=$VERSION" >> $GITHUB_ENV
4242
python tools/update_version.py $VERSION
43-
- name: Build and publish
44-
env:
45-
TWINE_USERNAME: ${{ secrets.PYPI_API_USER }}
46-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
43+
- name: Build
4744
run: |
4845
python setup.py sdist bdist_wheel
49-
twine upload dist/*
46+
47+
- name: upload artifact
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: release-dists
51+
path: dist/
5052

5153
- name: Create GitHub Issue on Failure
5254
if: failure()
@@ -66,3 +68,42 @@ jobs:
6668
body: issueBody,
6769
assignees
6870
});
71+
72+
pypi-publish:
73+
runs-on: ubuntu-latest
74+
needs:
75+
- release-build
76+
environment:
77+
name: release
78+
permissions:
79+
id-token: write
80+
issues: write
81+
82+
steps:
83+
- name: Retrieve release distributions
84+
uses: actions/download-artifact@v4
85+
with:
86+
name: release-dists
87+
path: dist/
88+
89+
- name: Publish release distributions to PyPI
90+
uses: pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc # v1.12.4
91+
92+
- name: Create GitHub Issue on Failure
93+
if: failure()
94+
uses: actions/github-script@v7
95+
with:
96+
script: |
97+
const { owner, repo } = context.repo;
98+
const version = process.env.VERSION;
99+
const issueTitle = `Release job for ${version} failed`;
100+
const issueBody = `The release job failed. Please check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details.`;
101+
const assignees = [context.actor];
102+
103+
await github.rest.issues.create({
104+
owner,
105+
repo,
106+
title: issueTitle,
107+
body: issueBody,
108+
assignees
109+
});

0 commit comments

Comments
 (0)