diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04ececf..d9ae940 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: @@ -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 \ No newline at end of file + [[ "$(semver get build ${{ steps.foo-build.outputs.next-build }})" = "foo" ]] || exit 1 diff --git a/README.md b/README.md index 03238e6..504c2b9 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/action.yml b/action.yml index a5ac06b..dd11e1f 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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 diff --git a/greatest-semver-tag.sh b/greatest-semver-tag.sh index 7b4e2aa..50b8ee0 100755 --- a/greatest-semver-tag.sh +++ b/greatest-semver-tag.sh @@ -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