|
1 | | -name: Publish to PyPI |
| 1 | +name: Auto-bump version, release, and publish |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | | - tags: |
6 | | - - "v*.*.*" # e.g. v0.1.0, v1.2.3 |
| 5 | + branches: |
| 6 | + - Publish |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
7 | 10 |
|
8 | 11 | jobs: |
9 | | - build-and-publish: |
| 12 | + bump-release-publish: |
| 13 | + name: Auto-bump version and publish |
10 | 14 | runs-on: ubuntu-latest |
11 | 15 |
|
12 | 16 | steps: |
13 | 17 | - name: Check out repository |
14 | 18 | uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + fetch-depth: 0 |
15 | 21 |
|
16 | 22 | - name: Set up Python |
17 | 23 | uses: actions/setup-python@v5 |
18 | 24 | with: |
19 | 25 | python-version: "3.11" |
20 | 26 |
|
21 | | - - name: Install build tools |
| 27 | + - name: Install dependencies |
22 | 28 | run: | |
23 | 29 | python -m pip install --upgrade pip |
24 | | - pip install build twine |
| 30 | + python -m pip install build twine toml |
| 31 | +
|
| 32 | + - name: Auto-increment version |
| 33 | + id: bump |
| 34 | + run: | |
| 35 | + python - << 'PY' |
| 36 | + import toml |
| 37 | + from pathlib import Path |
| 38 | +
|
| 39 | + path = Path("pyproject.toml") |
| 40 | + data = toml.loads(path.read_text()) |
| 41 | +
|
| 42 | + version = data["project"]["version"] |
| 43 | +
|
| 44 | + major, minor, patch = version.split(".") |
| 45 | + patch = str(int(patch) + 1) |
| 46 | + new_version = ".".join([major, minor, patch]) |
| 47 | +
|
| 48 | + data["project"]["version"] = new_version |
25 | 49 |
|
26 | | - - name: Build sdist and wheel |
27 | | - run: python -m build |
| 50 | + path.write_text(toml.dumps(data)) |
28 | 51 |
|
29 | | - - name: Check distribution files |
30 | | - run: twine check dist/* |
| 52 | + print(f"Bumped version: {version} -> {new_version}") |
| 53 | +
|
| 54 | + # Export for later steps |
| 55 | + with open(Path("$GITHUB_OUTPUT"), "a") as f: |
| 56 | + f.write(f"new_version={new_version}\n") |
| 57 | + PY |
| 58 | +
|
| 59 | + - name: Commit updated version |
| 60 | + run: | |
| 61 | + git config user.name "github-actions" |
| 62 | + git config user.email "actions@github.com" |
| 63 | + git add pyproject.toml |
| 64 | + git commit -m "Auto-bump version to ${{ steps.bump.outputs.new_version }}" |
| 65 | + git push |
| 66 | +
|
| 67 | + - name: Build distributions |
| 68 | + run: | |
| 69 | + python -m build |
31 | 70 |
|
32 | 71 | - name: Publish to PyPI |
33 | | - if: startsWith(github.ref, 'refs/tags/') |
34 | | - uses: pypa/gh-action-pypi-publish@release/v1 |
| 72 | + env: |
| 73 | + TWINE_USERNAME: "__token__" |
| 74 | + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} |
| 75 | + run: | |
| 76 | + twine upload dist/* |
| 77 | +
|
| 78 | + - name: Create GitHub release |
| 79 | + uses: softprops/action-gh-release@v2 |
35 | 80 | with: |
36 | | - user: __token__ |
37 | | - password: ${{ secrets.PYPI_API_TOKEN }} |
| 81 | + tag_name: v${{ steps.bump.outputs.new_version }} |
| 82 | + name: nessus-plugin-hosts v${{ steps.bump.outputs.new_version }} |
| 83 | + generate_release_notes: true |
| 84 | + env: |
| 85 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments