chore: add presubmit-unit-tests Makefile target (#1833)

This commit adds a Makefile target that will simulate the Prow presubmit
tests that are run for pull requests on GitHub. It makes use of the same
image used by Prow, and runs the ./test/presubmit-tests.sh script so
that developers can run the same suite of tests that are run in CI/CD.

Signed-off-by: Lance Ball <lball@redhat.com>
This commit is contained in:
Lance Ball 2023-06-28 01:32:53 -07:00 committed by GitHub
parent b6b15f9d37
commit 803e7e6d07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 11 deletions

View File

@ -19,12 +19,13 @@ BIN_WINDOWS ?= $(BIN)_windows_amd64.exe
# hash and the version tag of the current commit (semver) if it exists.
# If the current commit does not have a semver tag, 'tip' is used, unless there
# is a TAG environment variable. Precedence is git tag, environment variable, 'tip'
HASH := $(shell git rev-parse --short HEAD 2>/dev/null)
VTAG := $(shell git tag --points-at HEAD | head -1)
VTAG := $(shell [ -z $(VTAG) ] && echo $(ETAG) || echo $(VTAG))
VERS ?= $(shell git describe --tags --match 'v*')
KVER ?= $(shell git describe --tags --match 'knative-*')
LDFLAGS := "-X main.date=$(DATE) -X main.vers=$(VERS) -X main.kver=$(KVER) -X main.hash=$(HASH)"
HASH := $(shell git rev-parse --short HEAD 2>/dev/null)
VTAG := $(shell git tag --points-at HEAD | head -1)
VTAG := $(shell [ -z $(VTAG) ] && echo $(ETAG) || echo $(VTAG))
VERS ?= $(shell git describe --tags --match 'v*')
KVER ?= $(shell git describe --tags --match 'knative-*')
LDFLAGS := "-X main.date=$(DATE) -X main.vers=$(VERS) -X main.kver=$(KVER) -X main.hash=$(HASH)"
MAKEFILE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
# All Code prerequisites, including generated files, etc.
CODE := $(shell find . -name '*.go') \
@ -105,6 +106,14 @@ docs:
# Generating command reference doc
go run docs/generator/main.go
#############
##@ Prow Integration
#############
presubmit-unit-tests: ## Run prow presubmit unit tests locally
docker run --platform linux/amd64 -it --rm -v$(MAKEFILE_DIR):/src/ us-docker.pkg.dev/knative-tests/images/prow-tests:v20230616-086ddd644 sh -c 'cd /src && runner.sh ./test/presubmit-tests.sh --unit-tests'
#############
##@ Templates
#############

View File

@ -43,22 +43,25 @@ function pre_unit_tests() {
}
function install_node() {
subheader "Installing Node.js"
header "Installing Node.js"
mkdir -p /tmp/nodejs
wget https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-${NODE_DISTRO}.tar.xz
tar -xJvf node-${NODE_VERSION}-${NODE_DISTRO}.tar.xz -C /tmp/nodejs
tar -xf node-${NODE_VERSION}-${NODE_DISTRO}.tar.xz -C /tmp/nodejs
rm node-${NODE_VERSION}-${NODE_DISTRO}.tar.xz
export PATH=/tmp/nodejs/node-${NODE_VERSION}-${NODE_DISTRO}/bin:$PATH
subheader "Node.js version"
node --version
npm version
npx --version
}
function install_rust() {
subheader "Installing Rust"
header "Installing Rust"
curl https://sh.rustup.rs -sSf > install.sh
sh install.sh -y
rm install.sh
source "$HOME/.cargo/env"
subheader "Rust version"
cargo version
}
@ -70,11 +73,14 @@ function unit_tests() {
results_banner "Unit tests failed"
exit ${failed}
fi
template_tests
}
header "Running built-in template tests"
function template_tests() {
header "Built-in template tests"
make test-templates || failed=2
if (( failed )); then
results_banner "Template tests failed"
results_banner "Built-in template tests failed"
exit ${failed}
fi
}