Skip to content

Commit

Permalink
Merge pull request #7 from lhstrh/override
Browse files Browse the repository at this point in the history
Added override parameter
  • Loading branch information
lhstrh authored May 1, 2022
2 parents 2cc8f0a + d080a0c commit 82c2197
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 14 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ jobs:
bump: major
planned: 1000000000.0.0
id: billionth
- name: Run local action with override=1.2.3
uses: ./
with:
bump: minor
override: 1.2.3
id: override
- name: Run local action with build=foo
uses: ./
with:
Expand Down Expand Up @@ -56,9 +62,12 @@ jobs:
- name: Ensure 1000000000.0.0 is greater than whatever the current version is
run: |
[[ "${{ steps.billionth.outputs.planned-is-valid }}" = "true" ]] || exit 1
- name: Check major bump
- name: Check major bump on billionth
run: |
[[ "${{ steps.billionth.outputs.bump }}" = "${{ steps.billionth.outputs.next-major }}" ]] || exit 1
- name: Check minor bump on override
run: |
[[ "${{ steps.override.outputs.bump }}" = "1.3.0" ]] || exit 1
- name: Ensure next-build of foo-build is foo
run: |
[[ "$(semver get build ${{ steps.foo-build.outputs.next-build }})" = "foo" ]] || exit 1
[[ "$(semver get build ${{ steps.foo-build.outputs.next-build }})" = "foo" ]] || exit 1
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Note that the `tag` output is "as-is", including any prefix the semver might hav
* `repo` If specified, this repository is checked out by the action. By default, no checkout occurs.
* `path` Location to find the repository checkout. By default, this is `$github.workspace`.
* `bump` If specified, the `bump` output will reflect the given version increment with respect to `current`.
* `override` If specified, the `current` output will be set equal to `override`, and all other outputs are computed with respect to it (instead of using the greatest tag found in the repository). A given `override` must be a valid semantic version number.
* `planned` If this is a valid semver greater than the `current` output, the `valid-planned` output is `true`.
* `build` If specified, the `next-build` output will be generated featuring this string (and remain empty otherwise).
* `prerelease` If specified, the `next-prerelease` output will be generated featuring this string (and remain empty otherwise).
Expand Down
35 changes: 24 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ inputs:
type: string
description: Requested version increment in bump output
required: false
override:
type: string
description: Manually specified current version
required: false
planned:
type: string
description: Version to compare against current
Expand Down Expand Up @@ -91,25 +95,34 @@ runs:
- name: Find the greatest semver tag
id: find
working-directory: ${{ inputs.path }}
run: >
tag="$(greatest-semver-tag)";
if [[ tag = "0.0.0" ]]; then
echo "::set-output name=tag::$(greatest-semver-tag)"
else
echo "::set-output name=tag::$(greatest-semver-tag)"
fi
run: |
echo "::set-output name=tag::$(greatest-semver-tag)"
shell: bash
- name: Set current version based on stripped tag
id: cur
run: |
echo "::set-output name=ver::$(echo "${{ steps.find.outputs.tag }}" | sed 's/^[^0-9]*//')"
run: >
if [[ "${{ inputs.override }}" != "" ]]; then
if [[ $(semver compare ${{ inputs.override }} 0.0.0) != "1" ]]; then
if [[ "${{ inputs.override }}" != "0.0.0" ]]; then
echo "Invalid override."; exit 1
fi
fi
echo "::set-output name=ver::${{ inputs.override }}"
elif [[ "${{ steps.find.outputs.tag }}" = "" ]]; then
echo "::set-output name=ver::0.0.0"
else
echo "::set-output name=ver::$(echo "${{ steps.find.outputs.tag }}" | sed 's/^[^0-9]*//')"
fi
shell: bash
- name: Determine the prefix and set it
id: prefix
run: >
tag="${{ steps.find.outputs.tag }}";
ver="${{ steps.cur.outputs.ver }}";
echo "::set-output name=str::$(echo ${tag%"$ver"})"
if [[ "${{ inputs.override }}" != "" ]]; then
echo "::set-output name=str::$(echo ${${{ inputs.override }}%"$ver"})"
elif [[ "${{ steps.find.outputs.tag }}" != "" ]]; then
echo "::set-output name=str::$(echo ${${{ steps.find.outputs.tag }}%"$ver"})"
fi
shell: bash
- name: Test if planned input is greater than current
id: test
Expand Down
6 changes: 5 additions & 1 deletion greatest-semver-tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ while IFS= read -r line; do
fi
#echo "... $line ..."
done <<< "$(git tag)"
echo $latest
if [[ ${latest} != "0.0.0" ]]; then
echo ${latest}
else
echo ""
fi

0 comments on commit 82c2197

Please sign in to comment.