Skip to content

Commit 39675f4

Browse files
authored
Merge pull request #944 from PowerGridModel/add-trusted-publisher-management-pypi
Add trusted publisher management in PyPI
2 parents 4a17de8 + d56f18b commit 39675f4

File tree

6 files changed

+65
-97
lines changed

6 files changed

+65
-97
lines changed

.github/workflows/build-test-release.yml

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ on:
1313
type: boolean
1414
description: Create a (pre-)release when CI passes
1515
required: true
16-
secrets:
17-
PYPI_USER:
18-
required: true
19-
PYPI_PASS:
20-
required: true
2116
# run this workflow manually from the Actions tab
2217
workflow_dispatch:
2318
inputs:
@@ -44,12 +39,13 @@ jobs:
4439
python-version: "3.12"
4540

4641
- name: Set PyPI Version
47-
run: |
48-
pip install requests build
49-
python set_pypi_version.py
42+
uses: PowerGridModel/pgm-version-bump@main
5043

5144
- name: Build SDist
52-
run: python -m build --sdist --outdir wheelhouse .
45+
run: |
46+
cat PYPI_VERSION
47+
pip install build
48+
python -m build --sdist --outdir wheelhouse .
5349
5450
- name: Keep version file
5551
uses: actions/upload-artifact@v4
@@ -283,16 +279,14 @@ jobs:
283279
- name: Test
284280
run: pytest
285281

286-
publish-wheels:
282+
github-release:
283+
name: Create and release assets to GitHub
287284
needs: [build-cpp-test-linux, build-cpp-test-windows, build-cpp-test-macos, build-and-test-python, build-and-test-conda]
288285
# always run publish job but fail at the first step if previous jobs have been failed
289286
if: always()
290-
runs-on: ubuntu-24.04
287+
runs-on: ubuntu-latest
291288
permissions:
292289
contents: write
293-
env:
294-
TWINE_USERNAME: ${{ secrets.PYPI_USER }}
295-
TWINE_PASSWORD: ${{ secrets.PYPI_PASS }}
296290

297291
steps:
298292
- name: Fail fast
@@ -329,14 +323,7 @@ jobs:
329323
- name: Display tag
330324
run: echo "${{ steps.tag.outputs.tag }}"
331325

332-
- name: Upload wheels
333-
if: (inputs.create_release)
334-
run: |
335-
pip install twine
336-
echo "Publish to PyPI..."
337-
twine upload --verbose wheelhouse/*
338-
339-
- name: Release
326+
- name: Create GitHub release
340327
uses: softprops/action-gh-release@v2
341328
if: (inputs.create_release)
342329
with:

.github/workflows/ci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ jobs:
4343
# create_release becomes true if the event that triggered this workflow is "push" on main
4444
# otherwise create_release becomes false
4545
create_release: ${{ (github.event_name == 'workflow_dispatch' && inputs.create_release) || github.event_name == 'push'}}
46-
secrets:
47-
PYPI_USER: ${{ secrets.PYPI_USER }}
48-
PYPI_PASS: ${{ secrets.PYPI_PASS }}
4946

5047
check-code-quality:
5148
uses: "./.github/workflows/check-code-quality.yml"

.github/workflows/nightly.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ jobs:
2121
contents: write
2222
with:
2323
create_release: false
24-
secrets:
25-
PYPI_USER: user
26-
PYPI_PASS: pass
2724

2825
check-code-quality:
2926
uses: "./.github/workflows/check-code-quality.yml"

.github/workflows/publish-pypi.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-FileCopyrightText: Contributors to the Power Grid Model project <powergridmodel@lfenergy.org>
2+
#
3+
# SPDX-License-Identifier: MPL-2.0
4+
5+
name: Publish to PyPI
6+
7+
on:
8+
release:
9+
types: [published]
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: write
14+
id-token: write # Required for Trusted Publishing
15+
16+
jobs:
17+
publish:
18+
name: Publish to PyPI
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Download assets from GitHub release
23+
uses: robinraju/release-downloader@v1
24+
with:
25+
repository: ${{ github.repository }}
26+
# download the latest release
27+
latest: true
28+
# don't donwload pre-releases
29+
preRelease: false
30+
fileName: "*"
31+
# don't download GitHub-generated source tar and zip files
32+
tarBall: false
33+
zipBall: false
34+
# create a directory to store the downloaded assets
35+
out-file-path: assets-to-publish
36+
# don't extract downloaded files
37+
extract: false
38+
39+
- name: List downloaded assets
40+
run: ls -la assets-to-publish
41+
42+
- name: Upload assets to PyPI
43+
uses: pypa/gh-action-pypi-publish@release/v1
44+
with:
45+
# To test, use the TestPyPI:
46+
# repository-url: https://test.pypi.org/legacy/
47+
# You must also create an account and project on TestPyPI,
48+
# as well as set the trusted-publisher in the project settings:
49+
# https://docs.pypi.org/trusted-publishers/adding-a-publisher/
50+
# To publish to the official PyPI repository, just keep
51+
# repository-url commented out.
52+
packages-dir: assets-to-publish
53+
skip-existing: true
54+
print-hash: true
55+
verbose: true

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ authors = [
2020
]
2121
description = "Python/C++ library for distribution power system analysis"
2222
readme = "README.md"
23-
license = { text = "MPL-2.0" }
23+
license = "MPL-2.0"
2424
classifiers = [
2525
"Programming Language :: Python :: 3",
2626
"Programming Language :: Python :: Implementation :: CPython",
2727
"Programming Language :: C++",
2828
"Development Status :: 5 - Production/Stable",
2929
"Intended Audience :: Developers",
3030
"Intended Audience :: Science/Research",
31-
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)",
3231
"Operating System :: Microsoft :: Windows",
3332
"Operating System :: POSIX :: Linux",
3433
"Operating System :: MacOS",

set_pypi_version.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)