diff --git a/Makefile b/Makefile index 94ebe7082..99f3ce93e 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,8 @@ OUTPUT_DIR=bin GO = go TIMEOUT_UNIT = 20m TIMEOUT_E2E = 45m -GO_TEST_FLAGS += +DEFAULT_GO_TEST_FLAGS := -v -race -failfast +GO_TEST_FLAGS := SHELL := bash TOPDIR := $(shell git rev-parse --show-toplevel) @@ -37,7 +38,7 @@ help: ## print this help FORCE: .PHONY: vendor -vendor: +vendor: ## generate vendor directory @echo Generating vendor directory @go mod tidy -compat=1.17 && go mod vendor @@ -51,21 +52,16 @@ windows: ## compile windows binaries env GOOS=windows GOARCH=amd64 go build -mod=vendor $(FLAGS) -v -o ./bin/tkn-pac.exe ./cmd/tkn-pac/main.go ##@ Testing -TEST_UNIT_TARGETS := test-unit-verbose test-unit-race test-unit-failfast -test-unit-verbose: ARGS=-v -test-unit-failfast: ARGS=-failfast -test-unit-race: ARGS=-race -$(TEST_UNIT_TARGETS): test-unit +test: test-unit ## Run test-unit test-clean: ## Clean testcache @echo "Cleaning test cache" @go clean -testcache -.PHONY: $(TEST_UNIT_TARGETS) test test-unit +.PHONY: test test-unit test-no-cache: test-clean test-unit ## Run test-unit without caching -test: test-unit ## Run test-unit test-unit: ## Run unit tests @echo "Running unit tests..." @set -o pipefail ; \ - $(GO) test $(GO_TEST_FLAGS) -timeout $(TIMEOUT_UNIT) $(ARGS) ./pkg/... | { grep -v 'no test files'; true; } + $(GO) test $(DEFAULT_GO_TEST_FLAGS) $(GO_TEST_FLAGS) -timeout $(TIMEOUT_UNIT) ./pkg/... | { grep -v 'no test files'; false; } .PHONY: test-e2e-cleanup test-e2e-cleanup: ## cleanup test e2e namespace/pr left open @@ -74,7 +70,7 @@ test-e2e-cleanup: ## cleanup test e2e namespace/pr left open .PHONY: test-e2e test-e2e: test-e2e-cleanup ## run e2e tests env GODEBUG=asynctimerchan=1 \ - go test -timeout $(TIMEOUT_E2E) -failfast -count=1 -tags=e2e -v $(GO_TEST_FLAGS) ./test + $(GO) test $(DEFAULT_GO_TEST_FLAGS) $(GO_TEST_FLAGS) -timeout $(TIMEOUT_E2E) -failfast -count=1 -tags=e2e ./test .PHONY: html-coverage html-coverage: ## generate html coverage @@ -119,6 +115,10 @@ lint-shell: ${SH_FILES} ## runs shellcheck on all python files @echo "Linting shell script files..." @shellcheck $(SH_FILES) +.PHONY: gitlint +gitlint: ## Run gitlint + @gitlint --commit "`git log --format=format:%H --no-merges -1`" --ignore "Merge branch" + .PHONY: pre-commit pre-commit: ## Run pre-commit hooks script manually @pre-commit run --all-files @@ -154,12 +154,12 @@ fix-golangci-lint: ## run golangci-lint and fix on all go files --fix @[[ -n `git status --porcelain` ]] && { echo "Go files has been cleaned 🧹. Cleaned Files: ";git status --porcelain ;} || echo "Go files are clean ✨" -.PHONY: fmt ## formats the GO code(excludes vendors dir) -fmt: +.PHONY: fmt +fmt: ## formats the GO code(excludes vendors dir) @go fmt `go list ./... | grep -v /vendor/` -.PHONY: fumpt ## formats the GO code with gofumpt(excludes vendors dir) -fumpt: +.PHONY: fumpt +fumpt: ## formats the GO code with gofumpt(excludes vendors dir) @find test pkg -name '*.go'|xargs -P4 $(GOFUMPT) -w -extra ##@ Local Development @@ -171,15 +171,6 @@ dev: ## deploys dev setup locally dev-redeploy: ## redeploy pac in local setup ./hack/dev/kind/install.sh -p -.PHONY: dev-docs -dev-docs: download-hugo ## preview live your docs with hugo - @$(HUGO_BIN) server -s docs/ & - if type -p xdg-open 2>/dev/null >/dev/null; then \ - xdg-open http://localhost:1313; \ - elif type -p open 2>/dev/null >/dev/null; then \ - open http://localhost:1313; \ - fi - ##@ Generated files check-generated: # check if all files that needs to be generated are generated @git status -uno |grep -E "modified:[ ]*(vendor/|.*.golden$)" && \ @@ -194,15 +185,23 @@ update-golden: ## run unit tests (updating golden files) .PHONY: generated generated: update-golden fumpt ## generate all files that needs to be generated +##@ Docs + .PHONY: download-hugo -download-hugo: +download-hugo: ## Download hugo software ./hack/download-hugo.sh $(HUGO_VERSION) $(TMPDIR)/hugo -.PHONY: gitlint -gitlint: ## Run gitlint - @gitlint --commit "`git log --format=format:%H --no-merges -1`" --ignore "Merge branch" +.PHONY: dev-docs +dev-docs: download-hugo ## preview live your docs with hugo + @$(HUGO_BIN) server -s docs/ & + if type -p xdg-open 2>/dev/null >/dev/null; then \ + xdg-open http://localhost:1313; \ + elif type -p open 2>/dev/null >/dev/null; then \ + open http://localhost:1313; \ + fi + +##@ Misc - .PHONY: clean clean: ## clean build artifacts rm -fR bin diff --git a/hack/gh-workflow-ci.sh b/hack/gh-workflow-ci.sh index 0051abccd..0e50aefea 100755 --- a/hack/gh-workflow-ci.sh +++ b/hack/gh-workflow-ci.sh @@ -37,8 +37,8 @@ create_second_github_app_controller_on_ghe() { local test_github_second_webhook_secret="${3}" if [[ -n "$(type -p apt)" ]]; then - apt update && - apt install -y python3-yaml + sudo apt update && + sudo apt install -y python3-yaml elif [[ -n "$(type -p dnf)" ]]; then dnf install -y python3-pyyaml else @@ -96,8 +96,6 @@ run_e2e_tests() { export TEST_GITHUB_PRIVATE_TASK_URL="https://github.com/openshift-pipelines/pipelines-as-code-e2e-tests-private/blob/main/remote_task.yaml" export TEST_GITHUB_PRIVATE_TASK_NAME="task-remote" - export GO_TEST_FLAGS="-v -race -failfast" - export TEST_BITBUCKET_CLOUD_API_URL=https://api.bitbucket.org/2.0 export TEST_BITBUCKET_CLOUD_E2E_REPOSITORY=cboudjna/pac-e2e-tests export TEST_BITBUCKET_CLOUD_TOKEN=${bitbucket_cloud_token} @@ -142,7 +140,7 @@ run_e2e_tests() { mapfile -t tests < <(get_tests "${target}") echo "About to run ${#tests[@]} tests: ${tests[*]}" # shellcheck disable=SC2001 - GO_TEST_FLAGS="-run \"$(echo "${tests[*]}" | sed 's/ /|/g')\"" make test-e2e + make test-e2e GO_TEST_FLAGS="-run \"$(echo "${tests[*]}" | sed 's/ /|/g')\"" } collect_logs() {