| 1 |
--- |
| 2 |
name: release python |
| 3 |
|
| 4 |
on: |
| 5 |
push: |
| 6 |
branches: [master] |
| 7 |
tags: |
| 8 |
- '**' |
| 9 |
workflow_dispatch: |
| 10 |
inputs: |
| 11 |
tag: |
| 12 |
description: 'Tag to check out' |
| 13 |
required: false |
| 14 |
|
| 15 |
jobs: |
| 16 |
build_sdist: |
| 17 |
name: Build source distribution |
| 18 |
runs-on: ubuntu-latest |
| 19 |
env: |
| 20 |
PYTHON_VERSION: "3.10" |
| 21 |
container: |
| 22 |
image: ghcr.io/linux-nvme/debian.python:latest |
| 23 |
steps: |
| 24 |
- uses: actions/checkout@v5 |
| 25 |
|
| 26 |
- name: Allow workspace |
| 27 |
run: | |
| 28 |
git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 29 |
|
| 30 |
- name: Build sdist |
| 31 |
run: | |
| 32 |
pipx run build --sdist |
| 33 |
|
| 34 |
- name: Validate sdist |
| 35 |
run: | |
| 36 |
pipx run twine check dist/*.tar.gz |
| 37 |
|
| 38 |
- uses: actions/upload-artifact@v5 |
| 39 |
with: |
| 40 |
path: dist/*.tar.gz |
| 41 |
retention-days: 5 |
| 42 |
|
| 43 |
build_test_sdist: |
| 44 |
name: Build test source distribution |
| 45 |
runs-on: ubuntu-latest |
| 46 |
env: |
| 47 |
PYTHON_VERSION: "3.10" |
| 48 |
container: |
| 49 |
image: ghcr.io/linux-nvme/debian.python:latest |
| 50 |
steps: |
| 51 |
- name: Check out repository (with tags) |
| 52 |
uses: actions/checkout@v5 |
| 53 |
with: |
| 54 |
fetch-depth: 0 # Required for `git describe` |
| 55 |
|
| 56 |
- name: Allow workspace |
| 57 |
run: | |
| 58 |
git config --global --add safe.directory "$GITHUB_WORKSPACE" |
| 59 |
|
| 60 |
- name: Compute dev version from git |
| 61 |
id: version |
| 62 |
run: | |
| 63 |
TAG=$(git describe --tags --abbrev=0) |
| 64 |
REV=$(git rev-list "$TAG"..HEAD --count) |
| 65 |
BASE_VERSION="${TAG#v}" |
| 66 |
VERSION="${BASE_VERSION}.dev${REV}" |
| 67 |
echo "dev_version=$VERSION" >> $GITHUB_OUTPUT |
| 68 |
echo "Computed dev version: $VERSION" |
| 69 |
|
| 70 |
- name: Patch version in meson.build |
| 71 |
run: | |
| 72 |
sed -i -e "0,/[ \t]version: /s/\([ \t]version: \).*/\1\'${{ steps.version.outputs.dev_version }}\',/" meson.build |
| 73 |
|
| 74 |
- name: Build sdist |
| 75 |
run: | |
| 76 |
pipx run build --sdist |
| 77 |
|
| 78 |
- name: Validate sdist |
| 79 |
run: | |
| 80 |
pipx run twine check dist/*.tar.gz |
| 81 |
|
| 82 |
- uses: actions/upload-artifact@v5 |
| 83 |
with: |
| 84 |
name: test_pypi |
| 85 |
path: dist/*.tar.gz |
| 86 |
retention-days: 5 |
| 87 |
|
| 88 |
upload_test_pypi: |
| 89 |
needs: [build_test_sdist] |
| 90 |
runs-on: ubuntu-latest |
| 91 |
env: |
| 92 |
PYTHON_VERSION: "3.10" |
| 93 |
environment: pypi |
| 94 |
permissions: |
| 95 |
id-token: write |
| 96 |
if: github.repository == 'linux-nvme/libnvme' |
| 97 |
steps: |
| 98 |
- uses: actions/download-artifact@v6 |
| 99 |
with: |
| 100 |
name: test_pypi |
| 101 |
path: dist |
| 102 |
|
| 103 |
- name: Publish package to TestPyPI |
| 104 |
uses: pypa/[email protected] |
| 105 |
with: |
| 106 |
repository-url: https://test.pypi.org/legacy/ |
| 107 |
|
| 108 |
upload_pypi: |
| 109 |
needs: [build_sdist] |
| 110 |
runs-on: ubuntu-latest |
| 111 |
env: |
| 112 |
PYTHON_VERSION: "3.10" |
| 113 |
environment: pypi |
| 114 |
permissions: |
| 115 |
id-token: write |
| 116 |
if: startsWith(github.ref, 'refs/tags/v') && github.repository == 'linux-nvme/libnvme' |
| 117 |
steps: |
| 118 |
- name: Check if it is a release tag |
| 119 |
id: check-tag |
| 120 |
run: | |
| 121 |
if [[ ${{ github.event.ref }} =~ ^refs/tags/v([0-9]+\.[0-9]+)(\.[0-9]+)?(-rc[0-9]+)?$ ]]; then |
| 122 |
echo ::set-output name=match::true |
| 123 |
fi |
| 124 |
|
| 125 |
- name: Download artifiact |
| 126 |
uses: actions/download-artifact@v6 |
| 127 |
if: steps.check-tag.outputs.match == 'true' |
| 128 |
with: |
| 129 |
name: artifact |
| 130 |
path: dist |
| 131 |
|
| 132 |
- name: Publish package to PyPI |
| 133 |
uses: pypa/[email protected] |
| 134 |
if: steps.check-tag.outputs.match == 'true' |