From de32b9a79aa5c3a354d7f5a2d7cd44cf114bbbb8 Mon Sep 17 00:00:00 2001 From: Jean du Plessis Date: Mon, 4 Nov 2024 10:11:45 +0200 Subject: [PATCH] Stop using deprecated upbound/official-provider-ci workflows Signed-off-by: Jean du Plessis --- Makefile | 29 +++++++++++++++++++++++++++++ scripts/tag.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100755 scripts/tag.sh diff --git a/Makefile b/Makefile index d86d2452f..d154f55d5 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,15 @@ GO_REQUIRED_VERSION ?= 1.21 # Uncomment below if you need to override the version. # GOLANGCILINT_VERSION ?= 1.54.0 +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 +BUILDTAGGER_DOWNLOAD_URL ?= https://s3.us-west-2.amazonaws.com/upbound.official-providers-ci.releases/main/$(BUILDTAGGER_VERSION)/bin/$(SAFEHOST_PLATFORM)/buildtagger +endif + # SUBPACKAGES ?= $(shell find cmd/provider -type d -maxdepth 1 -mindepth 1 | cut -d/ -f3) SUBPACKAGES ?= monolith GO_STATIC_PACKAGES ?= $(GO_PROJECT)/cmd/generator ${SUBPACKAGES:%=$(GO_PROJECT)/cmd/provider/%} @@ -397,6 +406,26 @@ kustomize-crds: output.init $(KUSTOMIZE) $(YQ) .PHONY: kustomize-crds +ifeq ($(RUN_BUILDTAGGER),true) +lint.init: build-lint-cache +lint.done: delete-build-tags + +build-lint-cache: $(GOLANGCILINT) + @$(INFO) Running golangci-lint with the analysis cache building phase. + @# we run the initial analysis cache build phase using the relatively + @# smaller API group "account", to keep the memory requirements at a + @# minimum. + @(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 --disable-all --exclude '.*')) || $(FAIL) + @$(OK) Running golangci-lint with the analysis cache building phase. + +delete-build-tags: + @$(INFO) Untagging source files. + @EXTRA_BUILDTAGGER_ARGS="--delete" RESTORE_DEEPCOPY_TAGS="true" ./scripts/tag.sh || $(FAIL) + @$(OK) Untagging source files. +endif + # TODO(negz): Update CI to use these targets. vendor: modules.download vendor.check: modules.check diff --git a/scripts/tag.sh b/scripts/tag.sh new file mode 100755 index 000000000..d64e991fc --- /dev/null +++ b/scripts/tag.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +set -aeuo pipefail + +# SPDX-FileCopyrightText: 2024 The Crossplane Authors +# +# SPDX-License-Identifier: CC0-1.0 + +TAGGER="/tmp/buildtagger" +REPO_ROOT="." +EXTRA_BUILDTAGGER_ARGS="${EXTRA_BUILDTAGGER_ARGS:-}" +RESTORE_DEEPCOPY_TAGS="${RESTORE_DEEPCOPY_TAGS:-false}" + +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 ${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 ${EXTRA_BUILDTAGGER_ARGS} +# cmd/generator/main.go -> config || generate || all +"${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 ${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 ${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 ${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 ${EXTRA_BUILDTAGGER_ARGS} +# config/overrides.go -> configprovider || register || config || all +"${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 ${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 ${EXTRA_BUILDTAGGER_ARGS} + +if [[ "${RESTORE_DEEPCOPY_TAGS}" == "true" ]]; then + "${TAGGER}" --parent-dir "${REPO_ROOT}"/apis --regex "zz_generated.deepcopy.go" --tag-format "!ignore_autogenerated" --mode file +fi \ No newline at end of file