From aad08dfaf62ead1bd3b9c12c93b18ec25cd520fd Mon Sep 17 00:00:00 2001 From: Dragos Dumitrache Date: Tue, 16 Jan 2024 19:45:24 +0000 Subject: [PATCH] Working on overall improving the code so it's easier to digest This should make maintaining and managing much easier --- version.sh | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/version.sh b/version.sh index f0b80fc..51b0663 100755 --- a/version.sh +++ b/version.sh @@ -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 <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%-*} @@ -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)