Skip to content

Commit 1558dfe

Browse files
committed
Migrate to Trusted Publishing (pypi)
1 parent 039af0e commit 1558dfe

File tree

3 files changed

+52
-37
lines changed

3 files changed

+52
-37
lines changed

.github/workflows/merge.yml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ on:
1313
types: closed
1414
branches:
1515
- main
16-
- async
1716

1817
jobs:
1918
publishing:
2019
name: Build and publish Python 🐍 distributions 📦 to PyPI
2120
runs-on: ubuntu-latest
21+
environment: pypi
22+
permissions:
23+
id-token: write
2224
# Only trigger on merges, not just closes
2325
if: github.event.pull_request.merged == true
2426
steps:
@@ -29,16 +31,15 @@ jobs:
2931
uses: actions/setup-python@v5
3032
with:
3133
python-version: ${{ env.DEFAULT_PYTHON }}
32-
- name: Install pypa/build
33-
run: >-
34-
python3 -m
35-
pip install
36-
build
37-
--user
38-
- name: Build a binary wheel and a source tarball
39-
run: python3 -m build
34+
- name: Prepare uv
35+
run: |
36+
pip install uv
37+
uv venv --seed venv
38+
- name: Build
39+
run: |
40+
. venv/bin/activate
41+
uv build
4042
- name: Publish distribution 📦 to PyPI
41-
uses: pypa/gh-action-pypi-publish@release/v1
42-
with:
43-
password: ${{ secrets.pypi_token }}
44-
skip_existing: true
43+
run: |
44+
. venv/bin/activate
45+
uv publish

.github/workflows/verify.yml

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ jobs:
273273
test-publishing:
274274
name: Build and publish Python 🐍 distributions 📦 to TestPyPI
275275
runs-on: ubuntu-latest
276+
environment: testpypi
277+
permissions:
278+
id-token: write
276279
needs:
277280
- cache
278281
- prepare
@@ -281,34 +284,41 @@ jobs:
281284
steps:
282285
- name: Check out committed code
283286
uses: actions/checkout@v4
284-
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
285-
id: python
286-
uses: actions/setup-python@v5
287-
with:
288-
python-version: ${{ env.DEFAULT_PYTHON }}
289-
- name: Create or reuse cache
290-
id: cache-reuse
291-
uses: ./.github/actions/restore-venv
292-
with:
293-
cache-key: ${{ needs.cache.outputs.cache-key }}
294-
python-version: ${{ steps.python.outputs.python-version }}
295-
venv-dir: ${{ env.VENV }}
296-
precommit-home: ${{ env.PRE_COMMIT_HOME }}
297-
- name: Install pypa/build
287+
- name: Prepare uv
298288
run: |
289+
pip install uv
290+
uv venv --seed venv
299291
. venv/bin/activate
300-
uv pip install build
301-
- name: Build a binary wheel and a source tarball
292+
uv pip install toml
293+
- name: Check for existing package on TestPyPI
294+
id: check_package
302295
run: |
303296
. venv/bin/activate
304-
python3 -m build
305-
- name: Publish distribution 📦 to Test PyPI
306-
uses: pypa/gh-action-pypi-publish@release/v1
307-
continue-on-error: true
308-
with:
309-
password: ${{ secrets.testpypi_token }}
310-
repository_url: https://test.pypi.org/legacy/
311-
skip_existing: true
297+
PACKAGE_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
298+
PACKAGE_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])")
299+
300+
# Use jq to check for the version in the releases object
301+
EXISTING_VERSIONS=$(curl -s "https://test.pypi.org/pypi/$PACKAGE_NAME/json" | jq '.releases | keys[]')
302+
303+
echo "Checking for package: $PACKAGE_NAME==$PACKAGE_VERSION"
304+
305+
if [[ "$EXISTING_VERSIONS" =~ "$PACKAGE_VERSION" ]]; then
306+
echo "Package version already exists. Skipping upload."
307+
echo "should_publish=false" >> $GITHUB_OUTPUT
308+
else
309+
echo "Package version does not exist. Proceeding with upload."
310+
echo "should_publish=true" >> $GITHUB_OUTPUT
311+
fi
312+
- name: Build
313+
if: steps.check_package.outputs.should_publish == 'true'
314+
run: |
315+
. venv/bin/activate
316+
uv build
317+
- name: Publish distribution 📦 to TestPyPI
318+
if: steps.check_package.outputs.should_publish == 'true'
319+
run: |
320+
. venv/bin/activate
321+
uv publish --publish-url https://test.pypi.org/legacy/
312322
313323
complexity:
314324
name: Process test complexity

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Ongoing / v0.44.8a0
4+
5+
- Chores move module publishing on (test)pypi to Trusted Publishing (and using uv) - released as alpha 0.44.8a0 to demonstrate functionality
6+
37
## v0.44.7 - 2025-07-08
48

59
- PR [282](https://github.com/plugwise/python-plugwise-usb/pull/282): Finalize switch implementation

0 commit comments

Comments
 (0)