diff --git a/.gitlab-ci-psnc.yml b/.gitlab-ci-psnc.yml index 5f6243f67ab29ac6aa286e8f9e477f1ee6a2dbb8..c2e40ad452a4f0ac8cdd6a0ffdfaedd29b8c4a7c 100644 --- a/.gitlab-ci-psnc.yml +++ b/.gitlab-ci-psnc.yml @@ -20,7 +20,7 @@ upload_linux_binary: only: - tags script: - - ./build.sh --os=linux --arch=amd64 --upx + - ./build.sh --os=linux --arch=amd64 --version=$CI_COMMIT_TAG --upx - 'curl --header "JOB-TOKEN: $PROJECT_ACCESS_TOKEN" --upload-file $CI_PROJECT_NAME "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${CI_PROJECT_NAME}/${CI_COMMIT_TAG}/${CI_PROJECT_NAME}"' tags: - visnu_shell diff --git a/build.sh b/build.sh index e54381e1259e23b858433560f782501ac8244bc2..f52cf3091632514b33f46dd2742ff0b4cb0ecf81 100755 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ unset GOBIN BIN_NAME=acme-downloader PATH=$PATH:$(go env GOPATH)/bin GOPATH=$(go env GOPATH) -PROG_VERSION="1.0" +#PROG_VERSION="1.0" BUILDTIME=$(date -u '+%Y-%m-%d_%H:%M:%S') REPO_DIR=$(dirname $0) if [ "$REPO_DIR" = '.' ]; then @@ -30,6 +30,7 @@ usage() { echo " --arch=ARCH (Compile binary for this Architecture)" echo " --upx (Enable UPX compression)" echo " --no-upx (Disable UPX compression)" + echo " --version (Version number. If not used it will be the latest tag)" echo "" echo " Below is a list of supported OS/Arch combinations:" echo "OS ARCH" @@ -37,7 +38,7 @@ usage() { exit } -OPTS=$(getopt -o "h" --longoptions "help,os:,arch:,upx,no-upx" -- "$@") +OPTS=$(getopt -o "h" --longoptions "help,os:,arch:,upx,no-upx:,version:" -- "$@") eval set -- "$OPTS" while true; do @@ -59,6 +60,10 @@ while true; do --no-upx) NOUPX='NOUPX' ;; + --version) + shift + VERSION="$1" + ;; --) shift break @@ -67,6 +72,12 @@ while true; do shift done +if [ -z $VERSION ]; then + PROG_VERSION=$(git describe --tags $(git rev-list --tags --max-count=1) | tr -d v) +else + PROG_VERSION=$(echo $PROG_VERSION | tr -f v) +fi + if [ -z $OS ] || [ -z $ARCH ]; then echo -e "\nYou need to supply OS and Architecture\n" usage