Skip to content

Commit 9a592f1

Browse files
committed
Add GitHub token authentication to Makefile downloads
Fixes GitHub rate limiting issues in CI by automatically using GITHUB_TOKEN when available for downloads from GitHub (raw.githubusercontent.com and github.com/releases). Falls back gracefully to unauthenticated downloads when no token is present, maintaining compatibility with local development. Updated targets: - kustomize (install script) - yq (binary release) - kuttl (binary release) - operator-sdk (binary release) - opm (binary release) - golangci-lint (install script) Usage in CI: export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} Local dev: no changes required Jira: OSPRH-17779 Signed-off-by: Martin Schuppert <mschuppert@redhat.com>
1 parent aaf6236 commit 9a592f1

1 file changed

Lines changed: 44 additions & 8 deletions

File tree

Makefile

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,14 @@ tidy: ## Run go mod tidy on every mod file in the repo
187187

188188
.PHONY: golangci-lint
189189
golangci-lint:
190-
test -s $(LOCALBIN)/golangci-lint || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.59.1
190+
test -s $(LOCALBIN)/golangci-lint || { \
191+
if [ -n "$$GITHUB_TOKEN" ]; then \
192+
echo "Using GitHub token for golangci-lint download"; \
193+
curl -sSfL -H "Authorization: token $$GITHUB_TOKEN" https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.59.1; \
194+
else \
195+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.59.1; \
196+
fi; \
197+
}
191198
$(LOCALBIN)/golangci-lint run --fix
192199

193200
MAX_PROCS := 5
@@ -322,7 +329,15 @@ $(KUSTOMIZE): $(LOCALBIN)
322329
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
323330
rm -rf $(LOCALBIN)/kustomize; \
324331
fi
325-
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
332+
test -s $(LOCALBIN)/kustomize || { \
333+
if [ -n "$$GITHUB_TOKEN" ]; then \
334+
echo "Using GitHub token for authenticated download"; \
335+
curl -Ss -H "Authorization: token $$GITHUB_TOKEN" $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); \
336+
else \
337+
echo "No GitHub token found, using unauthenticated download"; \
338+
curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); \
339+
fi; \
340+
}
326341

327342
.PHONY: controller-gen
328343
controller-gen: gowork $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
@@ -352,7 +367,14 @@ kuttl-test: ## Run kuttl tests
352367
.PHONY: kuttl
353368
kuttl: $(KUTTL) ## Download kubectl-kuttl locally if necessary.
354369
$(KUTTL): $(LOCALBIN)
355-
test -s $(LOCALBIN)/kubectl-kuttl || curl -L -o $(LOCALBIN)/kubectl-kuttl https://github.com/kudobuilder/kuttl/releases/download/v$(KUTTL_VERSION)/kubectl-kuttl_$(KUTTL_VERSION)_linux_x86_64
370+
test -s $(LOCALBIN)/kubectl-kuttl || { \
371+
if [ -n "$$GITHUB_TOKEN" ]; then \
372+
echo "Using GitHub token for kuttl download"; \
373+
curl -Ss -L -H "Authorization: token $$GITHUB_TOKEN" -o $(LOCALBIN)/kubectl-kuttl https://github.com/kudobuilder/kuttl/releases/download/v$(KUTTL_VERSION)/kubectl-kuttl_$(KUTTL_VERSION)_linux_x86_64; \
374+
else \
375+
curl -L -o $(LOCALBIN)/kubectl-kuttl https://github.com/kudobuilder/kuttl/releases/download/v$(KUTTL_VERSION)/kubectl-kuttl_$(KUTTL_VERSION)_linux_x86_64; \
376+
fi; \
377+
}
356378
chmod +x $(LOCALBIN)/kubectl-kuttl
357379

358380
.PHONY: operator-sdk
@@ -364,7 +386,12 @@ ifeq (, $(shell which operator-sdk 2>/dev/null))
364386
set -e ;\
365387
mkdir -p $(dir $(OPERATOR_SDK)) ;\
366388
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
367-
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
389+
if [ -n "$$GITHUB_TOKEN" ]; then \
390+
echo "Using GitHub token for operator-sdk download"; \
391+
curl -sSL -H "Authorization: token $$GITHUB_TOKEN" -o $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH}; \
392+
else \
393+
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH}; \
394+
fi ;\
368395
chmod +x $(OPERATOR_SDK) ;\
369396
}
370397
else
@@ -398,7 +425,12 @@ ifeq (,$(shell which opm 2>/dev/null))
398425
set -e ;\
399426
mkdir -p $(dir $(OPM)) ;\
400427
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
401-
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.29.0/$${OS}-$${ARCH}-opm ;\
428+
if [ -n "$$GITHUB_TOKEN" ]; then \
429+
echo "Using GitHub token for opm download"; \
430+
curl -sSL -H "Authorization: token $$GITHUB_TOKEN" -o $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.29.0/$${OS}-$${ARCH}-opm; \
431+
else \
432+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.29.0/$${OS}-$${ARCH}-opm; \
433+
fi ;\
402434
chmod +x $(OPM) ;\
403435
}
404436
else
@@ -408,9 +440,13 @@ endif
408440

409441
.PHONY: yq
410442
yq: $(LOCALBIN) ## Download and install yq in local env
411-
test -s $(LOCALBIN)/yq || ( cd $(LOCALBIN) &&\
412-
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64.tar.gz -O - |\
413-
tar xz && mv yq_linux_amd64 $(LOCALBIN)/yq )
443+
test -s $(LOCALBIN)/yq || ( cd $(LOCALBIN) && \
444+
if [ -n "$$GITHUB_TOKEN" ]; then \
445+
echo "Using GitHub token for yq download"; \
446+
curl -Ss -L -H "Authorization: token $$GITHUB_TOKEN" https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64.tar.gz | tar xz && mv yq_linux_amd64 $(LOCALBIN)/yq; \
447+
else \
448+
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64.tar.gz -O - | tar xz && mv yq_linux_amd64 $(LOCALBIN)/yq; \
449+
fi )
414450

415451
.PHONY: oc
416452
oc: $(LOCALBIN) ## Download and install oc in local env

0 commit comments

Comments
 (0)