|
| 1 | +name: Publish MailThunder Stable to PyPI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + paths-ignore: |
| 7 | + - '**.md' |
| 8 | + - 'docs/**' |
| 9 | + - '.github/**' |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: publish-stable |
| 13 | + cancel-in-progress: false |
| 14 | + |
| 15 | +jobs: |
| 16 | + test: |
| 17 | + permissions: |
| 18 | + contents: read |
| 19 | + runs-on: ${{ matrix.os }} |
| 20 | + strategy: |
| 21 | + fail-fast: true |
| 22 | + matrix: |
| 23 | + os: [ ubuntu-latest, windows-latest, macos-latest ] |
| 24 | + python-version: [ "3.9", "3.10", "3.11", "3.12" ] |
| 25 | + |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - name: Set up Python ${{ matrix.python-version }} |
| 30 | + uses: actions/setup-python@v5 |
| 31 | + with: |
| 32 | + python-version: ${{ matrix.python-version }} |
| 33 | + |
| 34 | + - name: Install dependencies |
| 35 | + run: | |
| 36 | + python -m pip install --upgrade pip |
| 37 | + pip install pytest |
| 38 | + pip install -e . |
| 39 | +
|
| 40 | + - name: Run tests |
| 41 | + run: python -m pytest test/unit_test/ --ignore=test/unit_test/manual_test -v |
| 42 | + |
| 43 | + publish: |
| 44 | + needs: test |
| 45 | + runs-on: ubuntu-latest |
| 46 | + permissions: |
| 47 | + contents: write |
| 48 | + steps: |
| 49 | + - uses: actions/checkout@v4 |
| 50 | + with: |
| 51 | + ref: main |
| 52 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + fetch-depth: 0 |
| 54 | + |
| 55 | + - name: Set up Python |
| 56 | + uses: actions/setup-python@v5 |
| 57 | + with: |
| 58 | + python-version: "3.12" |
| 59 | + |
| 60 | + - name: Install build tooling |
| 61 | + run: | |
| 62 | + python -m pip install --upgrade pip |
| 63 | + pip install build twine tomli tomli-w |
| 64 | +
|
| 65 | + - name: Bump patch version in pyproject.toml |
| 66 | + id: bump |
| 67 | + run: | |
| 68 | + python - <<'PY' |
| 69 | + import os |
| 70 | + import tomli |
| 71 | + import tomli_w |
| 72 | +
|
| 73 | + path = "pyproject.toml" |
| 74 | + with open(path, "rb") as handle: |
| 75 | + data = tomli.load(handle) |
| 76 | +
|
| 77 | + current = data["project"]["version"] |
| 78 | + major, minor, patch = (int(part) for part in current.split(".")) |
| 79 | + patch += 1 |
| 80 | + new_version = f"{major}.{minor}.{patch}" |
| 81 | + data["project"]["version"] = new_version |
| 82 | +
|
| 83 | + with open(path, "wb") as handle: |
| 84 | + tomli_w.dump(data, handle) |
| 85 | +
|
| 86 | + with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as out: |
| 87 | + out.write(f"old_version={current}\n") |
| 88 | + out.write(f"new_version={new_version}\n") |
| 89 | +
|
| 90 | + print(f"Bumped version: {current} -> {new_version}") |
| 91 | + PY |
| 92 | +
|
| 93 | + - name: Build distributions |
| 94 | + run: python -m build |
| 95 | + |
| 96 | + - name: Publish to PyPI |
| 97 | + env: |
| 98 | + TWINE_USERNAME: __token__ |
| 99 | + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 100 | + run: python -m twine upload --non-interactive dist/* |
| 101 | + |
| 102 | + - name: Commit and tag version bump |
| 103 | + run: | |
| 104 | + git config user.name "github-actions[bot]" |
| 105 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 106 | + git add pyproject.toml |
| 107 | + git commit -m "chore: bump stable version to ${{ steps.bump.outputs.new_version }}" |
| 108 | + git tag "v${{ steps.bump.outputs.new_version }}" |
| 109 | + git push origin main |
| 110 | + git push origin "v${{ steps.bump.outputs.new_version }}" |
| 111 | +
|
| 112 | + - name: Create GitHub Release |
| 113 | + env: |
| 114 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 115 | + run: | |
| 116 | + gh release create "v${{ steps.bump.outputs.new_version }}" \ |
| 117 | + --title "v${{ steps.bump.outputs.new_version }}" \ |
| 118 | + --notes "Automated stable release for v${{ steps.bump.outputs.new_version }}. Published to PyPI as \`je-mail-thunder==${{ steps.bump.outputs.new_version }}\`." \ |
| 119 | + --target main \ |
| 120 | + dist/* |
0 commit comments