Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch go mod download overwriting changes to vendor #3008

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ DOCKER_USE_ID_FOR_LINUX=$(shell if [ "$$(uname -s)" = "Linux" ] && [ -n "$${USER
GO_MOD_CACHE=$(shell source $(BUILD_LIB)/common.sh && build::common::use_go_version $(GOLANG_VERSION) > /dev/null 2>&1 && go env GOMODCACHE)
GO_BUILD_CACHE=$(shell source $(BUILD_LIB)/common.sh && build::common::use_go_version $(GOLANG_VERSION) > /dev/null 2>&1 && go env GOCACHE)
CGO_TARGET?=
GO_MODS_VENDORED?=false
######################

#### BUILD FLAGS ####
Expand Down Expand Up @@ -520,7 +521,7 @@ $(GIT_PATCH_TARGET): $(GIT_CHECKOUT_TARGET)
$(REPO)/%ks-distro-go-mod-download: REPO_SUBPATH=$(if $(filter e,$*),,$(*:%/e=%))
$(REPO)/%ks-distro-go-mod-download: $(if $(PATCHES_DIR),$(GIT_PATCH_TARGET),$(GIT_CHECKOUT_TARGET))
@echo -e $(call TARGET_START_LOG)
$(BASE_DIRECTORY)/build/lib/go_mod_download.sh $(MAKE_ROOT) $(REPO) $(GIT_TAG) $(GOLANG_VERSION) "$(REPO_SUBPATH)"
if [[ "$(GO_MODS_VENDORED)" == "false" ]]; then $(BASE_DIRECTORY)/build/lib/go_mod_download.sh $(MAKE_ROOT) $(REPO) $(GIT_TAG) $(GOLANG_VERSION) "$(REPO_SUBPATH)"; fi
@touch $@
@echo -e $(call TARGET_END_LOG)

Expand Down
18 changes: 17 additions & 1 deletion build/lib/go_mod_download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail
Expand All @@ -31,4 +30,21 @@ cd $REPO/$REPO_SUBPATH
CACHE_KEY=$(echo $PROJECT_ROOT | sed 's/\(.*\)\//\1-/' | xargs basename)
build::common::use_go_version $GOLANG_VERSION
build::common::set_go_cache $CACHE_KEY $TAG

# if there is a existing vendor directory running go mod vendor is not
# neccessairly a problem since vendor directories generally match upstream dependencies
# in some cases tho upstream has patched specific dependenies or more likely
# we are carrying a patch which does
# in these cases this go mod vendor will overwrite those patches
PRE_EXISTING_VENDOR=""
if [ -d vendor ]; then
PRE_EXISTING_VENDOR="true"
fi

build::common::echo_and_run go mod vendor

if [ "${PRE_EXISTING_VENDOR}" = "true" ] && [ "$(git status --porcelain -- vendor | wc -l)" -gt 0 ]; then
echo "ERROR: 'go mod vendor' is updating the pre-existing vendor directory! This is likely not what you want since it could be overwriting patches"
echo "To skip downloading vendor dependencies for this project, set GO_MODS_VENDORED=true in the Makefile"
exit 1
fi
Loading