|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*.*.*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + id-token: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + validate: |
| 14 | + name: Validate tag matches package version |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Set up Python |
| 20 | + uses: actions/setup-python@v5 |
| 21 | + with: |
| 22 | + python-version: "3.12" |
| 23 | + |
| 24 | + - name: Check version match |
| 25 | + run: | |
| 26 | + TAG_VERSION="${GITHUB_REF_NAME#v}" |
| 27 | + PKG_VERSION=$(python - <<'PY' |
| 28 | + import tomllib |
| 29 | + with open('pyproject.toml', 'rb') as f: |
| 30 | + data = tomllib.load(f) |
| 31 | + print(data['project']['version']) |
| 32 | + PY |
| 33 | + ) |
| 34 | + if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then |
| 35 | + echo "Tag version ($TAG_VERSION) does not match package version ($PKG_VERSION)." |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | + echo "Version check passed: $PKG_VERSION" |
| 39 | +
|
| 40 | + test: |
| 41 | + name: Full test suite before release |
| 42 | + needs: validate |
| 43 | + runs-on: ubuntu-latest |
| 44 | + strategy: |
| 45 | + fail-fast: false |
| 46 | + matrix: |
| 47 | + python-version: ["3.11", "3.12", "3.13"] |
| 48 | + |
| 49 | + steps: |
| 50 | + - uses: actions/checkout@v4 |
| 51 | + |
| 52 | + - name: Set up Python ${{ matrix.python-version }} |
| 53 | + uses: actions/setup-python@v5 |
| 54 | + with: |
| 55 | + python-version: ${{ matrix.python-version }} |
| 56 | + |
| 57 | + - name: Install dependencies |
| 58 | + run: | |
| 59 | + python -m pip install --upgrade pip |
| 60 | + pip install -e .[dev] |
| 61 | +
|
| 62 | + - name: Run tests |
| 63 | + run: pytest |
| 64 | + |
| 65 | + build-and-publish: |
| 66 | + name: Build distribution and publish to PyPI |
| 67 | + needs: test |
| 68 | + runs-on: ubuntu-latest |
| 69 | + environment: |
| 70 | + name: pypi |
| 71 | + url: https://pypi.org/project/fanvue-python-sdk/ |
| 72 | + |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@v4 |
| 75 | + |
| 76 | + - name: Set up Python |
| 77 | + uses: actions/setup-python@v5 |
| 78 | + with: |
| 79 | + python-version: "3.12" |
| 80 | + |
| 81 | + - name: Install build tools |
| 82 | + run: python -m pip install --upgrade build |
| 83 | + |
| 84 | + - name: Build distributions |
| 85 | + run: python -m build |
| 86 | + |
| 87 | + - name: Publish to PyPI |
| 88 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 89 | + |
| 90 | + github-release: |
| 91 | + name: Create GitHub release |
| 92 | + needs: build-and-publish |
| 93 | + runs-on: ubuntu-latest |
| 94 | + |
| 95 | + steps: |
| 96 | + - uses: actions/checkout@v4 |
| 97 | + with: |
| 98 | + fetch-depth: 0 |
| 99 | + |
| 100 | + - name: Create GitHub Release |
| 101 | + uses: softprops/action-gh-release@v2 |
| 102 | + with: |
| 103 | + generate_release_notes: true |
| 104 | + draft: false |
| 105 | + prerelease: ${{ contains(github.ref_name, '-') }} |
0 commit comments