From 5af72f0ae1d12841ddc66968772c06618645eee9 Mon Sep 17 00:00:00 2001 From: Phil Jay Date: Sat, 31 Aug 2024 14:38:32 +1000 Subject: [PATCH] Introduce new outputs --- .github/workflows/test-and-release.yml | 15 +++++++++++++++ action.yml | 6 ++++++ tests/test_version-increment.bats | 8 ++++---- tests/test_version-lookup.bats | 14 ++++++++++++++ version-increment.sh | 5 ++--- 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-and-release.yml b/.github/workflows/test-and-release.yml index f46778e..647ca3f 100644 --- a/.github/workflows/test-and-release.yml +++ b/.github/workflows/test-and-release.yml @@ -114,6 +114,21 @@ jobs: [[ "${{ steps.version-via-api.outputs.patch-version }}" == "${{ steps.version-via-git.outputs.patch-version }}" ]] # Don't test the full version or pre-version, since the number of digits is likely to be different (9 via api vs. 7 via git) + - name: Get next version via Git with tag-prefix + uses: ./ + id: version-prefix + with: + scheme: 'semver' + use_api: false + tag_prefix: 'foo/bar@' + + - name: Check that it starts from 0.0.1 (since prefix doesn't exist) + shell: bash + run: | + [[ "${{ steps.version-prefix.outputs.current-version }}" == "0.0.0" ]] + [[ "${{ steps.version-prefix.outputs.version }}" == "0.0.1" ]] + [[ "${{ steps.version-prefix.outputs.prefixed-version }}" == "foo/bar@0.0.1" ]] + release: needs: - test-action-yml diff --git a/action.yml b/action.yml index 4f64fd7..c6c81a6 100644 --- a/action.yml +++ b/action.yml @@ -80,6 +80,12 @@ outputs: patch-v-version: description: 'Patch number of the incremented version, prefixed with a `v` charatcter' value: ${{ steps.version-increment.outputs.PATCH_V_VERSION }} + prefixed-version: + description: 'Incremented version calculated, including a `tag_prefix` if specified' + value: ${{ inputs.tag_prefix}}${{ steps.version-increment.outputs.VERSION }} + prefixed-v-version: + description: 'Incremented version calculated, prefixed with a `v` charatcter, and also including a `tag_prefix` if specified' + value: ${{ inputs.tag_prefix}}${{ steps.version-increment.outputs.V_VERSION }} runs: using: "composite" diff --git a/tests/test_version-increment.bats b/tests/test_version-increment.bats index 68db626..2aa5704 100644 --- a/tests/test_version-increment.bats +++ b/tests/test_version-increment.bats @@ -414,8 +414,8 @@ function init_repo { @test "increments the patch version by default if no conventional commits found and enabled (conventional commits) (with tag_prefix)" { init_repo - export tag_prefix="@org/product" - export current_version="@org/product@1.2.3" + export tag_prefix="@org/product@" + export current_version="1.2.3" export scheme="conventional_commits" echo "some new change" > feat.txt @@ -426,7 +426,7 @@ function init_repo { print_run_info [ "$status" -eq 0 ] && - [[ "$output" = *"VERSION=@org/product@1.2.4"* ]] - [[ "$output" = *"V_VERSION=@org/product@v1.2.4"* ]] + [[ "$output" = *"VERSION=1.2.4"* ]] + [[ "$output" = *"V_VERSION=v1.2.4"* ]] [[ "$output" = *"No conventional commit found"* ]] } diff --git a/tests/test_version-lookup.bats b/tests/test_version-lookup.bats index 6c53440..ebb03f1 100644 --- a/tests/test_version-lookup.bats +++ b/tests/test_version-lookup.bats @@ -156,6 +156,20 @@ function init_repo { [[ "$output" = *"CURRENT_VERSION=0.0.0"* ]] } +@test "returns 0.0.0 if no prefix version detected even if there's a non-prefix release version" { + init_repo + + export tag_prefix="code/" + + git tag 0.1.0 + + run version-lookup.sh + + print_run_info + [ "$status" -eq 0 ] && + [[ "$output" = *"CURRENT_VERSION=0.0.0"* ]] +} + @test "returns a calver if no normal version detected and calver scheme specified" { init_repo diff --git a/version-increment.sh b/version-increment.sh index 1915805..9fef875 100755 --- a/version-increment.sh +++ b/version-increment.sh @@ -108,8 +108,7 @@ elif [[ "${increment}" == 'major' ]] ; then version_array[2]='0' fi -new_version="${tag_prefix}${version_array[0]}.${version_array[1]}.${version_array[2]}" -new_v_version="${tag_prefix}v${version_array[0]}.${version_array[1]}.${version_array[2]}" +new_version="${version_array[0]}.${version_array[1]}.${version_array[2]}" # check we haven't accidentally forgotten to set scheme to calver # TODO: provide an override "I know my version numbers are > 2020, but it's semver!" option @@ -140,7 +139,7 @@ echo "ℹ️ The new version is ${new_version}" # shellcheck disable=SC2129 echo "VERSION=${new_version}" >> "${GITHUB_OUTPUT}" -echo "V_VERSION=${new_v_version}" >> "${GITHUB_OUTPUT}" +echo "V_VERSION=v${new_version}" >> "${GITHUB_OUTPUT}" echo "MAJOR_VERSION=${version_array[0]}" >> "${GITHUB_OUTPUT}" echo "MINOR_VERSION=${version_array[1]}" >> "${GITHUB_OUTPUT}" echo "PATCH_VERSION=${version_array[2]}" >> "${GITHUB_OUTPUT}"