diff --git a/.github/workflows/bump-version-release.yaml b/.github/workflows/bump-version-release.yaml index a891d118e..9631a8620 100644 --- a/.github/workflows/bump-version-release.yaml +++ b/.github/workflows/bump-version-release.yaml @@ -13,11 +13,6 @@ on: required: false default: true type: boolean - changelog-config: - description: "Changelog config path." - required: false - default: "" - type: string working-directory: description: "Working directory containing `.bumpversion.cfg`. (Default is .)" required: false @@ -57,34 +52,35 @@ jobs: uses: bakdata/ci-templates/actions/checkout@1.32.0 with: ref: ${{ github.event.repository.default_branch }} - persist-credentials: false # required for pushing to protected branch later + persist-credentials: true # required for pushing to protected branch later - - name: Bump version + - name: Setup Git + run: | + git config --global user.name "${{ secrets.github-username }}" + git config --global user.email "${{ secrets.github-email }}" + + - name: Remove snapshot suffix id: bump-version - uses: bakdata/ci-templates/actions/bump-version@v1.21.2 + uses: bakdata/ci-templates/actions/bump-version@feat/new-bumpversion with: - release-type: ${{ inputs.release-type }} + release-type: "release" working-directory: ${{ inputs.working-directory }} + - name: Commit .bumpversion.cfg file without snapshot + run: | + git add .bumpversion.cfg + git commit -m "Bump version ${{ steps.bump-version.outputs.old-version }} → ${{ steps.bump-version.outputs.release-version }}" + git fetch origin + git rebase --strategy-option=theirs origin/main + git push --verbose + - name: Create changelog id: build-changelog - uses: bakdata/ci-templates/actions/changelog-generate@1.35.0 + uses: bakdata/ci-templates/actions/changelog-generate@tiedemann/changelog-action if: ${{ inputs.changelog }} with: github-token: ${{ secrets.github-token }} - config: ${{ inputs.changelog-config }} - new-tag: ${{ steps.bump-version.outputs.release-version }} - fetch-reviewers: "true" - fetch-release-information: "true" - - - name: Commit and push changes including .bumpversion.cfg file - uses: bakdata/ci-templates/actions/commit-and-push@v1.6.0 - with: - ref: ${{ github.event.repository.default_branch }} - commit-message: "Bump version ${{ steps.bump-version.outputs.old-version }} → ${{ steps.bump-version.outputs.release-version }}" - github-username: ${{ secrets.github-username }} - github-email: ${{ secrets.github-email }} - github-token: ${{ secrets.github-token }} + tag: ${{ steps.bump-version.outputs.release-version }} - name: Tag and release uses: bakdata/ci-templates/actions/tag-and-release@v1.22.0 @@ -95,3 +91,18 @@ jobs: github-token: ${{ secrets.github-token }} release-title: "${{ steps.bump-version.outputs.release-version }}" release-body: "${{ steps.build-changelog.outputs.single-changelog }}" + + - name: Bump to next snapshot version + id: bump-version-snapshot + uses: bakdata/ci-templates/actions/bump-version@feat/new-bumpversion + with: + release-type: ${{ inputs.release-type }} + working-directory: ${{ inputs.working-directory }} + + - name: Commit .bumpversion.cfg file new version and snapshot + run: | + git add .bumpversion.cfg + git commit -m "Bump version ${{ steps.bump-version.outputs.release-version }} → ${{ steps.bump-version-snapshot.outputs.release-version }}" + git fetch origin + git rebase --strategy-option=theirs origin/main + git push --verbose diff --git a/actions/bump-version/action.yaml b/actions/bump-version/action.yaml index a6bea5a61..8091b6965 100644 --- a/actions/bump-version/action.yaml +++ b/actions/bump-version/action.yaml @@ -1,9 +1,25 @@ name: "Bump version" -description: "Bump version with python bump2version using .bumpversion.cfg" +description: "Bump version with python bump-my-version using .bumpversion.cfg" +# config example .bumpversion.cfg: +# [bumpversion] +# current_version = 1.0.0 +# search = version: {current_version} +# replace = version: {new_version} +# parse = (?P\d+)\.(?P\d+)\.(?P\d+)(-(?Psnapshot))? +# serialize = +# {major}.{minor}.{patch}-{release} +# {major}.{minor}.{patch} + +# [bumpversion:part:release] +# first_value = snapshot +# optional_value = release +# values = +# snapshot +# release inputs: release-type: - description: "The type of the release (major, minor or patch)." + description: "The type of the release (release, major, minor or patch). Release is a special case, where the snapshot suffix is removed." required: true working-directory: description: "The directory containing the `.bumpversion.cfg` file." @@ -25,20 +41,27 @@ outputs: runs: using: "composite" steps: - - name: Set up bump2version + - name: Set up bump-my-version run: | - pipx install bump2version + pipx install bump-my-version shell: bash - name: Bump version id: bump-version run: | - parameters=(--no-commit --no-tag ${{ inputs.release-type }}) - echo "old-version=$(python -c "from configparser import ConfigParser; cfg = ConfigParser(); cfg.read('.bumpversion.cfg'); print(cfg['bumpversion']['current_version'])")" >> "$GITHUB_OUTPUT" - if [ -n "${{ inputs.new-version }}" ]; then - parameters+=(--new-version ${{ inputs.new-version }}) + echo "old-version=$(bump-my-version show current_version | tail -1)" >> "$GITHUB_OUTPUT" + + if [[ "${{ inputs.new-version }}" != "" ]]; then + bump-my-version --new-version ${{ inputs.new-version }} + else + bump-my-version bump ${{ inputs.release-type }} fi - bump2version "${parameters[@]}" - echo "new-version=$(python -c "from configparser import ConfigParser; cfg = ConfigParser(); cfg.read('.bumpversion.cfg'); print(cfg['bumpversion']['current_version'])")" >> "$GITHUB_OUTPUT" + echo "new-version=$(bump-my-version show current_version | tail -1)" >> "$GITHUB_OUTPUT" + # release: a.b.c-snapshot -> a.b.c + # release a.b.c -> crash + # major: a.b.c(-snapshot)? -> a+1.0.0-snapshot + # minor: a.b.c(-snapshot)? -> a.b+1.0-snapshot + # patch: a.b.c(-snapshot)? -> a.b.c+1-snapshot + # TLDR: release removes the snapshot suffix shell: bash working-directory: ${{ inputs.working-directory }} diff --git a/docs/actions/bump-version/README.md b/docs/actions/bump-version/README.md index 36370d711..2bc4883a2 100644 --- a/docs/actions/bump-version/README.md +++ b/docs/actions/bump-version/README.md @@ -38,11 +38,11 @@ steps: -| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION | -| ----------------- | ------ | -------- | ------- | ----------------------------------------------------- | -| new-version | string | false | | | -| release-type | string | true | | The type of the release (major, minor or patch). | -| working-directory | string | false | `"."` | The directory containing the `.bumpversion.cfg` file. | +| INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION | +| ----------------- | ------ | -------- | ------- | -------------------------------------------------------------------------------------------------------------------------- | +| new-version | string | false | | | +| release-type | string | true | | The type of the release (release, major, minor or patch). Release is a special case, where the snapshot suffix is removed. | +| working-directory | string | false | `"."` | The directory containing the `.bumpversion.cfg` file. | diff --git a/docs/workflows/bump-version-release/README.md b/docs/workflows/bump-version-release/README.md index 2f70664a3..a3e2017ee 100644 --- a/docs/workflows/bump-version-release/README.md +++ b/docs/workflows/bump-version-release/README.md @@ -64,7 +64,6 @@ jobs: | INPUT | TYPE | REQUIRED | DEFAULT | DESCRIPTION | | ----------------- | ------- | -------- | ------- | --------------------------------------------------------------- | | changelog | boolean | false | `true` | Create changelog for release. | -| changelog-config | string | false | | Changelog config path. | | release-type | string | true | | Scope of the release (major, minor or patch). | | working-directory | string | false | `"."` | Working directory containing `.bumpversion.cfg`. (Default is .) |