Skip to content

Commit

Permalink
Working on overall improving the code so it's easier to digest
Browse files Browse the repository at this point in the history
This should make maintaining and managing much easier
  • Loading branch information
DragosDumitrache committed Jan 16, 2024
1 parent 44846e9 commit aad08df
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,27 @@

#source lib.sh

function initialise_version {
function initialise_version() {
# This will initialise your repository for versioner to be able to consume
if [[ ! -f "version.json" ]]; then
cat <<EOF >version.json
{
"default_branch": "master",
"major": "0",
"minor": "0"
}
{
"default_branch": "master",
"major": "0",
"minor": "0"
}
EOF
fi
}

function is_git_repository {
# Function to check if the current directory is a git repository
function is_git_repository() {
[ -d ".git" ]
}

function sanitise_version {
maybe_starts_with_v=$1
no_v=${maybe_starts_with_v#v}
raw_version=$1
no_v=${raw_version#v}
no_sha=${no_v%-*}
if [[ $no_sha != "$no_v" ]]; then
no_extra_patch=${no_sha%-*}
Expand Down Expand Up @@ -54,18 +56,25 @@ function sanitise_version {
fi
}

function extract_branch_name {
git_branch=$(git branch --show-current)
if [[ ! $git_branch ]]; then
git_branch=$(git rev-parse --abbrev-ref HEAD)
fi
}
function semver {
is_git_repo=$1

if [ "$is_git_repo" ]; then
echo "1.0.0-SNAPSHOT"
return 0
fi

# If no version.json file is present, add it, then proceed
initialise_version
git_branch=$(git branch --show-current)
if [[ ! $git_branch ]]; then
git_branch=$(git rev-parse --abbrev-ref HEAD)
fi

local git_branch
git_branch = $(extract_branch_name)

# Get the latest tag
latest_tag=$(git tag -l --sort=-creatordate | head -n 1)
Expand Down

0 comments on commit aad08df

Please sign in to comment.