|
| 1 | +# Build and publish to PyPI on GitHub release creation or manual trigger. |
| 2 | +# Uses OIDC trusted publishing — no stored PyPI token required. |
| 3 | +# Pure Python package — a universal wheel suffices; no cibuildwheel needed. |
| 4 | + |
| 5 | +name: Release |
| 6 | + |
| 7 | +on: |
| 8 | + release: |
| 9 | + types: [created] |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +env: |
| 13 | + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true |
| 14 | + |
| 15 | +jobs: |
| 16 | + verify_version: |
| 17 | + name: Verify tag matches package version |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v6 |
| 21 | + - name: Check version |
| 22 | + # Skip check on manual workflow_dispatch runs (no release tag exists) |
| 23 | + if: github.event_name == 'release' |
| 24 | + run: | |
| 25 | + TAG="${GITHUB_REF_NAME#v}" |
| 26 | + PKG=$(python3 -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])") |
| 27 | + echo "Tag version : $TAG" |
| 28 | + echo "Package version: $PKG" |
| 29 | + [ "$TAG" = "$PKG" ] || { echo "ERROR: tag v$TAG does not match pyproject.toml version $PKG"; exit 1; } |
| 30 | +
|
| 31 | + build: |
| 32 | + name: Build sdist and wheel |
| 33 | + needs: verify_version |
| 34 | + runs-on: ubuntu-latest |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v6 |
| 37 | + |
| 38 | + - uses: actions/setup-python@v6 |
| 39 | + with: |
| 40 | + python-version: "3.12" |
| 41 | + |
| 42 | + - name: Build sdist and wheel |
| 43 | + run: pipx run build |
| 44 | + |
| 45 | + - uses: actions/upload-artifact@v4 |
| 46 | + with: |
| 47 | + name: dist |
| 48 | + path: dist/ |
| 49 | + |
| 50 | + smoke_test: |
| 51 | + name: Smoke-test wheel |
| 52 | + needs: build |
| 53 | + runs-on: ubuntu-latest |
| 54 | + steps: |
| 55 | + - uses: actions/setup-python@v6 |
| 56 | + with: |
| 57 | + python-version: "3.12" |
| 58 | + |
| 59 | + - uses: actions/download-artifact@v4 |
| 60 | + with: |
| 61 | + name: dist |
| 62 | + path: dist |
| 63 | + |
| 64 | + - name: Install wheel (pulls deps from PyPI) |
| 65 | + run: pip install --find-links dist machinevision-toolbox-python |
| 66 | + |
| 67 | + - name: Smoke test |
| 68 | + run: python -c "import machinevisiontoolbox; print('OK', machinevisiontoolbox.__version__)" |
| 69 | + |
| 70 | + upload_pypi: |
| 71 | + name: Publish to PyPI |
| 72 | + needs: [build, smoke_test] |
| 73 | + runs-on: ubuntu-latest |
| 74 | + environment: pypi |
| 75 | + permissions: |
| 76 | + id-token: write # required for OIDC trusted publishing |
| 77 | + steps: |
| 78 | + - uses: actions/download-artifact@v4 |
| 79 | + with: |
| 80 | + name: dist |
| 81 | + path: dist |
| 82 | + |
| 83 | + - uses: pypa/gh-action-pypi-publish@release/v1 |
| 84 | + with: |
| 85 | + skip_existing: true |
0 commit comments