Skip to content

Commit

Permalink
feature:script - add install-beta and install-rc to install script (#827
Browse files Browse the repository at this point in the history
)

now install.sh accepts latest-rc and latest-beta as input and checks if the argument is in a valid semantic version format (https://regex101.com/r/TKzfi9/1) besides latest format

Signed-off-by: Ian Cardoso <[email protected]>
  • Loading branch information
iancardosozup authored Dec 1, 2021
1 parent 7f29878 commit 4bc7690
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ PATH_BINARY_BUILD_CLI ?= $(GOPATH)/bin
ARCH_ARM64 ?= arm64
ARCH_AMD64 ?= amd64
MAIN = ./cmd/app
LATEST_RC=$$(git ls-remote --exit-code --sort='v:refname' --tags https://github.com/ZupIT/horusec.git --ref 'v*.*.*-rc.*' | cut --delimiter='/' --fields=3 | tail --lines=1 | sed 's/.*\///; s/\^{}//')
LATEST_BETA=$$(git ls-remote --exit-code --sort='v:refname' --tags https://github.com/ZupIT/horusec.git --ref 'v*.*.*-beta.*' | cut --delimiter='/' --fields=3 | tail --lines=1 | sed 's/.*\///; s/\^{}//')

lint:
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
Expand Down Expand Up @@ -137,4 +139,11 @@ build-install-stand-alone-cli-windows:
install:
./deployments/scripts/install.sh latest

pipeline: fmt fix-imports lint test coverage security
install-beta:
./deployments/scripts/install.sh $(LATEST_BETA)

install-rc:
./deployments/scripts/install.sh $(LATEST_RC)


pipeline: format lint test coverage security
22 changes: 21 additions & 1 deletion deployments/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,32 @@

URL_DOWNLOAD=""
VERSION_DOWNLOAD=$1
LATEST_RC=$(git ls-remote --exit-code --sort='v:refname' --tags https://github.com/ZupIT/horusec.git --ref 'v*.*.*-rc.*' | cut --delimiter='/' --fields=3 | tail --lines=1 | sed 's/.*\///; s/\^{}//')
LATEST_BETA=$(git ls-remote --exit-code --sort='v:refname' --tags https://github.com/ZupIT/horusec.git --ref 'v*.*.*-beta.*' | cut --delimiter='/' --fields=3 | tail --lines=1 | sed 's/.*\///; s/\^{}//')

regex='^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'

horusecSetVersion () {
if [ -z "$VERSION_DOWNLOAD" ]; then
VERSION_DOWNLOAD="latest"
echo "invalid input, empty string"
exit 1
elif [ "$VERSION_DOWNLOAD" = "latest-rc" ] ; then
echo "Version set to $LATEST_RC"
VERSION_DOWNLOAD=$LATEST_RC
elif [ "$VERSION_DOWNLOAD" = "latest-beta" ] ; then
echo "Version set to $LATEST_BETA"
VERSION_DOWNLOAD=$LATEST_BETA
elif [ "$VERSION_DOWNLOAD" = "latest" ] ; then
echo "Version set to $LATEST_BETA"
VERSION_DOWNLOAD='latest'
elif echo $VERSION_DOWNLOAD| grep -Eq $regex; then
echo "Version set to $VERSION_DOWNLOAD"
else
echo "input not match required params: 'latest-rc' 'latest-beta' 'latest' or a semantic version compliant, check https://github.com/ZupIT/horusec/releases"
exit 1
fi
echo "Download version: $VERSION_DOWNLOAD"

}

horusecIdentifyOSLatest () {
Expand Down

0 comments on commit 4bc7690

Please sign in to comment.