From a793831a6ee605394043b3057020cc4df117c9ea Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 22 Apr 2025 16:50:20 +0200 Subject: [PATCH 1/2] build: upload unique pypi test versions PyPi doesn't allow to overwrite existing releases. Thus every single upload needs to unique. Use the git describe to come up with an id. Signed-off-by: Daniel Wagner --- .github/workflows/release-python.yml | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/.github/workflows/release-python.yml b/.github/workflows/release-python.yml index b7f2966ee..318b42795 100644 --- a/.github/workflows/release-python.yml +++ b/.github/workflows/release-python.yml @@ -46,11 +46,46 @@ jobs: permissions: id-token: write steps: + - name: Check out repository (with tags) + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Required for `git describe` + + - name: Allow workspace + run: git config --global --add safe.directory "$GITHUB_WORKSPACE" + - uses: actions/download-artifact@v4 with: name: artifact path: dist + - name: Extract sdist for patching + run: | + mkdir sdist && tar -xzf dist/*.tar.gz -C sdist --strip-components=1 + + - name: Compute dev version from git + id: version + run: | + TAG=$(git describe --tags --abbrev=0) + REV=$(git rev-list "$TAG"..HEAD --count) + BASE_VERSION="${TAG#v}" + VERSION="${BASE_VERSION}.dev${REV}" + echo "dev_version=$VERSION" >> $GITHUB_OUTPUT + echo "Computed dev version: $VERSION" + + - name: Patch version in pyproject.toml + run: | + sed -i "s/^version = .*/version = \"${{ steps.version.outputs.dev_version }}\"/" sdist/pyproject.toml + + - name: Rebuild sdist with dev version + run: | + cd sdist + pipx run build --sdist + mv dist/*.tar.gz ../dist/ + + - name: Validate rebuilt sdist + run: pipx run twine check dist/*.tar.gz + - name: Publish package to TestPyPI uses: pypa/gh-action-pypi-publish@v1.12.4 with: From 607e7bdcd2a23390c880c30eaf95a1040384112c Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Tue, 22 Apr 2025 16:58:19 +0200 Subject: [PATCH 2/2] build: add cleanup task for pypi test uploads Be nice with upstream and remove old test uploads. Signed-off-by: Daniel Wagner --- .github/workflows/cleanup-python.yml | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/cleanup-python.yml diff --git a/.github/workflows/cleanup-python.yml b/.github/workflows/cleanup-python.yml new file mode 100644 index 000000000..3bcac75e1 --- /dev/null +++ b/.github/workflows/cleanup-python.yml @@ -0,0 +1,35 @@ +name: Cleanup dev versions on TestPyPI + +on: + workflow_dispatch: + inputs: + keep-last: + description: "How many recent dev releases to keep" + required: false + default: "5" + dry-run: + description: "Only simulate the deletion (true/false)" + required: false + default: "true" + +jobs: + cleanup: + runs-on: ubuntu-latest + environment: pypi + steps: + - name: Install pypi-cleanup + run: pip install pypi-cleanup + + - name: Run pypi-cleanup on TestPyPI + env: + PYPI_USERNAME: __token__ + PYPI_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }} + run: | + pypi-cleanup \ + --username "$PYPI_USERNAME" \ + --password "$PYPI_PASSWORD" \ + --repository-url https://test.pypi.org/legacy/ \ + --project libnvme \ + --keep ${{ github.event.inputs.keep-last }} \ + --version-regex '.*\.dev[0-9]+' \ + $([ "${{ github.event.inputs.dry-run }}" == "true" ] && echo "--dry-run")