|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' # Trigger on version tags like v0.1.0, v1.0.0, etc. |
| 7 | + workflow_dispatch: # Allow manual trigger |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + name: Run Tests |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Set up Python |
| 17 | + uses: actions/setup-python@v5 |
| 18 | + with: |
| 19 | + python-version: '3.10' |
| 20 | + |
| 21 | + - name: Install uv |
| 22 | + run: curl -LsSf https://astral.sh/uv/install.sh | sh |
| 23 | + |
| 24 | + - name: Install dependencies |
| 25 | + run: | |
| 26 | + uv sync --extra dev |
| 27 | +
|
| 28 | + - name: Run tests |
| 29 | + run: | |
| 30 | + uv run pytest tests/unit/ -v --cov=rencom |
| 31 | +
|
| 32 | + - name: Type check |
| 33 | + run: | |
| 34 | + uv run mypy rencom/ --ignore-missing-imports || true |
| 35 | +
|
| 36 | + - name: Lint |
| 37 | + run: | |
| 38 | + uv run ruff check . || true |
| 39 | +
|
| 40 | + build: |
| 41 | + name: Build Distribution |
| 42 | + needs: test |
| 43 | + runs-on: ubuntu-latest |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v4 |
| 46 | + |
| 47 | + - name: Set up Python |
| 48 | + uses: actions/setup-python@v5 |
| 49 | + with: |
| 50 | + python-version: '3.10' |
| 51 | + |
| 52 | + - name: Install uv |
| 53 | + run: curl -LsSf https://astral.sh/uv/install.sh | sh |
| 54 | + |
| 55 | + - name: Build package |
| 56 | + run: uv build |
| 57 | + |
| 58 | + - name: Check package |
| 59 | + run: | |
| 60 | + uv pip install twine |
| 61 | + uv run twine check dist/* |
| 62 | +
|
| 63 | + - name: Upload artifacts |
| 64 | + uses: actions/upload-artifact@v4 |
| 65 | + with: |
| 66 | + name: dist |
| 67 | + path: dist/ |
| 68 | + |
| 69 | + publish-testpypi: |
| 70 | + name: Publish to TestPyPI |
| 71 | + needs: build |
| 72 | + runs-on: ubuntu-latest |
| 73 | + environment: |
| 74 | + name: testpypi |
| 75 | + url: https://test.pypi.org/project/rencom/ |
| 76 | + permissions: |
| 77 | + id-token: write # For trusted publishing |
| 78 | + |
| 79 | + steps: |
| 80 | + - name: Download artifacts |
| 81 | + uses: actions/download-artifact@v4 |
| 82 | + with: |
| 83 | + name: dist |
| 84 | + path: dist/ |
| 85 | + |
| 86 | + - name: Publish to TestPyPI |
| 87 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 88 | + with: |
| 89 | + repository-url: https://test.pypi.org/legacy/ |
| 90 | + skip-existing: true |
| 91 | + |
| 92 | + publish-pypi: |
| 93 | + name: Publish to PyPI |
| 94 | + needs: [build, publish-testpypi] |
| 95 | + runs-on: ubuntu-latest |
| 96 | + environment: |
| 97 | + name: pypi |
| 98 | + url: https://pypi.org/project/rencom/ |
| 99 | + permissions: |
| 100 | + id-token: write # For trusted publishing |
| 101 | + |
| 102 | + steps: |
| 103 | + - name: Download artifacts |
| 104 | + uses: actions/download-artifact@v4 |
| 105 | + with: |
| 106 | + name: dist |
| 107 | + path: dist/ |
| 108 | + |
| 109 | + - name: Publish to PyPI |
| 110 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 111 | + |
| 112 | + create-release: |
| 113 | + name: Create GitHub Release |
| 114 | + needs: publish-pypi |
| 115 | + runs-on: ubuntu-latest |
| 116 | + permissions: |
| 117 | + contents: write |
| 118 | + steps: |
| 119 | + - uses: actions/checkout@v4 |
| 120 | + |
| 121 | + - name: Extract version from tag |
| 122 | + id: version |
| 123 | + run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT |
| 124 | + |
| 125 | + - name: Extract changelog |
| 126 | + id: changelog |
| 127 | + run: | |
| 128 | + VERSION=${{ steps.version.outputs.VERSION }} |
| 129 | + # Extract section for this version from CHANGELOG.md |
| 130 | + sed -n "/## \[${VERSION}\]/,/## \[/p" CHANGELOG.md | sed '$d' > release_notes.md |
| 131 | +
|
| 132 | + - name: Create Release |
| 133 | + uses: softprops/action-gh-release@v1 |
| 134 | + with: |
| 135 | + name: Release v${{ steps.version.outputs.VERSION }} |
| 136 | + body_path: release_notes.md |
| 137 | + draft: false |
| 138 | + prerelease: false |
0 commit comments