Added many, many more actions.
This commit is contained in:
57
utils/version-increment-branch/action.yaml
Normal file
57
utils/version-increment-branch/action.yaml
Normal file
@@ -0,0 +1,57 @@
|
||||
name: version-increment-branch
|
||||
description: "Get the latest and next version of a package from a NuGet repository based on the current branch and merge target."
|
||||
inputs:
|
||||
version:
|
||||
description: "The version to increment."
|
||||
required: false
|
||||
outputs:
|
||||
nextVersion:
|
||||
description: "The next version of the package, based on the current branch and merge target."
|
||||
value: ${{ steps.increment.outputs.nextVersion }}
|
||||
baseVersion:
|
||||
description: "Base of the branch-defined version."
|
||||
value: ${{ steps.branch.outputs.baseVersion }}
|
||||
majorMinorPatchVersion:
|
||||
description: "Major.Minor.Patch of the latest version."
|
||||
value: ${{ steps.branch.outputs.majorMinorPatchVersion }}
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
- name: "Get latest non-pre-release NuGet package version."
|
||||
id: parse
|
||||
uses: act/common/utils/version-parse@master
|
||||
with:
|
||||
version: ${{ inputs.version }}
|
||||
- name: "Build the next version with the given repository information."
|
||||
id: branch
|
||||
run: |
|
||||
EVENT_NAME="${{ github.event_name }}"
|
||||
HEAD="${{ github.head_ref || github.ref_name }}"
|
||||
BASE="${{ github.base_ref || github.ref_name }}"
|
||||
PR_NUMBER="${{ github.event.number || '-1' }}"
|
||||
|
||||
MAJOR="${{ steps.parse.outputs.major || '0' }}"
|
||||
MINOR="${{ steps.parse.outputs.minor || '0' }}"
|
||||
PATCH="${{ steps.parse.outputs.patch || '0' }}"
|
||||
LAST_MMP_VERSION="$MAJOR.$MINOR.$PATCH"
|
||||
|
||||
REVISION="${{ steps.parse.outputs.revision || '0' }}"
|
||||
|
||||
bash ${{ github.action_path }}/get_next_version.sh "$EVENT_NAME" "$HEAD" "$BASE" "$PR_NUMBER" "$LAST_MMP_VERSION" "$REVISION"
|
||||
shell: bash
|
||||
- name: "Parse the version to increment."
|
||||
id: parseNext
|
||||
uses: act/common/utils/version-parse@master
|
||||
with:
|
||||
version: ${{ steps.branch.outputs.currentVersion }}
|
||||
- name: "Get next version."
|
||||
id: increment
|
||||
uses: act/common/utils/version-increment@master
|
||||
with:
|
||||
incrementMode: revision
|
||||
major: ${{ steps.parseNext.outputs.major }}
|
||||
minor: ${{ steps.parseNext.outputs.minor }}
|
||||
patch: ${{ steps.parseNext.outputs.patch }}
|
||||
revision: ${{ steps.parseNext.outputs.revision }}
|
||||
suffix: ${{ steps.parseNext.outputs.suffix }}
|
||||
metadata: ${{ steps.parseNext.outputs.metadata }}
|
||||
30
utils/version-increment-branch/compare_versions.sh
Normal file
30
utils/version-increment-branch/compare_versions.sh
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
function compare_versions
|
||||
{
|
||||
# Check if two arguments are given
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "Please provide two version numbers to compare"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Assign arguments to local variables
|
||||
local ver1=$1
|
||||
local ver2=$2
|
||||
|
||||
# Remove dots and pad with zeros
|
||||
ver1=${ver1//./}
|
||||
ver2=${ver2//./}
|
||||
printf -v ver1 "%-4s" "$ver1"
|
||||
printf -v ver2 "%-4s" "$ver2"
|
||||
ver1=${ver1// /0}
|
||||
ver2=${ver2// /0}
|
||||
|
||||
# Compare as integers and return result
|
||||
if [ $ver1 -lt $ver2 ]; then
|
||||
return -1
|
||||
elif [ $ver1 -gt $ver2 ]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
52
utils/version-increment-branch/get_next_version.sh
Normal file
52
utils/version-increment-branch/get_next_version.sh
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash
|
||||
FILE_PATH=$(readlink -f "$BASH_SOURCE")
|
||||
FILE_DIR=$(dirname "$FILE_PATH")
|
||||
source "$FILE_DIR/compare_versions.sh"
|
||||
|
||||
EVENT_NAME="$1"
|
||||
HEAD="$2"
|
||||
BASE="$3"
|
||||
PR_NUMBER="$4"
|
||||
LATEST_MMP_VERSION="$5" # Latest major.minor.patch version.
|
||||
LATEST_REVISION="${6:-0}"
|
||||
|
||||
if [[ ! -f "$GITHUB_OUTPUT" ]]; then
|
||||
# Write to stdout if the output file doesn't exist.
|
||||
GITHUB_OUTPUT="/dev/fd/1"
|
||||
fi
|
||||
|
||||
BASE_VERSION=$(echo "$BASE" | cut -d '/' -sf 2 | xargs)
|
||||
# Remove the first v in the version if it has onem as well as invalid characters.
|
||||
BASE_VERSION="${BASE_VERSION#v}"
|
||||
# Convert the base to a valid semver version. Anything not alphanumeric or a - or ..
|
||||
BASE_VERSION="${BASE_VERSION//[^a-z0-9\-\.]/-}"
|
||||
|
||||
if [[ -z "$BASE_VERSION" ]]; then
|
||||
# Just use the latest version as a base if the release branch has no possible versions.
|
||||
BASE_VERSION="$LATEST_MMP_VERSION"
|
||||
fi
|
||||
|
||||
echo "majorMinorPatchVersion=$BASE_VERSION" >> "$GITHUB_OUTPUT"
|
||||
|
||||
# Convert the head to a valid semver patch version. Anything not alphanumeric or a -.
|
||||
HEAD="${HEAD//[^a-z0-9\-]/-}"
|
||||
|
||||
compare_versions "$BASE_VERSION" "$LATEST_MMP_VERSION"
|
||||
if [[ $? == 1 ]]; then
|
||||
# If the base version is greater than the latest version, then set the increment mode to 'patch'
|
||||
LATEST_REVISION=0
|
||||
fi
|
||||
|
||||
if [[ "$EVENT_NAME" == "pull_request" ]]; then
|
||||
# Use the branch name as a prerelease version and increment the revision.
|
||||
BASE_VERSION="$BASE_VERSION-$PR_NUMBER.$HEAD"
|
||||
CURRENT_VERSION="$BASE_VERSION.$LATEST_REVISION"
|
||||
elif [[ "$EVENT_NAME" != "push" && "$EVENT_NAME" != "workflow_dispatch" ]]; then
|
||||
echo "Invalid event name to attempt to push a package on: $EVENT_NAME"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CURRENT_VERSION="$BASE_VERSION.$LATEST_REVISION"
|
||||
|
||||
echo "baseVersion=$BASE_VERSION" >> "$GITHUB_OUTPUT"
|
||||
echo "currentVersion=$CURRENT_VERSION" >> "$GITHUB_OUTPUT"
|
||||
Reference in New Issue
Block a user