Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/cleanup-python.yml
Original file line number Diff line number Diff line change
@@ -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")
35 changes: 35 additions & 0 deletions .github/workflows/release-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
Expand Down