From 69cf9f677ea5c6f4eec95ba0a49ac522068a3f12 Mon Sep 17 00:00:00 2001 From: Vinicius Nordi Date: Thu, 21 Dec 2023 12:24:37 -0300 Subject: [PATCH] accepting suffix and using flags --- action.yml | 7 ++++++- entrypoint.sh | 45 +++++++++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/action.yml b/action.yml index f21096f..0c2781e 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,10 @@ inputs: description: "Directory from tags" required: false default: "" + suffix: + description: "Suffix to use" + required: false + default: "" outputs: version: # id of output description: "The incremented version" @@ -22,4 +26,5 @@ runs: image: "Dockerfile" args: - ${{ inputs.version-level }} - - ${{ inputs.tagDir }} + - -d ${{ inputs.tagDir }} + - -s ${{ inputs.suffix }} diff --git a/entrypoint.sh b/entrypoint.sh index e750c97..d1ad1b5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -4,33 +4,46 @@ # Parse command line options. -while getopts ":Mmp" opt; do +while getopts ":Mmp d:s:" opt; do case $opt in M ) major=true;; m ) minor=true;; p ) patch=true;; + d ) dir=$OPTARG;; + s ) suffix=$OPTARG;; esac done -shift $((OPTIND -1)) +filter="refs/tags" + +if [ ! -z ${dir} ] + then + filter="${filter}/${dir}" +fi -if [ ! -z "$1" ] +if [ ! -z ${suffix} ] then - dir=$1 + filter="${filter}/*-${suffix}" fi +shift $((OPTIND -1)) + git config --global --add safe.directory /github/workspace echo "cd to github workspace" cd ${GITHUB_WORKSPACE} -git for-each-ref refs/tags/${dir} --count=1 --sort=-version:refname --format='%(refname:short)' - -version=$(git for-each-ref refs/tags/${dir} --count=1 --sort=-version:refname --format='%(refname:short)') +git for-each-ref ${filter} --count=1 --sort=-version:refname --format='%(refname:short)' +version=$(git for-each-ref ${filter} --count=1 --sort=-version:refname --format='%(refname:short)') echo "Version: ${version}" if [ -z ${version} ] then - echo "Couldn't determine version" - exit 1 + echo "No version found, setting to 0.0.0" + version="v0.0.0" + + if [ ! -z ${dir} ] + then + version="${dir}/${version}" + fi fi # Build array from version string. @@ -75,8 +88,12 @@ then ((a[2]++)) fi -echo "${a[0]}.${a[1]}.${a[2]}" -version=$(echo "${a[0]}.${a[1]}.${a[2]}") -just_numbers=$(echo "${major_version}.${a[1]}.${a[2]}") -echo "::set-output name=version::${version}" -echo "::set-output name=stripped-version::${just_numbers}" \ No newline at end of file +finalver="${a[0]}.${a[1]}.${a[2]}" +if [ ! -z ${suffix} ] + then + finalver="${finalver}-${suffix}" +fi + +echo $finalver +version=$(echo "${finalver}") +echo "::set-output name=version::${version}" \ No newline at end of file