|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + id-token: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + test-and-build: |
| 14 | + name: Test and Build |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: '3.12' |
| 27 | + cache: 'pip' |
| 28 | + |
| 29 | + - name: Install dependencies |
| 30 | + run: | |
| 31 | + python -m pip install --upgrade pip |
| 32 | + pip install -e ".[dev]" |
| 33 | + pip install build |
| 34 | +
|
| 35 | + - name: Run tests |
| 36 | + run: python -m pytest tests/ -v |
| 37 | + |
| 38 | + - name: Build package |
| 39 | + run: python -m build |
| 40 | + |
| 41 | + - name: Upload build artifacts |
| 42 | + uses: actions/upload-artifact@v4 |
| 43 | + with: |
| 44 | + name: release-artifacts |
| 45 | + path: | |
| 46 | + dist/ |
| 47 | + pyproject.toml |
| 48 | + README.md |
| 49 | + LICENSE |
| 50 | + retention-days: 30 |
| 51 | + |
| 52 | + release: |
| 53 | + name: Release |
| 54 | + runs-on: ubuntu-latest |
| 55 | + needs: test-and-build |
| 56 | + if: github.ref == 'refs/heads/main' |
| 57 | + |
| 58 | + steps: |
| 59 | + - name: Checkout code |
| 60 | + uses: actions/checkout@v4 |
| 61 | + with: |
| 62 | + fetch-depth: 0 |
| 63 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 64 | + |
| 65 | + - name: Set up Python |
| 66 | + uses: actions/setup-python@v5 |
| 67 | + with: |
| 68 | + python-version: '3.12' |
| 69 | + cache: 'pip' |
| 70 | + |
| 71 | + - name: Install dependencies |
| 72 | + run: | |
| 73 | + python -m pip install --upgrade pip |
| 74 | + pip install python-semantic-release build |
| 75 | +
|
| 76 | + - name: Configure Git |
| 77 | + run: | |
| 78 | + git config user.name "github-actions[bot]" |
| 79 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 80 | +
|
| 81 | + - name: Python Semantic Release |
| 82 | + id: release |
| 83 | + env: |
| 84 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + run: | |
| 86 | + semantic-release version |
| 87 | + semantic-release publish |
| 88 | +
|
| 89 | + - name: Download build artifacts |
| 90 | + uses: actions/download-artifact@v4 |
| 91 | + with: |
| 92 | + name: release-artifacts |
| 93 | + path: artifacts/ |
| 94 | + |
| 95 | + - name: Publish to PyPI |
| 96 | + if: steps.release.outputs.released == 'true' |
| 97 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 98 | + with: |
| 99 | + packages-dir: artifacts/dist/ |
0 commit comments