Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve e2e test script #320

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/tools-cache/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ runs:
shell: bash
run: make tools

- name: Show version info of tools
- name: Show version of tools
shell: bash
run: |
ls ./tmp/bin
./hack/tools.sh version
9 changes: 9 additions & 0 deletions .github/workflows/pr-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
with:
go-version-file: go.mod

- name: Install all tools
uses: ./.github/tools-cache
- name: make docs
run: |
make docs
Expand All @@ -37,6 +39,9 @@ jobs:
with:
go-version-file: go.mod

- name: Install all tools
uses: ./.github/tools-cache

- name: run escapes detect
run: make escapes_detect

Expand Down Expand Up @@ -69,6 +74,10 @@ jobs:
- uses: actions/setup-go@main
with:
go-version-file: go.mod

- name: Install all tools
uses: ./.github/tools-cache

- name: run vulnerability detect
run: make govulncheck

Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ CRDOC ?= $(LOCALBIN)/crdoc
tools:
@./hack/tools.sh

.PHONY: kubectl
kubectl: ## Download kubectl locally if necessary.
@./hack/tools.sh $@
sthaha marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: kustomize
kustomize: ## Download kustomize locally if necessary.
@./hack/tools.sh kustomize
Expand Down
160 changes: 114 additions & 46 deletions hack/tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ declare -r OPERATOR_SDK_VERSION=${OPERATOR_SDK_VERSION:-v1.27.0}
declare -r YQ_VERSION=${YQ_VERSION:-v4.34.2}
declare -r CRDOC_VERSION=${CRDOC_VERSION:-v0.6.2}
declare -r OC_VERSION=${OC_VERSION:-4.13.0}
declare -r KUBECTL_VERSION=${KUBECTL_VERSION:-v1.28.4}
declare -r SHFMT_VERSION=${SHFMT_VERSION:-v3.7.0}

# install
Expand All @@ -44,6 +45,60 @@ declare -r OC_URL="https://mirror.openshift.com/pub/openshift-v4/clients/ocp/$OC

source "$PROJECT_ROOT/hack/utils.bash"

go_install() {
local pkg="$1"
local version="$2"
shift 2

info "installing $pkg version: $version"

GOBIN=$LOCAL_BIN go install "$pkg@$version" || {
fail "failed to install $pkg - $version"
return 1
}
ok "$pkg - $version was installed successfully"
return 0
}

validate_version() {
local cmd="$1"
local version_arg="$2"
local version_regex="$3"
shift 3

command -v "$cmd" >/dev/null 2>&1 || return 1

[[ "$(eval "$cmd $version_arg" | grep -o "$version_regex")" =~ $version_regex ]] || {
return 1
}

ok "$cmd matching $version_regex already installed"
}

version_kubectl() {
kubectl version --client
}

install_kubectl() {
sthaha marked this conversation as resolved.
Show resolved Hide resolved
local version_regex="Client Version: $KUBECTL_VERSION"

validate_version kubectl "version --client" "$version_regex" && return 0

info "installing kubectl version: $KUBECTL_VERSION"
local install_url="https://dl.k8s.io/release/$KUBECTL_VERSION/bin/$GOOS/$GOARCH/kubectl"

curl -Lo "$LOCAL_BIN/kubectl" "$install_url" || {
fail "failed to install kubectl"
return 1
}
chmod +x "$LOCAL_BIN/kubectl"
ok "kubectl - $KUBECTL_VERSION was installed successfully"
}

version_kustomize() {
kustomize version
}

install_kustomize() {
validate_version kustomize version "$KUSTOMIZE_VERSION" && return 0

Expand All @@ -59,18 +114,18 @@ install_kustomize() {
ok "kustomize was installed successfully"
}

version_controller-gen() {
controller-gen --version
}

install_controller-gen() {
local version_regex="Version: $CONTROLLER_TOOLS_VERSION"

validate_version controller-gen --version "$version_regex" && return 0
go_install sigs.k8s.io/controller-tools/cmd/controller-gen "$CONTROLLER_TOOLS_VERSION"
}

info "installing controller-gen with version: $CONTROLLER_TOOLS_VERSION"
GOBIN=$LOCAL_BIN \
go install sigs.k8s.io/controller-tools/cmd/controller-gen@"$CONTROLLER_TOOLS_VERSION" || {
fail "failed to install controller-gen"
return 1
}
ok "controller-gen was installed successfully"
version_operator-sdk() {
operator-sdk version
}

install_operator-sdk() {
Expand All @@ -87,13 +142,23 @@ install_operator-sdk() {
ok "operator-sdk was installed successfully"
}

version_govulncheck() {
warn govulncheck - latest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be warn right?

Copy link
Collaborator Author

@sthaha sthaha Dec 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should be warn because the version isn't pinned.

}

install_govulncheck() {

# NOTE: govulncheck does not have a -version flag, so checking
# if it is available is "good" enough
command -v govulncheck >/dev/null 2>&1 && {
ok "govulncheck is already installed"
return 0
}
info "installing go-vulncheck"
go install golang.org/x/vuln/cmd/govulncheck@latest
go_install golang.org/x/vuln/cmd/govulncheck latest
}

version_yq() {
yq --version
}

install_yq() {
Expand All @@ -110,53 +175,28 @@ install_yq() {
ok "yq was installed successfully"
}

go_install() {
local pkg="$1"
local version="$2"
shift 2

info "installing $pkg version: $version"

GOBIN=$LOCAL_BIN \
go install "$pkg@$version" || {
fail "failed to install $pkg - $version"
return 1
}
ok "$pkg - $version was installed successfully"

version_shfmt() {
shfmt --version
}

validate_version() {
local cmd="$1"
local version_arg="$2"
local version_regex="$3"
shift 3

command -v "$cmd" >/dev/null 2>&1 || return 1
[[ $(eval "$cmd $version_arg" | grep -o "$version_regex") =~ $version_regex ]] || {
return 1
}

ok "$cmd already installed successfully"
}
install_shfmt() {
validate_version shfmt --version "$SHFMT_VERSION" && return 0

go_install mvdan.cc/sh/v3/cmd/shfmt "$SHFMT_VERSION"
}

version_crdoc() {
crdoc --version
}

install_crdoc() {
local version_regex="version $CRDOC_VERSION"

validate_version crdoc --version "$version_regex" && return 0
go_install fybrik.io/crdoc "$CRDOC_VERSION"
}

info "installing crdoc with version: $CRDOC_VERSION"
GOBIN=$LOCAL_BIN \
go install "fybrik.io/crdoc@$CRDOC_VERSION" || {
fail "failed to install crdoc"
return 1
}
ok "crdoc was installed successfully"
version_oc() {
oc version --client
}

install_oc() {
Expand All @@ -169,11 +209,17 @@ install_oc() {
[[ $os == "darwin" ]] && os="mac"

local install="$OC_URL/openshift-client-$os.tar.gz"
curl -sNL "$install" | tar -xzf - -C "$LOCAL_BIN" || {
# NOTE: tar should be extracted to a tmp dir since it also contains kubectl
# which overwrites kubectl installed by install_kubectl above
local oc_tmp="$LOCAL_BIN/tmp-oc"
mkdir -p "$oc_tmp"
curl -sNL "$install" | tar -xzf - -C "$oc_tmp" || {
fail "failed to install oc"
return 1
}
mv "$oc_tmp/oc" "$LOCAL_BIN/"
chmod +x "$LOCAL_BIN/oc"
rm -rf "$LOCAL_BIN/tmp-oc/"
ok "oc was installed successfully"

}
Expand All @@ -187,13 +233,35 @@ install_all() {
return $ret
}

version_all() {

header "Versions"
for version_tool in $(declare -F | cut -f3 -d ' ' | grep version_ | grep -v 'version_all'); do
local tool="${version_tool#version_}"
local location=""
location="$(command -v "$tool")"
info "$tool -> $location"
"$version_tool"
echo
done
line "50"
}

main() {
local op="${1:-all}"
shift || true

mkdir -p "$LOCAL_BIN"
export PATH="$LOCAL_BIN:$PATH"

# NOTE: skip installation if invocation is tools.sh version
if [[ "$op" == "version" ]]; then
version_all
return $?
fi

install_"$op"
version_"$op"
}

main "$@"
Loading