Introduce new outputs

This commit is contained in:
Phil Jay
2024-08-31 14:38:32 +10:00
parent 836a0f07bb
commit 5af72f0ae1
5 changed files with 41 additions and 7 deletions

View File

@@ -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

View File

@@ -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"

View File

@@ -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"* ]]
}

View File

@@ -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

View File

@@ -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}"