|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - uses: actions/setup-python@v5 |
| 16 | + with: |
| 17 | + python-version: '3.11' |
| 18 | + |
| 19 | + - name: Clean build artifacts |
| 20 | + run: rm -rf dist build ./*.egg-info |
| 21 | + |
| 22 | + - name: Install dependencies |
| 23 | + run: python -m pip install -e '.[dev]' build twine 'packaging>=24.2' |
| 24 | + |
| 25 | + - name: Verify tag matches package version |
| 26 | + env: |
| 27 | + GITHUB_REF_NAME: ${{ github.ref_name }} |
| 28 | + run: | |
| 29 | + python - <<'PY' |
| 30 | + import os |
| 31 | + from pathlib import Path |
| 32 | +
|
| 33 | + tag = os.environ["GITHUB_REF_NAME"] |
| 34 | + if not tag.startswith("v"): |
| 35 | + raise SystemExit(f"Release tags must start with 'v': {tag}") |
| 36 | +
|
| 37 | + namespace: dict[str, str] = {} |
| 38 | + exec(Path("justoneapi/_version.py").read_text(), namespace) |
| 39 | + package_version = namespace["__version__"] |
| 40 | + tag_version = tag.removeprefix("v") |
| 41 | +
|
| 42 | + if tag_version != package_version: |
| 43 | + raise SystemExit( |
| 44 | + f"Tag version {tag_version} does not match package version {package_version}" |
| 45 | + ) |
| 46 | +
|
| 47 | + print(f"Validated release tag {tag} for package version {package_version}") |
| 48 | + PY |
| 49 | +
|
| 50 | + - name: Normalize OpenAPI |
| 51 | + run: python scripts/normalize_openapi.py |
| 52 | + |
| 53 | + - name: Generate SDK |
| 54 | + run: python scripts/generate_sdk.py |
| 55 | + |
| 56 | + - name: Ensure generated artifacts are committed |
| 57 | + run: git diff --exit-code -- openapi/public-api.normalized.json justoneapi/generated |
| 58 | + |
| 59 | + - name: Run tests |
| 60 | + run: python -m pytest |
| 61 | + |
| 62 | + - name: Build distributions |
| 63 | + run: python -m build |
| 64 | + |
| 65 | + - name: Check distributions |
| 66 | + run: python -m twine check dist/* |
| 67 | + |
| 68 | + - name: Upload distributions |
| 69 | + uses: actions/upload-artifact@v4 |
| 70 | + with: |
| 71 | + name: python-dist |
| 72 | + path: dist/* |
| 73 | + |
| 74 | + publish: |
| 75 | + needs: build |
| 76 | + runs-on: ubuntu-latest |
| 77 | + permissions: |
| 78 | + contents: write |
| 79 | + id-token: write |
| 80 | + |
| 81 | + steps: |
| 82 | + - name: Download distributions |
| 83 | + uses: actions/download-artifact@v4 |
| 84 | + with: |
| 85 | + name: python-dist |
| 86 | + path: dist |
| 87 | + |
| 88 | + - name: Publish to PyPI |
| 89 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 90 | + |
| 91 | + - name: Create GitHub release |
| 92 | + env: |
| 93 | + GH_TOKEN: ${{ github.token }} |
| 94 | + GITHUB_REF_NAME: ${{ github.ref_name }} |
| 95 | + run: gh release create "$GITHUB_REF_NAME" dist/* --generate-notes --title "$GITHUB_REF_NAME" |
0 commit comments