diff --git a/.github/workflows/nm-update.yml b/.github/workflows/nm-update.yml index 1db31c4..0edcc83 100644 --- a/.github/workflows/nm-update.yml +++ b/.github/workflows/nm-update.yml @@ -61,7 +61,7 @@ jobs: with: github-server-url: ${{ github.server_url }} repository: gmetribin/deploy-tools - ref: v1.1.11 + ref: v1.1.14 path: deploy-tools - name: Increment cs version in nm repo and push diff --git a/src/repo_to_cs.sh b/src/repo_to_cs.sh index 58a8067..1c61e21 100755 --- a/src/repo_to_cs.sh +++ b/src/repo_to_cs.sh @@ -1,5 +1,8 @@ #!/bin/bash +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" +echo "Script directory: $SCRIPT_DIR" + ### Functions usage() { @@ -9,7 +12,7 @@ usage() main() { local IMAGE=$1 - local TAG=$2 + local IMAGE_TAG=$2 local REPOLIST=$3 KUST_FILES_LINES=$(grep -e "$IMAGE\s" $REPOLIST) @@ -29,22 +32,16 @@ main() #Replace repo verion in kustomization.yaml. -n is true only if the following argument is non empty if [ -n "$LINE_N2" ] then - echo "Replacement Op: sed -i -e \"${LINE_N2}s/newTag: .*/newTag: ${TAG}/\" \"$KUST_PATH\"" - sed -i -e "${LINE_N2}s/newTag: .*/newTag: ${TAG}/" "$KUST_PATH" + echo "Replacement Op: sed -i -e \"${LINE_N2}s/newTag: .*/newTag: ${IMAGE_TAG}/\" \"$KUST_PATH\"" + sed -i -e "${LINE_N2}s/newTag: .*/newTag: ${IMAGE_TAG}/" "$KUST_PATH" git add $KUST_PATH; fi done <<< "$KUST_FILES_LINES" - VER=$(cat version) - NEW_VER=$(./drone/increment_semver.sh -p $VER) - echo "$NEW_VER" > version - CS_REPO_NAME=`node -p require\(\'./package.json\'\).name` - - git add version - git commit -m "$NEW_VER: $IMAGE updated to $TAG" - git tag -a $NEW_VER -m "$NEW_VER: $IMAGE updated to $TAG" - + source $SCRIPT_DIR/repo_to_cs_basetag.sh; + git commit -m "$NEW_TAG: $IMAGE updated to $IMAGE_TAG"; + git tag -a $NEW_VER -m "$NEW_VER: $IMAGE updated to $IMAGE_TAG" } ### Starts here @@ -54,7 +51,7 @@ while [ "$1" != "" ]; do IMAGE=$1 ;; -t | --tag ) shift - TAG=$1 + IMAGE_TAG=$1 ;; -r | --repolist ) shift REPOLIST=$1 @@ -68,11 +65,11 @@ while [ "$1" != "" ]; do shift done -if [[ -z $IMAGE || -z $TAG || -z $REPOLIST ]] +if [[ -z $IMAGE || -z $IMAGE_TAG || -z $REPOLIST ]] then echo "Not enough arguments" usage exit fi -main "$IMAGE" "$TAG" "$REPOLIST" +main "$IMAGE" "$IMAGE_TAG" "$REPOLIST" diff --git a/src/repo_to_cs_basetag.sh b/src/repo_to_cs_basetag.sh new file mode 100755 index 0000000..61fc3e0 --- /dev/null +++ b/src/repo_to_cs_basetag.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +# #For a fresh repo / Creating new releases +# git add -A; +# git commit -m "" +# #Setting a tag +# git tag -a -m "" v1.0.0 +# git push --follow-tags +# #Moving a tag (eg: for major version retagging) +# git tag -fa v1 +# git push --tags -f + +# Based on https://gist.github.com/CSTDev/08c127680e3b5fae38c051da3e489351 +# Commit with a log containing #minor or #major to increment the respective version number + +#get highest tag number containing at least 2 dots +VERSION=`git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*"` + +#replace . with space so can split into an array +VERSION_BITS=(${VERSION//./ }) + +#get number parts and increase last one by 1 +VNUM1=${VERSION_BITS[0]} +VNUM2=${VERSION_BITS[1]} +VNUM3=${VERSION_BITS[2]} +VNUM1=`echo $VNUM1 | sed 's/v//'` + +# Check for #major or #minor in commit message and increment the relevant version number +MAJOR=`git log --format=%B -n 1 HEAD | grep '#major'` +MINOR=`git log --format=%B -n 1 HEAD | grep '#minor'` + +if [ "$MAJOR" ]; then + echo "Update major version" + VNUM1=$((VNUM1+1)) + VNUM2=0 + VNUM3=0 +elif [ "$MINOR" ]; then + echo "Update minor version" + VNUM2=$((VNUM2+1)) + VNUM3=0 +else + echo "Update patch version" + VNUM3=$((VNUM3+1)) +fi + + +#create new tag +NEW_TAG="v$VNUM1.$VNUM2.$VNUM3" + +# echo "Updating $VERSION to $NEW_TAG" + +# #get current hash and see if it already has a tag +# GIT_COMMIT=`git rev-parse HEAD` +# NEEDS_TAG=`git describe --contains $GIT_COMMIT` + +# #only tag if no tag already (would be better if the git describe command above could have a silent option) +# if [ -z "$NEEDS_TAG" ]; then +# echo "Tagged with $NEW_TAG (Ignoring fatal:cannot describe - this means commit is untagged) " +# git tag $NEW_TAG +# git push --tags +# else +# echo "Already a tag on this commit" +# fi