From 7df05d90df6e9082cddadcd1056b5c762f3e419f Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Thu, 16 May 2024 02:09:10 -0400 Subject: [PATCH] Avoid git warnings on shallow checkout (#5455) ## Which problem is this PR solving? Many of GH workflows are logging warnings like this: ``` Run make install-test-tools fatal: No names found, cannot describe anything. fatal: No names found, cannot describe anything. fatal: No names found, cannot describe anything. fatal: No names found, cannot describe anything. fatal: No names found, cannot describe anything. ``` This is because we typically do a shallow checkout of the repo without tags. ## Description of the changes - Check for shallow checkout and don't run `git describe` ## How was this change tested? - CI `lint`: no warnings logged when calling `make` ``` $ make echo-version GIT_CLOSEST_TAG=0.0.0 ``` Signed-off-by: Yuri Shkuro --- .github/workflows/ci-lint-checks.yaml | 9 ++++++--- Makefile | 14 +++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci-lint-checks.yaml b/.github/workflows/ci-lint-checks.yaml index 616495c67b0..c6efb1411cc 100644 --- a/.github/workflows/ci-lint-checks.yaml +++ b/.github/workflows/ci-lint-checks.yaml @@ -14,7 +14,7 @@ concurrency: # See https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions permissions: # added using https://github.com/step-security/secure-workflows contents: read - + jobs: lint: runs-on: ubuntu-latest @@ -30,11 +30,14 @@ jobs: with: go-version: 1.22.x + - name: Print Jaeger version + run: make echo-version + - name: Install tools run: make install-test-tools - name: Lint run: make lint - + - name: Ensure PR is not on main branch - uses: ./.github/actions/block-pr-not-on-main \ No newline at end of file + uses: ./.github/actions/block-pr-not-on-main diff --git a/Makefile b/Makefile index 2cbf176a7ad..7055dad4630 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,9 @@ IMPORT_LOG=.import.log COLORIZE ?= | $(SED) 's/PASS/✅ PASS/g' | $(SED) 's/FAIL/❌ FAIL/g' | $(SED) 's/SKIP/🔕 SKIP/g' GIT_SHA=$(shell git rev-parse HEAD) -GIT_CLOSEST_TAG=$(shell git describe --abbrev=0 --tags) +GIT_SHALLOW_CLONE := $(shell git rev-parse --is-shallow-repository) +# Some of GitHub Actions workflows do a shallow checkout without tags. This avoids logging warnings from git. +GIT_CLOSEST_TAG=$(shell if [ "$(GIT_SHALLOW_CLONE)" = "false" ]; then git describe --abbrev=0 --tags; else echo 0.0.0; fi) ifneq ($(GIT_CLOSEST_TAG),$(shell echo ${GIT_CLOSEST_TAG} | grep -E "$(semver_regex)")) $(warning GIT_CLOSEST_TAG=$(GIT_CLOSEST_TAG) is not in the semver format $(semver_regex)) endif @@ -91,9 +93,15 @@ include Makefile.Crossdock.mk .PHONY: test-and-lint test-and-lint: test fmt lint +.PHONY: echo-version +echo-version: + @echo "GIT_CLOSEST_TAG=$(GIT_CLOSEST_TAG)" + +.PHONY: echo-all-pkgs echo-all-pkgs: @echo $(ALL_PKGS) | tr ' ' '\n' | sort +.PHONY: echo-all-srcs echo-all-srcs: @echo $(ALL_SRC) | tr ' ' '\n' | sort @@ -474,10 +482,6 @@ generate-mocks: install-tools $(MOCKERY) --all --dir ./storage/spanstore/ --output ./storage/spanstore/mocks $(MOCKERY) --all --dir ./proto-gen/storage_v1/ --output ./proto-gen/storage_v1/mocks -.PHONY: echo-version -echo-version: - @echo $(GIT_CLOSEST_TAG) - .PHONY: certs certs: cd pkg/config/tlscfg/testdata && ./gen-certs.sh