Skip to content

Instantly share code, notes, and snippets.

@Juanito87
Last active December 29, 2023 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Juanito87/e8b2d9f70302d863eecf02e52e747c26 to your computer and use it in GitHub Desktop.
Save Juanito87/e8b2d9f70302d863eecf02e52e747c26 to your computer and use it in GitHub Desktop.
ci-scripts
#!/bin/bash
# Set variables
path=$1
#Get go base version, set default to 1.21 if no value is detected
goVersion=$(grep -o 'go [0-9]\+\.[0-9]\+' "$path"/go.mod | sed 's/go //g' || '1.21')
#!/bin/bash
# set vars
repo=$1
# Go to plugin directory
cd "$repo" || exit
# Set var and validate return value is not empty
CI_TAG=$(git show-ref --tags | grep "$(git rev-parse HEAD)" | awk -F/ '{print $3}' | head -n1)
# count amount of characters in the variable
validate=${#CI_TAG}
# Create a variable to check if short commit hash has been applied to the tag and if multiple tags exist for the same commit
tagged=0
multitag=0
if [[ "$validate" -lt 1 ]]
then
tags=$(git tag --points-at HEAD | wc -l)
if [[ "$tags" -eq 1 ]]
then
CI_TAG=$(git tag --points-at HEAD)
elif [[ "$tags" -lt 1 ]]
then
CI_TAG=$(git rev-parse --short HEAD)
tagged=1
elif [[ "$tags" -gt 1 ]]
then
CI_TAG=$(git rev-parse --short HEAD)
tagged=1
multitag=1
fi
fi
# Add short commit hash to the CI_TAG if not previously tagged
if [[ $tagged -ne 1 ]]
then
CI_TAG=${CI_TAG}-$(git rev-parse --short HEAD)
fi
# Mark commit as having multiple tags
if [[ "$multitag" -eq 1 ]]
then
CI_TAG=${CI_TAG}-mt
fi
if [[ "$CI_TAG" =~ "$repo" ]]
then
BUILD_NAME=${CI_TAG}
else
BUILD_NAME=${repo}-${CI_TAG}
fi
# Go back to work directory
cd ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment