From 0213361875e4fca959d0613d3cd39c8b7a09f22f Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Tue, 1 Sep 2026 23:39:04 +1000 Subject: [PATCH 1/9] add gha for publishing --- .github/workflows/release.yml | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100755 index 0000000..68eea99 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,53 @@ +name: Release + +on: + push: + tags: + - 'v*.*.*' + + workflow_dispatch: + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v5 + + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: '3.12' + + - name: Install build + run: pip install build + + - name: Build distributions + run: python -m build + + - name: Upload distributions + uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/ + + publish: + name: Publish to PyPI + needs: build + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + environment: pypi + permissions: + id-token: write + steps: + - name: Download distributions + uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 From 90cfe885941a9e2274fb5bba90c4542a2fa90e00 Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Wed, 2 Sep 2026 21:46:08 +1000 Subject: [PATCH 2/9] publish to test.pypi --- .github/workflows/release.yml | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 68eea99..f9efb1a 100755 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,11 +34,11 @@ jobs: name: dist path: dist/ - publish: + publish-pypi: name: Publish to PyPI needs: build runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') + if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-rc') environment: pypi permissions: id-token: write @@ -51,3 +51,23 @@ jobs: - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + + publish-testpypi: + name: Publish to TestPyPI + needs: build + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-rc') + environment: testpypi + permissions: + id-token: write + steps: + - name: Download distributions + uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ + + - name: Publish to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ From c371ca75b6de89c11dba564ceb0a4d1f368211d0 Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Thu, 3 Sep 2026 13:14:30 +1000 Subject: [PATCH 3/9] disable publish to prod --- .github/workflows/release.yml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f9efb1a..d0f83dc 100755 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,23 +34,23 @@ jobs: name: dist path: dist/ - publish-pypi: - name: Publish to PyPI - needs: build - runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-rc') - environment: pypi - permissions: - id-token: write - steps: - - name: Download distributions - uses: actions/download-artifact@v4 - with: - name: dist - path: dist/ + # publish-pypi: + # name: Publish to PyPI + # needs: build + # runs-on: ubuntu-latest + # if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-rc') + # environment: pypi + # permissions: + # id-token: write + # steps: + # - name: Download distributions + # uses: actions/download-artifact@v4 + # with: + # name: dist + # path: dist/ - - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 + # - name: Publish to PyPI + # uses: pypa/gh-action-pypi-publish@release/v1 publish-testpypi: name: Publish to TestPyPI From 0ead91e6018f63cd4a129252f102a231c29f230a Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Thu, 3 Sep 2026 13:15:20 +1000 Subject: [PATCH 4/9] only disable the publish to prod step --- .github/workflows/release.yml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d0f83dc..375bca5 100755 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,20 +34,20 @@ jobs: name: dist path: dist/ - # publish-pypi: - # name: Publish to PyPI - # needs: build - # runs-on: ubuntu-latest - # if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-rc') - # environment: pypi - # permissions: - # id-token: write - # steps: - # - name: Download distributions - # uses: actions/download-artifact@v4 - # with: - # name: dist - # path: dist/ + publish-pypi: + name: Publish to PyPI + needs: build + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-rc') + environment: pypi + permissions: + id-token: write + steps: + - name: Download distributions + uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ # - name: Publish to PyPI # uses: pypa/gh-action-pypi-publish@release/v1 From e3ccf006cd7feb8641caab9ab90af074a0166ed4 Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Sun, 6 Sep 2026 15:10:52 +1000 Subject: [PATCH 5/9] Bump version to 2.2.1rc2 for TestPyPI publish The previous rc1 tag built version 2.2.0 (unchanged from __init__.py), which already existed on TestPyPI and was rejected as a duplicate filename. --- src/powersensor_local/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/powersensor_local/__init__.py b/src/powersensor_local/__init__.py index a27a2ed..f2943f7 100644 --- a/src/powersensor_local/__init__.py +++ b/src/powersensor_local/__init__.py @@ -44,7 +44,7 @@ 'PowersensorLegacyDevices', 'PowersensorZeroconfDevices', ] -__version__ = "2.2.0" +__version__ = "2.2.1rc2" from .devices import PowersensorDevices, PowersensorLegacyDevices from .legacy_discovery import LegacyDiscovery from .plug_api import PlugApi From 2d6fa9ea4b64a3ca664ef218404fcbd43f995d01 Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Sun, 6 Sep 2026 15:24:58 +1000 Subject: [PATCH 6/9] re-enable publish to production pypi --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 375bca5..f9efb1a 100755 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -49,8 +49,8 @@ jobs: name: dist path: dist/ - # - name: Publish to PyPI - # uses: pypa/gh-action-pypi-publish@release/v1 + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 publish-testpypi: name: Publish to TestPyPI From a545963d6ce2fc149a64ff2311710b20dd45705f Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Sun, 6 Sep 2026 22:37:27 +1000 Subject: [PATCH 7/9] manual publish via github actions --- .github/workflows/release.yml | 52 +++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f9efb1a..211e802 100755 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,17 +1,33 @@ name: Release on: - push: - tags: - - 'v*.*.*' - workflow_dispatch: + inputs: + publish-destination: + description: 'Publish destination (only main branch can be published to PyPi)' + required: true + default: "test.pypi" + type: choice + options: + - pypi + - test.pypi permissions: contents: read jobs: + publish-check: + runs-on: ubuntu-latest + steps: + - name: Check if branch is main + if: | + (inputs.publish-destination == 'pypi' && github.ref != 'refs/heads/main') + run: | + echo "Only main branch can be published to PyPi." + exit 1 + build: + needs: [publish-check] runs-on: ubuntu-latest steps: - name: Checkout repository @@ -37,8 +53,8 @@ jobs: publish-pypi: name: Publish to PyPI needs: build + if: inputs.publish-destination == 'pypi' runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') && !contains(github.ref, '-rc') environment: pypi permissions: id-token: write @@ -52,11 +68,35 @@ jobs: - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + tag: + name: Create git tag + needs: [publish-pypi] + if: inputs.publish-destination == 'pypi' + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout repository + uses: actions/checkout@v5 + + - name: Determine version + id: version + run: | + VERSION=$(grep -oP '(?<=^__version__ = ")[^"]+' src/powersensor_local/__init__.py) + echo "tag=v$VERSION" >> "$GITHUB_OUTPUT" + + - name: Create and push tag + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag "${{ steps.version.outputs.tag }}" + git push origin "${{ steps.version.outputs.tag }}" + publish-testpypi: name: Publish to TestPyPI needs: build + if: inputs.publish-destination == 'test.pypi' runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-rc') environment: testpypi permissions: id-token: write From 8553713ed8e0810bcdc65880081eb8aa2e589cc6 Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Mon, 7 Sep 2026 14:52:02 +1000 Subject: [PATCH 8/9] change release workflow --- .github/workflows/release.yml | 81 +++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 28 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 211e802..77c1459 100755 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,13 +4,17 @@ on: workflow_dispatch: inputs: publish-destination: - description: 'Publish destination (only main branch can be published to PyPi)' + description: 'Publish destination (main branch only)' required: true default: "test.pypi" type: choice options: - pypi - test.pypi + pypi-tag: + description: 'Git tag to release to PyPI, e.g. v2.2.1 (required when destination is pypi; ignored for test.pypi)' + required: false + type: string permissions: contents: read @@ -19,12 +23,31 @@ jobs: publish-check: runs-on: ubuntu-latest steps: - - name: Check if branch is main - if: | - (inputs.publish-destination == 'pypi' && github.ref != 'refs/heads/main') + - name: Check preconditions run: | - echo "Only main branch can be published to PyPi." - exit 1 + if [ "${{ github.ref }}" != "refs/heads/main" ]; then + echo "This workflow can only be triggered from the main branch." + exit 1 + fi + if [ "${{ inputs.publish-destination }}" = "pypi" ] && [ -z "${{ inputs.pypi-tag }}" ]; then + echo "Please provide the git tag to release to PyPI (e.g. v2.2.1)." + exit 1 + fi + + - name: Checkout repository + if: inputs.publish-destination == 'pypi' + uses: actions/checkout@v5 + with: + fetch-tags: true + fetch-depth: 0 + + - name: Validate PyPI tag + if: inputs.publish-destination == 'pypi' + run: | + if ! git rev-parse -q --verify "refs/tags/${{ inputs.pypi-tag }}" >/dev/null; then + echo "::error::Tag '${{ inputs.pypi-tag }}' was not found in this repository. Check the tag name (e.g. v2.2.1) and try again." + exit 1 + fi build: needs: [publish-check] @@ -32,6 +55,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v5 + with: + ref: ${{ inputs.publish-destination == 'pypi' && inputs.pypi-tag || github.ref_name }} - name: Set up Python uses: actions/setup-python@v6 @@ -68,10 +93,30 @@ jobs: - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 + publish-testpypi: + name: Publish to TestPyPI + needs: build + if: inputs.publish-destination == 'test.pypi' + runs-on: ubuntu-latest + environment: testpypi + permissions: + id-token: write + steps: + - name: Download distributions + uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ + + - name: Publish to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + tag: name: Create git tag - needs: [publish-pypi] - if: inputs.publish-destination == 'pypi' + needs: [publish-testpypi] + if: inputs.publish-destination == 'test.pypi' runs-on: ubuntu-latest permissions: contents: write @@ -91,23 +136,3 @@ jobs: git config user.email "github-actions[bot]@users.noreply.github.com" git tag "${{ steps.version.outputs.tag }}" git push origin "${{ steps.version.outputs.tag }}" - - publish-testpypi: - name: Publish to TestPyPI - needs: build - if: inputs.publish-destination == 'test.pypi' - runs-on: ubuntu-latest - environment: testpypi - permissions: - id-token: write - steps: - - name: Download distributions - uses: actions/download-artifact@v4 - with: - name: dist - path: dist/ - - - name: Publish to TestPyPI - uses: pypa/gh-action-pypi-publish@release/v1 - with: - repository-url: https://test.pypi.org/legacy/ From add773f5ee247de46ad8ae574fcd3267f42b9672 Mon Sep 17 00:00:00 2001 From: Joo Aun Saw Date: Mon, 7 Sep 2026 14:52:18 +1000 Subject: [PATCH 9/9] comment out publish-to-pypi for now --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 77c1459..d072431 100755 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -90,8 +90,8 @@ jobs: name: dist path: dist/ - - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 + # - name: Publish to PyPI + # uses: pypa/gh-action-pypi-publish@release/v1 publish-testpypi: name: Publish to TestPyPI