Skip to content

Commit 36fa9ec

Browse files
committed
Add trusted publishing (while using uv)
1 parent fe99d21 commit 36fa9ec

File tree

3 files changed

+52
-31
lines changed

3 files changed

+52
-31
lines changed

.github/workflows/merge.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ jobs:
1818
publishing:
1919
name: Build and publish Python 🐍 distributions 📦 to PyPI
2020
runs-on: ubuntu-latest
21+
environment: pypi
22+
permissions:
23+
id-token: write
2124
# Only trigger on merges, not just closes
2225
if: github.event.pull_request.merged == true
2326
steps:
@@ -28,16 +31,15 @@ jobs:
2831
uses: actions/setup-python@v5
2932
with:
3033
python-version: ${{ env.DEFAULT_PYTHON }}
31-
- name: Install pypa/build
32-
run: >-
33-
python3 -m
34-
pip install
35-
build
36-
--user
37-
- name: Build a binary wheel and a source tarball
38-
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
3942
- name: Publish distribution 📦 to PyPI
40-
uses: pypa/gh-action-pypi-publish@release/v1
41-
with:
42-
password: ${{ secrets.pypi_token }}
43-
skip-existing: true
43+
run: |
44+
. venv/bin/activate
45+
uv publish

.github/workflows/verify.yml

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ jobs:
237237
test-publishing:
238238
name: Build and publish Python 🐍 distributions 📦 to TestPyPI
239239
runs-on: ubuntu-latest
240+
environment: testpypi
241+
permissions:
242+
id-token: write
240243
needs:
241244
- cache
242245
- prepare
@@ -245,29 +248,41 @@ jobs:
245248
steps:
246249
- name: Check out committed code
247250
uses: actions/checkout@v4
248-
- name: Restore cached environment
249-
id: cache-reuse
250-
uses: plugwise/gh-actions/restore-venv@v1
251-
with:
252-
cache-key: ${{ needs.cache.outputs.cache-key }}
253-
python-version: ${{ env.DEFAULT_PYTHON }}
254-
venv-dir: ${{ env.VENV }}
255-
precommit-home: ${{ env.PRE_COMMIT_HOME }}
256-
- name: Install pypa/build
251+
- name: Prepare uv
257252
run: |
253+
pip install uv
254+
uv venv --seed venv
258255
. venv/bin/activate
259-
uv pip install build
260-
- name: Build a binary wheel and a source tarball
256+
uv pip install toml
257+
- name: Check for existing package on TestPyPI
258+
id: check_package
261259
run: |
262260
. venv/bin/activate
263-
python3 -m build
264-
- name: Publish distribution 📦 to Test PyPI
265-
uses: pypa/gh-action-pypi-publish@release/v1
266-
continue-on-error: true
267-
with:
268-
password: ${{ secrets.testpypi_token }}
269-
repository-url: https://test.pypi.org/legacy/
270-
skip-existing: true
261+
PACKAGE_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
262+
PACKAGE_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])")
263+
264+
# Use jq to check for the version in the releases object
265+
EXISTING_VERSIONS=$(curl -s "https://test.pypi.org/pypi/$PACKAGE_NAME/json" | jq '.releases | keys[]')
266+
267+
echo "Checking for package: $PACKAGE_NAME==$PACKAGE_VERSION"
268+
269+
if [[ "$EXISTING_VERSIONS" =~ "$PACKAGE_VERSION" ]]; then
270+
echo "Package version already exists. Skipping upload."
271+
echo "should_publish=false" >> $GITHUB_OUTPUT
272+
else
273+
echo "Package version does not exist. Proceeding with upload."
274+
echo "should_publish=true" >> $GITHUB_OUTPUT
275+
fi
276+
- name: Build
277+
if: steps.check_package.outputs.should_publish == 'true'
278+
run: |
279+
. venv/bin/activate
280+
uv build
281+
- name: Publish distribution 📦 to TestPyPI
282+
if: steps.check_package.outputs.should_publish == 'true'
283+
run: |
284+
. venv/bin/activate
285+
uv publish --publish-url https://test.pypi.org/legacy/
271286
272287
complexity:
273288
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
4+
5+
- Chores move module publishing on (test)pypi to Trusted Publishing (and using uv)
6+
37
## v1.7.7
48

59
- Implement code quality improvements as suggested by SonarCloud via [#762](https://github.com/plugwise/python-plugwise/pull/762), [#763](https://github.com/plugwise/python-plugwise/pull/763), [#764](https://github.com/plugwise/python-plugwise/pull/764), and [#765](https://github.com/plugwise/python-plugwise/pull/765)

0 commit comments

Comments
 (0)