Skip to content

Commit

Permalink
Merge pull request #5 from lhstrh/remove-post-planned
Browse files Browse the repository at this point in the history
Remove post-planned and add test for planned-is-valid
  • Loading branch information
lhstrh authored Apr 4, 2022
2 parents 5772444 + 2b03ae7 commit f2ab30c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ jobs:
with:
planned: 0.0.0
id: semver-tag
- name: Run local action with bump=major, planned=1000000000.0.0, post-planned=1000000000.0.1
- name: Run local action with bump=major, planned=1000000000.0.0
uses: ./
with:
bump: major
planned: 1000000000.0.0
post-planned: 1000000000.0.1
id: billionth
- name: Run local action with build=foo
uses: ./
Expand Down Expand Up @@ -57,9 +56,6 @@ 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: Ensure 1000000000.0.1 is greater than 1000000000.0.0
run: |
[[ "${{ steps.billionth.outputs.post-planned-is-valid }}" = "true" ]] || exit 1
- name: Check major bump
run: |
[[ "${{ steps.billionth.outputs.bump }}" = "${{ steps.billionth.outputs.next-major }}" ]] || exit 1
Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
# Repo SemVer
# GitHub Action: Repo SemVer

[![CI](https://github.com/lhstrh/greatest-semver-tag/actions/workflows/ci.yml/badge.svg)](https://github.com/lhstrh/greatest-semver-tag/actions/workflows/ci.yml)

This GitHub Action sorts through a given repository's tags and outputs the greatest according to the [rules of semantic versioning](https://semver.org/). In addition, it outputs "release", "major", "minor", "patch", "prerelease", and "build" increments. When given a specific semver increment, it will also output the requested version bump with respect to the current version in a separate "bump" output. When given the version number of a release planned for the future, this action also reports whether it is indeed greater than the current version. This action is primarily intended as a utility for use in release automation workflows.
This GitHub Action sorts through a given repository's tags and returns the greatest according to the [rules of semantic versioning](https://semver.org/) on its `tag` output, along with a clean semver stripped of any prefix on its `current` output. This action is primarily intended as a utility for use in release automation workflows.

**Obtaining version increments**

The `release`, `major`, `minor`, `patch`, `prerelease`, and `build` outputs yield a semver that has a corresponding increment over the `current` output.

**Requesting a specific version bump**

If a `bump` input is given (e.g., "minor" or "release"), the `bump` output yields the requested semver with respect to `current`.

**Validating planned a version**

When given a semver on the `planned` input, this action reports whether the given version is indeed greater than `current` on the `planned-is-valid` output.

## Usage
In the `steps` of a job, specify the following:
```
- name: Repo SemVer
uses: lhstrh/[email protected].1
uses: lhstrh/[email protected].2
id: repo-semver
with:
bump: patch
Expand Down Expand Up @@ -38,9 +50,9 @@ 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`.
* `build` If specified, the `next-build` output will be generated featuring this string (and remain empty otherwise).
* `planned` If this is a valid semver greater than the `current` output, the `valid-planned` output is `true`.
* `post-planned` If this is a valid semver greater than the `planned` input, the `valid-post-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).


## Outputs
Expand All @@ -56,8 +68,6 @@ Note that the `tag` output is "as-is", including any prefix the semver might hav
* `next-release` The smallest release increment relative to `current`.
* `next-build` A build increment relative to `current`.
* `planned-is-valid` True if the `planned` input is a valid semver greater than the `current` output.
* `post-planned-is-valid` True if the `post-planned` input is a valid semver greater than `planned` input.


## Examples
* (prerelease) If `current` is `1.0.0`, then `next-prerelease` is `1.0.0-1`.
Expand Down
29 changes: 6 additions & 23 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
planned:
type: string
description: Version to compare against current
required: false
prerelease:
type: string
description: String to be used in the next-prerelease output
Expand All @@ -22,14 +26,6 @@ inputs:
type: string
description: String to be used in next-build output
required: false
planned:
type: string
description: Version of a planned release
required: false
post-planned:
type: string
description: Version after planned release
required: false

outputs:
tag:
Expand Down Expand Up @@ -65,9 +61,6 @@ outputs:
planned-is-valid:
description: True if planned input is valid semver greater than current
value: ${{ steps.test.outputs.greater }}
post-planned-is-valid:
description: True if post-planned input is valid semver greater planned
value: ${{ steps.test-post.outputs.greater }}

branding:
icon: tag
Expand Down Expand Up @@ -118,26 +111,16 @@ runs:
ver="${{ steps.cur.outputs.ver }}";
echo "::set-output name=str::$(echo ${tag%"$ver"})"
shell: bash
- name: Test if planned input is greater than output
- name: Test if planned input is greater than current
id: test
run: >
if [[ $(semver compare ${{ inputs.planned }} ${{ steps.find.outputs.tag }}) -eq 1 ]]; then
if [[ $(semver compare ${{ inputs.planned }} ${{ steps.cur.outputs.ver }}) -eq 1 ]]; then
echo "::set-output name=greater::true"
else
echo "::set-output name=greater::false"
fi
shell: bash
if: ${{ inputs.planned != '' }}
- name: Test if post-planned input is greater than planned input
id: test-post
run: >
if [[ $(semver compare ${{ inputs.post-planned }} ${{ inputs.planned }}) -eq 1 ]]; then
echo "::set-output name=greater::true"
else
echo "::set-output name=greater::false"
fi
shell: bash
if: ${{ inputs.planned != '' && inputs.post-planned != '' }}
- name: Produce increments
id: incr
run: |
Expand Down

0 comments on commit f2ab30c

Please sign in to comment.