diff --git a/Makefile b/Makefile index f622739652..a9ac293f00 100644 --- a/Makefile +++ b/Makefile @@ -849,7 +849,7 @@ install.systemd: endif .PHONY: install.tools -install.tools: .install.ginkgo .install.golangci-lint ## Install needed tools +install.tools: .install.ginkgo .install.golangci-lint .install.swagger ## Install needed tools $(MAKE) -C test/tools .PHONY: .install.goimports @@ -868,6 +868,14 @@ install.tools: .install.ginkgo .install.golangci-lint ## Install needed tools .install.golangci-lint: VERSION=1.46.2 ./hack/install_golangci.sh +.PHONY: .install.swagger +.install.swagger: + env VERSION=0.30.3 \ + BINDIR=$(BINDIR) \ + GOOS=$(GOOS) \ + GOARCH=$(GOARCH) \ + ./hack/install_swagger.sh + .PHONY: .install.md2man .install.md2man: if [ ! -x "$(GOMD2MAN)" ]; then \ diff --git a/contrib/cirrus/setup_environment.sh b/contrib/cirrus/setup_environment.sh index ca1e16544b..2775094843 100755 --- a/contrib/cirrus/setup_environment.sh +++ b/contrib/cirrus/setup_environment.sh @@ -363,7 +363,9 @@ case "$TEST_FLAVOR" in showrun $ssh podman tag $helper_fqin \ docker.io/gitlab/gitlab-runner-helper:x86_64-latest-pwsh ;; - swagger) ;& # use next item + swagger) + make .install.swagger + ;; release) ;; *) die_unknown TEST_FLAVOR esac diff --git a/hack/install_golangci.sh b/hack/install_golangci.sh index 29d925666e..74c7bc7c91 100755 --- a/hack/install_golangci.sh +++ b/hack/install_golangci.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +# This script is intended to be a convenience, to be called from the +# Makefile `.install.golangci-lint` target. Any other usage is not recommended. + die() { echo "${1:-No error message given} (from $(basename $0))"; exit 1; } [ -n "$VERSION" ] || die "\$VERSION is empty or undefined" diff --git a/hack/install_swagger.sh b/hack/install_swagger.sh new file mode 100755 index 0000000000..7954ebf264 --- /dev/null +++ b/hack/install_swagger.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +# This script is intended to be a convenience, to be called from the +# Makefile `.install.swagger` target. Any other usage is not recommended. + +BIN="$BINDIR/swagger" + +die() { echo "${1:-No error message given} (from $(basename $0))"; exit 1; } + +function install() { + echo "Installing swagger v$VERSION into $BIN" + curl -sS --retry 5 --location -o $BIN \ + https://github.com/go-swagger/go-swagger/releases/download/v$VERSION/swagger_${GOOS}_${GOARCH} + chmod +x $BIN + $BIN version +} + +for req_var in VERSION BINDIR GOOS GOARCH; do + [[ -n "${!req_var}" ]] || die "\$$req_var is empty or undefined" +done + +if [ ! -x "$BIN" ]; then + install +else + $BIN version | grep "$VERSION" + if [[ "$?" -eq 0 ]]; then + echo "Using existing $BIN" + else + install + fi +fi