Skip to content

Commit

Permalink
fix(makefile): update test flags and add comments
Browse files Browse the repository at this point in the history
- Introduced DEFAULT_GO_TEST_FLAGS for default test flags
- Added comments for vendor and other targets
- Removed redundant test-unit targets
- Updated test-e2e to use DEFAULT_GO_TEST_FLAGS
- Added gitlint target for commit message linting
- Minor formatting and cleanup
  • Loading branch information
chmouel committed Dec 19, 2024
1 parent 8110393 commit 6924457
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
57 changes: 28 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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$)" && \
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions hack/gh-workflow-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 6924457

Please sign in to comment.