diff --git a/shared.sh b/shared.sh index d924800..4476f28 100644 --- a/shared.sh +++ b/shared.sh @@ -16,8 +16,8 @@ pcre_old_calver='^(?P0|[1-9]\d*)-0{0,1}(?P0|[0-9]\d*)-R(?P0 input_errors='false' scheme="${scheme:-semver}" -if [[ "${scheme}" != 'semver' && "${scheme}" != 'calver' ]] ; then - echo "🛑 Value of 'scheme' is not valid, choose from 'semver' or 'calver'" 1>&2 +if [[ "${scheme}" != 'semver' && "${scheme}" != 'calver' && "${scheme}" != 'pep440' ]] ; then + echo "🛑 Value of 'scheme' is not valid, choose from 'semver', 'calver', or 'pep440'" 1>&2 input_errors='true' fi diff --git a/tests/test_version-increment.bats b/tests/test_version-increment.bats index 4e15087..52512f0 100644 --- a/tests/test_version-increment.bats +++ b/tests/test_version-increment.bats @@ -120,6 +120,23 @@ function init_repo { [[ "$output" = *"VERSION=2.0.0"* ]] } +@test "increments the major digit correctly (pep440)" { + init_repo + + export current_version=1.2.3 + export scheme="pep440" + export increment="major" + + run ../../version-increment.sh + + print_run_info + [ "$status" -eq 0 ] && + [[ "$output" = *"MAJOR_VERSION=2"* ]] && + [[ "$output" = *"MINOR_VERSION=0"* ]] && + [[ "$output" = *"PATCH_VERSION=0"* ]] && + [[ "$output" = *"VERSION=2.0.0"* ]] +} + @test "prefixes with v" { init_repo @@ -177,3 +194,19 @@ function init_repo { [[ "$output" = *"PRE_RELEASE_LABEL=pre.${short_ref}"* ]] [[ "$output" = *"VERSION=1.2.4-pre.${short_ref}"* ]] } + +@test "appends prerelease information in pep440 compatible way if on a branch and scheme is pep440" { + init_repo + + export current_version=10.20.30 + export scheme="pep440" + export GITHUB_REF="refs/heads/super-awesome-python" + export short_ref="$(git rev-parse --short HEAD | sed 's/0*//')" + + run ../../version-increment.sh + + print_run_info + [ "$status" -eq 0 ] && + [[ "$output" = *"PRE_RELEASE_LABEL=pre.${short_ref}"* ]] + [[ "$output" = *"VERSION=10.20.31+pre.${short_ref}"* ]] +} diff --git a/version-increment.sh b/version-increment.sh index 915b1a9..1c91ec4 100755 --- a/version-increment.sh +++ b/version-increment.sh @@ -75,7 +75,11 @@ fi # add pre-release info to version if not the default branch if [[ "${current_ref}" != "refs/heads/${default_branch}" ]] ; then pre_release="pre.${git_commit}" - new_version="${new_version}-${pre_release}" + if [[ "${scheme}" == 'pep440' ]] ; then + new_version="${new_version}+${pre_release}" + else + new_version="${new_version}-${pre_release}" + fi echo "PRE_RELEASE_LABEL=${pre_release}" >> "${GITHUB_OUTPUT}" fi diff --git a/version-lookup.sh b/version-lookup.sh index 45ed51c..90da3be 100755 --- a/version-lookup.sh +++ b/version-lookup.sh @@ -53,6 +53,9 @@ if [[ -z "${current_version:-}" ]] ; then semver) current_version="0.0.0" ;; + pep440) + current_version="0.0.0" + ;; calver) current_version="$(date '+%Y.%-m.0')" ;;