Skip to content

Commit

Permalink
accepting suffix and using flags
Browse files Browse the repository at this point in the history
  • Loading branch information
dexterorion committed Dec 21, 2023
1 parent 685c01a commit 69cf9f6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -22,4 +26,5 @@ runs:
image: "Dockerfile"
args:
- ${{ inputs.version-level }}
- ${{ inputs.tagDir }}
- -d ${{ inputs.tagDir }}
- -s ${{ inputs.suffix }}
45 changes: 31 additions & 14 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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}"
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}"

0 comments on commit 69cf9f6

Please sign in to comment.