|
| 1 | +name: Bump version |
| 2 | +# For the time being, we still do this with pdm. |
| 3 | +# Honestly, it doesn't really matter, |
| 4 | +# but one day uv will have a bump command too and we can switch to that. |
| 5 | +# Relevant issue in uv: https://github.com/astral-sh/uv/issues/6298 |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + bump_rule: |
| 11 | + type: choice |
| 12 | + description: How to bump the project's version (see https://github.com/carstencodes/pdm-bump#usage) |
| 13 | + options: |
| 14 | + - no-pre-release |
| 15 | + # no micro because we always sit on a pre-release in main, |
| 16 | + # so we would always use no-pre-release instead of micro |
| 17 | + # - micro |
| 18 | + - minor |
| 19 | + - major |
| 20 | + - "pre-release --pre alpha" |
| 21 | + - "pre-release --pre beta" |
| 22 | + - "pre-release --pre release-candidate" |
| 23 | + required: true |
| 24 | + |
| 25 | +jobs: |
| 26 | + bump_version: |
| 27 | + name: "Bump version and create changelog" |
| 28 | + if: "!startsWith(github.event.head_commit.message, 'bump:')" |
| 29 | + strategy: |
| 30 | + matrix: |
| 31 | + os: [ "ubuntu-latest" ] |
| 32 | + python-version: [ "3.9" ] |
| 33 | + runs-on: "${{ matrix.os }}" |
| 34 | + env: |
| 35 | + CI_COMMIT_EMAIL: "ci-runner@test-fork.invalid" |
| 36 | + steps: |
| 37 | + - name: Checkout repository |
| 38 | + uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + fetch-depth: 0 |
| 41 | + token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}" |
| 42 | + |
| 43 | + - name: Setup PDM |
| 44 | + uses: pdm-project/setup-pdm@v4.1 |
| 45 | + with: |
| 46 | + python-version: ${{ matrix.python-version }} |
| 47 | + |
| 48 | + - name: Install pdm-bump |
| 49 | + run: | |
| 50 | + pdm self add pdm-bump |
| 51 | +
|
| 52 | + - uses: ./.github/actions/setup |
| 53 | + with: |
| 54 | + python-version: ${{ matrix.python-version }} |
| 55 | + uv-dependency-install-flags: "--all-extras --group dev" |
| 56 | + |
| 57 | + - name: Create bump and changelog |
| 58 | + run: | |
| 59 | + git config --global user.name "$GITHUB_ACTOR" |
| 60 | + git config --global user.email "$CI_COMMIT_EMAIL" |
| 61 | +
|
| 62 | + BASE_VERSION=`sed -ne 's/^version = "\([0-9\.a]*\)"/\1/p' pyproject.toml` |
| 63 | + echo "Bumping from version $BASE_VERSION" |
| 64 | +
|
| 65 | + # Bump |
| 66 | + pdm bump ${{ github.event.inputs.bump_rule }} |
| 67 | +
|
| 68 | + NEW_VERSION=`sed -ne 's/^version = "\([0-9\.a]*\)"/\1/p' pyproject.toml` |
| 69 | + echo "Bumping to version $NEW_VERSION" |
| 70 | +
|
| 71 | + # Build CHANGELOG |
| 72 | + uv run towncrier build --yes --version v$NEW_VERSION |
| 73 | +
|
| 74 | + # Commit, tag and push |
| 75 | + git commit -a -m "bump: version $BASE_VERSION -> $NEW_VERSION" |
| 76 | + git tag v$NEW_VERSION |
| 77 | + git push && git push --tags |
| 78 | +
|
| 79 | + # Bump to alpha (so that future commits do not have the same |
| 80 | + # version as the tagged commit) |
| 81 | + BASE_VERSION=`sed -ne 's/^version = "\([0-9\.a]*\)"/\1/p' pyproject.toml` |
| 82 | +
|
| 83 | + # Bump to pre-release of next version |
| 84 | + pdm bump pre-release --pre alpha |
| 85 | +
|
| 86 | + NEW_VERSION=`sed -ne 's/^version = "\([0-9\.a]*\)"/\1/p' pyproject.toml` |
| 87 | + echo "Bumping version $BASE_VERSION > $NEW_VERSION" |
| 88 | +
|
| 89 | + # Commit and push |
| 90 | + git commit -a -m "bump(pre-release): version $BASE_VERSION > $NEW_VERSION" |
| 91 | + git push |
0 commit comments