|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + version: |
| 9 | + description: 'Version to publish (e.g., 0.2.0)' |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +jobs: |
| 14 | + publish: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Set up Python |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: '3.12' |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + run: | |
| 30 | + python -m pip install --upgrade pip |
| 31 | + pip install -e ".[dev]" |
| 32 | + pip install build twine |
| 33 | +
|
| 34 | + - name: Update version |
| 35 | + if: github.event_name == 'workflow_dispatch' |
| 36 | + run: | |
| 37 | + sed -i "s/VERSION = '.*'/VERSION = '${{ inputs.version }}'/" checkend/version.py |
| 38 | + sed -i "s/version = \".*\"/version = \"${{ inputs.version }}\"/" pyproject.toml |
| 39 | +
|
| 40 | + - name: Run tests |
| 41 | + run: pytest -v |
| 42 | + |
| 43 | + - name: Run linter |
| 44 | + run: ruff check . |
| 45 | + |
| 46 | + - name: Build package |
| 47 | + run: python -m build |
| 48 | + |
| 49 | + - name: Configure git |
| 50 | + if: github.event_name == 'workflow_dispatch' |
| 51 | + run: | |
| 52 | + git config user.name "github-actions[bot]" |
| 53 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 54 | +
|
| 55 | + - name: Install git-cliff |
| 56 | + if: github.event_name == 'workflow_dispatch' |
| 57 | + uses: kenji-miyake/setup-git-cliff@v2 |
| 58 | + |
| 59 | + - name: Generate changelog |
| 60 | + if: github.event_name == 'workflow_dispatch' |
| 61 | + run: | |
| 62 | + git-cliff --tag "v${{ inputs.version }}" -o CHANGELOG.md |
| 63 | +
|
| 64 | + - name: Commit version and changelog |
| 65 | + if: github.event_name == 'workflow_dispatch' |
| 66 | + run: | |
| 67 | + git pull --rebase origin main |
| 68 | + git add checkend/version.py pyproject.toml CHANGELOG.md |
| 69 | + if git diff --staged --quiet; then |
| 70 | + echo "No changes to commit" |
| 71 | + else |
| 72 | + git commit -m "Release v${{ inputs.version }}" |
| 73 | + git push |
| 74 | + fi |
| 75 | +
|
| 76 | + - name: Create tag and release |
| 77 | + if: github.event_name == 'workflow_dispatch' |
| 78 | + env: |
| 79 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + run: | |
| 81 | + if git rev-parse "v${{ inputs.version }}" >/dev/null 2>&1; then |
| 82 | + echo "Tag v${{ inputs.version }} already exists" |
| 83 | + else |
| 84 | + git tag "v${{ inputs.version }}" |
| 85 | + git push origin "v${{ inputs.version }}" |
| 86 | + fi |
| 87 | + if gh release view "v${{ inputs.version }}" >/dev/null 2>&1; then |
| 88 | + echo "Release v${{ inputs.version }} already exists" |
| 89 | + else |
| 90 | + gh release create "v${{ inputs.version }}" \ |
| 91 | + --title "v${{ inputs.version }}" \ |
| 92 | + --generate-notes |
| 93 | + fi |
| 94 | +
|
| 95 | + - name: Publish to PyPI |
| 96 | + env: |
| 97 | + TWINE_USERNAME: __token__ |
| 98 | + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 99 | + run: twine upload dist/* |
0 commit comments