|
58 | 58 | with: |
59 | 59 | name: coverage-xml |
60 | 60 | path: coverage.xml |
61 | | - |
62 | | - publish: |
63 | | - needs: pytest |
64 | | - if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
65 | | - runs-on: ubuntu-latest |
66 | | - permissions: |
67 | | - contents: write |
68 | | - steps: |
69 | | - - uses: actions/checkout@v4 |
70 | | - with: |
71 | | - token: ${{ secrets.GITHUB_TOKEN }} |
72 | | - - name: Set up Python |
73 | | - uses: actions/setup-python@v5 |
74 | | - with: |
75 | | - python-version: "3.12" |
76 | | - cache: pip |
77 | | - - name: Install build tools |
78 | | - run: | |
79 | | - python -m pip install --upgrade pip |
80 | | - pip install build twine |
81 | | - - name: Bump patch version in stable.toml and dev.toml |
82 | | - id: version |
83 | | - run: | |
84 | | - python - <<'PY' |
85 | | - import os |
86 | | - import pathlib |
87 | | - import re |
88 | | -
|
89 | | - def bump(path: pathlib.Path) -> str: |
90 | | - text = path.read_text(encoding="utf-8") |
91 | | - match = re.search(r'^version = "(\d+)\.(\d+)\.(\d+)"', text, re.MULTILINE) |
92 | | - if match is None: |
93 | | - raise SystemExit(f"no version line found in {path}") |
94 | | - major, minor, patch = (int(g) for g in match.groups()) |
95 | | - new = f"{major}.{minor}.{patch + 1}" |
96 | | - path.write_text(text.replace(match.group(0), f'version = "{new}"', 1), encoding="utf-8") |
97 | | - return new |
98 | | -
|
99 | | - stable_version = bump(pathlib.Path("stable.toml")) |
100 | | - dev_version = bump(pathlib.Path("dev.toml")) |
101 | | - with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as fp: |
102 | | - fp.write(f"version={stable_version}\n") |
103 | | - fp.write(f"dev_version={dev_version}\n") |
104 | | - print(f"stable.toml -> {stable_version}") |
105 | | - print(f"dev.toml -> {dev_version}") |
106 | | - PY |
107 | | - - name: Commit and push bumped versions back to main |
108 | | - id: bump_commit |
109 | | - env: |
110 | | - VERSION: ${{ steps.version.outputs.version }} |
111 | | - run: | |
112 | | - git config user.name "github-actions[bot]" |
113 | | - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
114 | | - git add stable.toml dev.toml |
115 | | - git commit -m "Bump version to v${VERSION} [skip ci]" |
116 | | - git push origin HEAD:main |
117 | | - echo "oid=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT" |
118 | | - - name: Use stable.toml as pyproject.toml |
119 | | - run: cp stable.toml pyproject.toml |
120 | | - - name: Build sdist and wheel |
121 | | - run: python -m build |
122 | | - - name: Twine check |
123 | | - run: twine check dist/* |
124 | | - - name: Twine upload to PyPI |
125 | | - env: |
126 | | - TWINE_USERNAME: __token__ |
127 | | - TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
128 | | - run: twine upload --non-interactive dist/* |
129 | | - - name: Create GitHub Release |
130 | | - env: |
131 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
132 | | - BUMP_OID: ${{ steps.bump_commit.outputs.oid }} |
133 | | - run: | |
134 | | - gh release create "v${{ steps.version.outputs.version }}" dist/* \ |
135 | | - --title "v${{ steps.version.outputs.version }}" \ |
136 | | - --generate-notes \ |
137 | | - --target "$BUMP_OID" |
0 commit comments