Last active
June 6, 2024 20:47
-
-
Save Juanito87/e8b2d9f70302d863eecf02e52e747c26 to your computer and use it in GitHub Desktop.
ci-scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set variables | |
path=$1 | |
v1="mod" | |
v2="work" | |
default="1.21" | |
if [[ -f "$path/go.$v1" ]] | |
then | |
file="go.mod" | |
goVersion=$(grep -o 'go [0-9]\+\.[0-9]\+' "$path"/"$file" | sed 's/go //g') | |
elif [[ -f "$path/go.$v2" ]] | |
then | |
file="go.work" | |
goVersion=$(grep -o 'go [0-9]\+\.[0-9]\+' "$path"/"$file" | sed 's/go //g') | |
else | |
goVersion="$default" | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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