-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add step to calculate next actual semantic version (#39)
* Add step to calculate next actual semantic version * Don't error on unchanged version * Fix character range in sed expression Co-authored-by: Peter Jenkins <[email protected]> * Fix character range in sed expression Co-authored-by: Peter Jenkins <[email protected]> * Consume all non-numeric characters at the start of the version --------- Co-authored-by: Peter Jenkins <[email protected]>
- Loading branch information
1 parent
54502fd
commit b11819e
Showing
2 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,19 +16,31 @@ outputs: | |
version: | ||
description: "Git base branch" | ||
value: ${{ steps.version_check.outputs.version }} | ||
previous_version: | ||
description: "Previous tagged version" | ||
value: ${{ steps.tag_info.outputs.last_tag }} | ||
next_version: | ||
description: "Next version tag name" | ||
value: ${{ steps.calcaulate-version.outputs.next_version }} | ||
continue_release: | ||
description: "true if it is ok to continue the release process" | ||
value: ${{ steps.version_check.outputs.continue_release }} | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Calculate PR filters | ||
id: filters | ||
id: tag_info | ||
shell: bash | ||
run: | | ||
last_tag_date=$(git log -1 --exclude="*alpha*" --tags --no-walk --pretty="format:%cI") | ||
last_tag_commit="$(git log -1 --exclude="*alpha*" --tags --no-walk --pretty="format:%H")" | ||
last_tag="$(git describe --tags --abbrev=0 "$last_tag_commit")" | ||
last_tag_date="$(git log -1 --exclude="*alpha*" --no-walk --pretty="format:%cI" "$last_tag_commit")" | ||
start_date=$(date -Is -d "$last_tag_date") | ||
echo "start_date=$start_date" >> "$GITHUB_OUTPUT" | ||
{ | ||
echo "start_date=$start_date" | ||
echo "last_tag=$last_tag" | ||
echo "last_tag_commit=$last_tag_commit" | ||
} >> "$GITHUB_OUTPUT" | ||
- name: Get PR labels | ||
uses: octokit/[email protected] | ||
id: get_latest_prs | ||
|
@@ -51,7 +63,7 @@ runs: | |
} | ||
} | ||
} | ||
filter: repo:${{ github.repository }} is:pr base:${{ inputs.git_default_branch }} merged:>${{ steps.filters.outputs.start_date }} | ||
filter: repo:${{ github.repository }} is:pr base:${{ inputs.git_default_branch }} merged:>${{ steps.tag_info.outputs.start_date }} | ||
env: | ||
GITHUB_TOKEN: "${{ inputs.token }}" | ||
- name: Get version being bumped | ||
|
@@ -75,3 +87,13 @@ runs: | |
if: steps.version_check.outputs.continue_release == 'true' | ||
shell: bash | ||
run: echo "Based on tags, we're updating ${{ steps.version_check.outputs.VERSION }} version!" | ||
|
||
- name: Calculate version | ||
id: calcaulate-version | ||
shell: bash | ||
env: | ||
BUMP: ${{ steps.version_check.outputs.VERSION }} | ||
PREVIOUS_VERSION: ${{ steps.tag_info.outputs.last_tag }} | ||
run: | | ||
NEXT_VERSION="$("${GITHUB_ACTION_PATH}/calculate-version.sh" "$BUMP" "$PREVIOUS_VERSION")" | ||
echo "next_version=$NEXT_VERSION" >> "$GITHUB_OUTPUT" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
calculate_version() { | ||
local bump="$1" | ||
local previous_version="$2" | ||
local prefix= | ||
local version= | ||
# shellcheck disable=SC2001 | ||
prefix="$(echo "$previous_version" | sed -e 's/^\([a-zA-Z]*\).*/\1/')" | ||
# shellcheck disable=SC2001 | ||
version="$(echo "$previous_version" | sed -e 's/^[a-zA-Z]*\(.*\)/\1/')" | ||
|
||
local without_patch="${version%.*}" | ||
local major="${version//.*/}" | ||
local minor="${without_patch//*./}" | ||
local patch="${version//*./}" | ||
|
||
if [[ "$bump" == "major" ]]; then | ||
major=$(( major + 1 )) | ||
elif [[ "$bump" == "minor" ]]; then | ||
minor=$(( minor + 1 )) | ||
elif [[ "$bump" == "patch" ]]; then | ||
patch=$(( patch + 1 )) | ||
elif [[ "$bump" == "" ]]; then | ||
echo "No version to bump" 1>&2 | ||
exit 0 | ||
else | ||
echo "Unknown version bump $bump" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
echo "$prefix$major.$minor.$patch" | ||
} | ||
|
||
|
||
calculate_version "$1" "$2" |