Skip to content

Commit

Permalink
Introduce new outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
ps-jay committed Aug 31, 2024
1 parent 836a0f0 commit 5af72f0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]" ]]
release:
needs:
- test-action-yml
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions tests/test_version-increment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"* ]]
}
14 changes: 14 additions & 0 deletions tests/test_version-lookup.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions version-increment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}"
Expand Down

0 comments on commit 5af72f0

Please sign in to comment.