Skip to content

Commit

Permalink
Use buildtagger by default with "make lint"
Browse files Browse the repository at this point in the history
Signed-off-by: Alper Rifat Ulucinar <[email protected]>
  • Loading branch information
ulucinar committed Mar 8, 2024
1 parent 767ba19 commit b127593
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ GO_REQUIRED_VERSION ?= 1.21
# Uncomment below if you need to override the version.
GOLANGCILINT_VERSION ?= 1.55.2

# if running in a CI job, we will use build constraints and use the buildtagger
# to generate the build tags.
RUN_BUILDTAGGER ?= true
# if RUN_BUILDTAGGER is set to "true", we will use build constraints
# and use the buildtagger tool to generate the build tags.
ifeq ($(RUN_BUILDTAGGER),true)
GO_LINT_ARGS ?= -v --build-tags all
BUILDTAGGER_VERSION ?= v0.12.0-rc.0.28.gdc5d6f3
Expand Down Expand Up @@ -352,6 +353,7 @@ build-lint-cache: $(GOLANGCILINT)
@$(INFO) Running golangci-lint with the analysis cache building phase.
@(BUILDTAGGER_DOWNLOAD_URL=$(BUILDTAGGER_DOWNLOAD_URL) ./scripts/tag.sh && \
(([[ "${SKIP_LINTER_ANALYSIS}" == "true" ]] && $(OK) "Skipping analysis cache build phase because it's already been populated") && \
[[ "${SKIP_LINTER_ANALYSIS}" == "true" ]] || $(GOLANGCILINT) run -v --build-tags account,configregistry,configprovider,linter_run -v --concurrency 1 --disable-all --exclude '.*')) || $(FAIL)
[[ "${SKIP_LINTER_ANALYSIS}" == "true" ]] || $(GOLANGCILINT) run -v --build-tags account,configregistry,configprovider,linter_run -v --concurrency 1 --disable-all --exclude '.*') && \
EXTRA_BUILDTAGGER_ARGS="--delete" RESTORE_DEEPCOPY_TAGS="true" ./scripts/tag.sh) || $(FAIL)
@$(OK) Running golangci-lint with the analysis cache building phase.
endif
44 changes: 24 additions & 20 deletions scripts/tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,41 @@ set -aeuo pipefail

TAGGER="/tmp/buildtagger"
REPO_ROOT="."
EXTRA_BUILDTAGGER_ARGS="${EXTRA_BUILDTAGGER_ARGS:-}"
RESTORE_DEEPCOPY_TAGS="${RESTORE_DEEPCOPY_TAGS:-false}"

curl -fsSL "${BUILDTAGGER_DOWNLOAD_URL}" -o "${TAGGER}"
chmod +x "${TAGGER}"
if [[ ! -f "${TAGGER}" ]]; then
curl -fsSL "${BUILDTAGGER_DOWNLOAD_URL}" -o "${TAGGER}"
chmod +x "${TAGGER}"
fi

"${TAGGER}" --parent-dir "${REPO_ROOT}"/apis --regex "(.+)/.+/.+\.go" --tag-format "(%s || all) && !ignore_autogenerated" --mode dir
"${TAGGER}" --parent-dir "${REPO_ROOT}"/apis --regex "(.+)/.+/zz_groupversion_info\.go" --tag-format "(%s || all) && !ignore_autogenerated" --mode dir
"${TAGGER}" --parent-dir "${REPO_ROOT}"/internal/controller --regex "(.+)/.+/zz_controller\.go" --tag-format "(%s || all) && !ignore_autogenerated" --mode dir
"${TAGGER}" --parent-dir "${REPO_ROOT}"/internal/controller --regex "zz_(.+)_setup\.go" --tag-format "(%s || all) && !ignore_autogenerated" --mode file
"${TAGGER}" --parent-dir "${REPO_ROOT}"/cmd/provider --regex "(.+)/zz_main\.go" --tag-format "(%s || all) && !ignore_autogenerated" --mode dir
"${TAGGER}" --parent-dir "${REPO_ROOT}"/config --regex "(.+)/config\.go" --tag-format "(%s || all) && !ignore_autogenerated" --mode dir
"${TAGGER}" --parent-dir "${REPO_ROOT}"/apis --regex "(.+)/.+/.+\.go" --tag-format "(%s || all) && !ignore_autogenerated" --mode dir ${EXTRA_BUILDTAGGER_ARGS}
"${TAGGER}" --parent-dir "${REPO_ROOT}"/apis --regex "(.+)/.+/zz_groupversion_info\.go" --tag-format "(%s || all) && !ignore_autogenerated" --mode dir ${EXTRA_BUILDTAGGER_ARGS}
"${TAGGER}" --parent-dir "${REPO_ROOT}"/internal/controller --regex "(.+)/.+/zz_controller\.go" --tag-format "(%s || all) && !ignore_autogenerated" --mode dir ${EXTRA_BUILDTAGGER_ARGS}
"${TAGGER}" --parent-dir "${REPO_ROOT}"/internal/controller --regex "zz_(.+)_setup\.go" --tag-format "(%s || all) && !ignore_autogenerated" --mode file ${EXTRA_BUILDTAGGER_ARGS}
"${TAGGER}" --parent-dir "${REPO_ROOT}"/cmd/provider --regex "(.+)/zz_main\.go" --tag-format "(%s || all) && !ignore_autogenerated" --mode dir ${EXTRA_BUILDTAGGER_ARGS}
"${TAGGER}" --parent-dir "${REPO_ROOT}"/config --regex "(.+)/config\.go" --tag-format "(%s || all) && !ignore_autogenerated" --mode dir ${EXTRA_BUILDTAGGER_ARGS}

# constant tags
# apis/zz_register.go -> (apiregister || register || all) && !ignore_autogenerated
"${TAGGER}" --parent-dir "${REPO_ROOT}"/apis/zz_register.go --tag-format "all && !ignore_autogenerated" --mode file
"${TAGGER}" --parent-dir "${REPO_ROOT}"/apis/zz_register.go --tag-format "all && !ignore_autogenerated" --mode file ${EXTRA_BUILDTAGGER_ARGS}
# cmd/generator/main.go -> config || generate || all
"${TAGGER}" --parent-dir "${REPO_ROOT}"/cmd/generator/main.go --tag-format "all" --mode file
"${TAGGER}" --parent-dir "${REPO_ROOT}"/cmd/generator/main.go --tag-format "all" --mode file ${EXTRA_BUILDTAGGER_ARGS}
# config/autoscaling/config_test.go -> (autoscaling || config || all) && !ignore_autogenerated
"${TAGGER}" --parent-dir "${REPO_ROOT}"/config/autoscaling/config_test.go --tag-format "(autoscaling || all) && !ignore_autogenerated" --mode file
"${TAGGER}" --parent-dir "${REPO_ROOT}"/config/autoscaling/config_test.go --tag-format "(autoscaling || all) && !ignore_autogenerated" --mode file ${EXTRA_BUILDTAGGER_ARGS}
# config/common/apis/lambda/extractor.go -> config || lambda || all
"${TAGGER}" --parent-dir "${REPO_ROOT}"/config/common/apis/lambda/extractor.go --tag-format "lambda || all" --mode file
"${TAGGER}" --parent-dir "${REPO_ROOT}"/config/common/apis/lambda/extractor.go --tag-format "lambda || all" --mode file ${EXTRA_BUILDTAGGER_ARGS}
# config/config_registry.go -> configregistry || register || config || all
"${TAGGER}" --parent-dir "${REPO_ROOT}"/config/registry.go --tag-format "configregistry || all" --mode file
"${TAGGER}" --parent-dir "${REPO_ROOT}"/config/registry.go --tag-format "configregistry || all" --mode file ${EXTRA_BUILDTAGGER_ARGS}
# config/provider.go -> configprovider || register || config || all
"${TAGGER}" --parent-dir "${REPO_ROOT}"/config/provider.go --tag-format "(configprovider || all) && !linter_run" --mode file
"${TAGGER}" --parent-dir "${REPO_ROOT}"/config/provider.go --tag-format "(configprovider || all) && !linter_run" --mode file ${EXTRA_BUILDTAGGER_ARGS}
# config/overrides.go -> configprovider || register || config || all
"${TAGGER}" --parent-dir "${REPO_ROOT}"/config/overrides.go --tag-format "configprovider || all" --mode file
"${TAGGER}" --parent-dir "${REPO_ROOT}"/config/overrides.go --tag-format "configprovider || all" --mode file ${EXTRA_BUILDTAGGER_ARGS}
# internal/controller/eks/clusterauth/controller.go -> eks || all
"${TAGGER}" --parent-dir "${REPO_ROOT}"/internal/controller/eks/clusterauth/controller.go --tag-format "eks || all" --mode file
"${TAGGER}" --parent-dir "${REPO_ROOT}"/internal/controller/eks/clusterauth/controller.go --tag-format "eks || all" --mode file ${EXTRA_BUILDTAGGER_ARGS}
# internal/controller/eks/clusterauth/eks.go -> eks || all
"${TAGGER}" --parent-dir "${REPO_ROOT}"/internal/controller/eks/clusterauth/eks.go --tag-format "eks || all" --mode file
"${TAGGER}" --parent-dir "${REPO_ROOT}"/internal/controller/eks/clusterauth/eks.go --tag-format "eks || all" --mode file ${EXTRA_BUILDTAGGER_ARGS}

# linter only files
# ./.../linter_run.go -> linter_run
"${TAGGER}" --parent-dir "${REPO_ROOT}" --regex "linter_run.go" --tag-format "linter_run" --mode file
if [[ "${RESTORE_DEEPCOPY_TAGS}" == "true" ]]; then
"${TAGGER}" --parent-dir "${REPO_ROOT}"/apis --regex "zz_generated.deepcopy.go" --tag-format "!ignore_autogenerated" --mode file
fi

0 comments on commit b127593

Please sign in to comment.