Skip to content

Commit e8be5d9

Browse files
authored
Merge pull request #770 from plugwise/tp
Add trusted publishing (while using uv)
2 parents fe99d21 + 2193a38 commit e8be5d9

File tree

4 files changed

+83
-42
lines changed

4 files changed

+83
-42
lines changed

.github/workflows/merge.yml

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,47 @@ jobs:
1818
publishing:
1919
name: Build and publish Python 🐍 distributions 📦 to PyPI
2020
runs-on: ubuntu-latest
21+
environment: pypi
22+
permissions:
23+
contents: read # Required by actions/checkout
24+
id-token: write # Needed for OIDC-based Trusted Publishing
2125
# Only trigger on merges, not just closes
2226
if: github.event.pull_request.merged == true
2327
steps:
2428
- name: Check out committed code
2529
uses: actions/checkout@v4
26-
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
27-
id: python
28-
uses: actions/setup-python@v5
29-
with:
30-
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
30+
- name: Prepare uv
31+
run: |
32+
pip install uv
33+
uv venv --seed venv
34+
. venv/bin/activate
35+
uv pip install toml
36+
- name: Check for existing package on PyPI
37+
id: check_package
38+
run: |
39+
. venv/bin/activate
40+
PACKAGE_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
41+
PACKAGE_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])")
42+
43+
# Use jq to check for the version in the releases object
44+
EXISTING_VERSIONS=$(curl -s "https://pypi.org/pypi/$PACKAGE_NAME/json" | jq '.releases | keys[]')
45+
46+
echo "Checking for package: $PACKAGE_NAME==$PACKAGE_VERSION"
47+
48+
if [[ "$EXISTING_VERSIONS" =~ "$PACKAGE_VERSION" ]]; then
49+
echo "Package version already exists. Skipping upload."
50+
echo "should_publish=false" >> $GITHUB_OUTPUT
51+
else
52+
echo "Package version does not exist. Proceeding with upload."
53+
echo "should_publish=true" >> $GITHUB_OUTPUT
54+
fi
55+
- name: Build
56+
if: steps.check_package.outputs.should_publish == 'true'
57+
run: |
58+
. venv/bin/activate
59+
uv build
3960
- 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
61+
if: steps.check_package.outputs.should_publish == 'true'
62+
run: |
63+
. venv/bin/activate
64+
uv publish

.github/workflows/verify.yml

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
ruff:
5858
runs-on: ubuntu-latest
5959
name: Ruff check and force
60-
needs:
60+
needs:
6161
- cache
6262
- prepare
6363
steps:
@@ -126,7 +126,7 @@ jobs:
126126
pytest:
127127
runs-on: ubuntu-latest
128128
name: Run pytest using Python ${{ matrix.python-version }}
129-
needs:
129+
needs:
130130
- cache
131131
- prepare
132132
- commitcheck
@@ -159,7 +159,7 @@ jobs:
159159
mypy:
160160
runs-on: ubuntu-latest
161161
name: Run mypy
162-
needs:
162+
needs:
163163
- cache
164164
- prepare
165165
- pytest
@@ -205,7 +205,7 @@ jobs:
205205
coverage:
206206
name: Process test coverage
207207
runs-on: ubuntu-latest
208-
needs:
208+
needs:
209209
- cache
210210
- prepare
211211
- pytest
@@ -237,6 +237,10 @@ jobs:
237237
test-publishing:
238238
name: Build and publish Python 🐍 distributions 📦 to TestPyPI
239239
runs-on: ubuntu-latest
240+
environment: testpypi
241+
permissions:
242+
contents: read # Required by actions/checkout
243+
id-token: write # Needed for OIDC-based Trusted Publishing
240244
needs:
241245
- cache
242246
- prepare
@@ -245,34 +249,46 @@ jobs:
245249
steps:
246250
- name: Check out committed code
247251
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
252+
- name: Prepare uv
257253
run: |
254+
pip install uv
255+
uv venv --seed venv
258256
. venv/bin/activate
259-
uv pip install build
260-
- name: Build a binary wheel and a source tarball
257+
uv pip install toml
258+
- name: Check for existing package on TestPyPI
259+
id: check_package
261260
run: |
262261
. 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
262+
PACKAGE_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])")
263+
PACKAGE_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])")
264+
265+
# Use jq to check for the version in the releases object
266+
EXISTING_VERSIONS=$(curl -s "https://test.pypi.org/pypi/$PACKAGE_NAME/json" | jq '.releases | keys[]')
267+
268+
echo "Checking for package: $PACKAGE_NAME==$PACKAGE_VERSION"
269+
270+
if [[ "$EXISTING_VERSIONS" =~ "$PACKAGE_VERSION" ]]; then
271+
echo "Package version already exists. Skipping upload."
272+
echo "should_publish=false" >> $GITHUB_OUTPUT
273+
else
274+
echo "Package version does not exist. Proceeding with upload."
275+
echo "should_publish=true" >> $GITHUB_OUTPUT
276+
fi
277+
- name: Build
278+
if: steps.check_package.outputs.should_publish == 'true'
279+
run: |
280+
. venv/bin/activate
281+
uv build
282+
- name: Publish distribution 📦 to TestPyPI
283+
if: steps.check_package.outputs.should_publish == 'true'
284+
run: |
285+
. venv/bin/activate
286+
uv publish --publish-url https://test.pypi.org/legacy/
271287
272288
complexity:
273289
name: Process test complexity
274290
runs-on: ubuntu-latest
275-
needs:
291+
needs:
276292
- cache
277293
- prepare
278294
- coverage

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 / 1.7.8a0+1
4+
5+
- Chores move module publishing on (test)pypi to Trusted Publishing (and using uv) - released as alpha 1.7.8a0+1 to demonstrate functionality
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)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "plugwise"
7-
version = "1.7.7"
7+
version = "1.7.8a1"
88
license = "MIT"
99
description = "Plugwise Smile (Adam/Anna/P1) and Stretch module for Python 3."
1010
readme = "README.md"

0 commit comments

Comments
 (0)