Skip to content

Commit

Permalink
fix:
Browse files Browse the repository at this point in the history
- use bump-my-version instead of deprecated bump2version
- merge snapshot action into bump action via parameter
- WARN: requires special config - example given
  • Loading branch information
DerTiedemann committed Aug 6, 2024
1 parent a2a3e0c commit 5eea497
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/bump-version-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ jobs:
ref: ${{ github.event.repository.default_branch }}
persist-credentials: false # required for pushing to protected branch later

- name: Bump version
- name: Remove snapshot suffix
id: bump-version
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 and push changes including .bumpversion.cfg file
Expand Down Expand Up @@ -96,12 +96,12 @@ jobs:
release-title: "${{ steps.bump-version.outputs.release-version }}"
release-body: "${{ steps.build-changelog.outputs.single-changelog }}"

- name: Bump version
id: bump-version-snapshot
uses: bakdata/ci-templates/actions/bump-version-snapshot@feat/new-bumpversion
- name: Bump to next snapshot version
id: bump-version

Check failure on line 100 in .github/workflows/bump-version-release.yaml

View workflow job for this annotation

GitHub Actions / actionlint

step ID "bump-version" duplicates. previously defined at line:63,col:13. step ID must be unique within a job. note that step ID is case insensitive
uses: bakdata/ci-templates/actions/bump-version@feat/new-bumpversion
with:
release-type: ${{ inputs.release-type }}
working-directory: ${{ inputs.working-directory }}
test-version: ${{ steps.bump-version.outputs.release-version }}

- name: Commit and push changes including .bumpversion.cfg file
uses: bakdata/ci-templates/actions/commit-and-push@v1.6.0
Expand Down
48 changes: 33 additions & 15 deletions actions/bump-version/action.yaml
Original file line number Diff line number Diff line change
@@ -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<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(-(?P<release>snapshot))?
# 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."
Expand All @@ -25,26 +41,28 @@ 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 --allow-dirty --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 [[ ${{ inputs.release-type }} == patch ]]; then
parameters+=(--new-version ${{ inputs.new-version }})
bump2version --allow-dirty release
parameters=(--no-commit --allow-dirty --no-tag)
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
bump2version --allow-dirty "${parameters[@]}"
bump2version --allow-dirty release
bump-my-version "${parameters[@]}" ${{ inputs.release-type }}
fi
echo "new-version=$(python -c "from configparser import ConfigParser; cfg = ConfigParser(); cfg.read('.bumpversion.cfg'); print(cfg['bumpversion']['current_version'])")" >> "$GITHUB_OUTPUT"
# We use the case for release-type "patch", because if we do not we get inproper results. For example : 0.0.1-snapshot -> 0.0.3
# If release-type == patch , we use "bump2version release". This command basically removes the suffix. For example : 0.0.1-snapshot -> 0.0.1
# In the other case we bump the version (major or minor), then we remove the snapshot suffix
echo "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 }}
10 changes: 5 additions & 5 deletions docs/actions/bump-version/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ steps:
<!-- AUTO-DOC-INPUT:START - Do not remove or modify this section -->
| 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. |

<!-- AUTO-DOC-INPUT:END -->

Expand Down

0 comments on commit 5eea497

Please sign in to comment.