|
| 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 | + build-release: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Check out repository |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + - name: Set up Python |
| 21 | + uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: "3.11" |
| 24 | + |
| 25 | + - name: Verify tag matches project version |
| 26 | + env: |
| 27 | + GITHUB_REF_NAME: ${{ github.ref_name }} |
| 28 | + run: | |
| 29 | + python - <<'PY' |
| 30 | + import os |
| 31 | + import pathlib |
| 32 | + import tomllib |
| 33 | +
|
| 34 | + pyproject = pathlib.Path("pyproject.toml") |
| 35 | + data = tomllib.loads(pyproject.read_text(encoding="utf-8")) |
| 36 | + version = data["project"]["version"] |
| 37 | + expected_tag = f"v{version}" |
| 38 | + actual_tag = os.environ["GITHUB_REF_NAME"] |
| 39 | +
|
| 40 | + if actual_tag != expected_tag: |
| 41 | + raise SystemExit(f"Tag {actual_tag!r} does not match project version {expected_tag!r}.") |
| 42 | + PY |
| 43 | +
|
| 44 | + - name: Install release tooling |
| 45 | + run: | |
| 46 | + python -m pip install --upgrade pip |
| 47 | + python -m pip install -e . build twine |
| 48 | +
|
| 49 | + - name: Run CLI smoke tests |
| 50 | + run: python -m unittest discover -s tests -p "test_*.py" -v |
| 51 | + |
| 52 | + - name: Build distribution artifacts |
| 53 | + run: python -m build |
| 54 | + |
| 55 | + - name: Validate package metadata |
| 56 | + run: python -m twine check dist/* |
| 57 | + |
| 58 | + - name: Publish GitHub release |
| 59 | + uses: softprops/action-gh-release@v2 |
| 60 | + with: |
| 61 | + files: dist/* |
| 62 | + generate_release_notes: true |
| 63 | + |
| 64 | + - name: Upload release artifacts |
| 65 | + uses: actions/upload-artifact@v4 |
| 66 | + with: |
| 67 | + name: python-dist |
| 68 | + path: dist/ |
| 69 | + |
| 70 | + publish-pypi: |
| 71 | + needs: build-release |
| 72 | + runs-on: ubuntu-latest |
| 73 | + environment: |
| 74 | + name: pypi |
| 75 | + url: https://pypi.org/p/always-attend |
| 76 | + permissions: |
| 77 | + id-token: write |
| 78 | + |
| 79 | + steps: |
| 80 | + - name: Download release artifacts |
| 81 | + uses: actions/download-artifact@v4 |
| 82 | + with: |
| 83 | + name: python-dist |
| 84 | + path: dist/ |
| 85 | + |
| 86 | + - name: Publish to PyPI |
| 87 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments