Fixed setting of the `ToolkitVersion` variable for our Go tools. (#8783)

This commit is contained in:
Pawel Winogrodzki 2024-04-12 14:24:08 -07:00 коммит произвёл GitHub
Родитель 4af64de901
Коммит 21b0a7fd8c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 18 добавлений и 6 удалений

Просмотреть файл

@ -91,6 +91,9 @@ clean-go-tools:
rm -rf $(TOOL_BINS_DIR)
rm -rf $(BUILD_DIR)/tools
go_ldflags := -X github.com/microsoft/azurelinux/toolkit/tools/internal/exe.ToolkitVersion=$(RELEASE_VERSION) \
-X github.com/microsoft/azurelinux/toolkit/tools/pkg/imagecustomizerlib.ToolVersion=$(IMAGE_CUSTOMIZER_FULL_VERSION)
# Matching rules for the above targets
# Tool specific pre-requisites are tracked via $(go-util): $(shell find...) dynamic variable defined above
ifneq ($(REBUILD_TOOLS),y)
@ -108,18 +111,16 @@ else
# Rebuild the go tools as needed
$(TOOL_BINS_DIR)/%: $(go_common_files)
cd $(TOOLS_DIR)/$* && \
go test -test.short -covermode=atomic -coverprofile=$(BUILD_DIR)/tools/$*.test_coverage ./... && \
TOOLKIT_VER="-X github.com/microsoft/CBL-Mariner/toolkit/tools/internal/exe.ToolkitVersion=$(RELEASE_VERSION)" && \
IMGCUST_VER="-X github.com/microsoft/CBL-Mariner/toolkit/tools/pkg/imagecustomizerlib.ToolVersion=$(IMAGE_CUSTOMIZER_FULL_VERSION)" && \
go test -ldflags="$(go_ldflags)" -test.short -covermode=atomic -coverprofile=$(BUILD_DIR)/tools/$*.test_coverage ./... && \
CGO_ENABLED=0 go build \
-ldflags="$$TOOLKIT_VER $$IMGCUST_VER" \
-ldflags="$(go_ldflags)" \
-o $(TOOL_BINS_DIR)
endif
# Runs tests for common components
$(BUILD_DIR)/tools/internal.test_coverage: $(go_internal_files) $(go_imagegen_files) $(STATUS_FLAGS_DIR)/got_go_deps.flag
cd $(TOOLS_DIR)/$* && \
go test -test.short -covermode=atomic -coverprofile=$@ ./...
go test -ldflags="$(go_ldflags)" -test.short -covermode=atomic -coverprofile=$@ ./...
# Downloads all the go dependencies without using sudo, so we don't break other go use cases for the user.
# We can check if $SUDO_USER is set (the user who invoked sudo), and if so, use that user to run go get via sudo -u.
@ -153,7 +154,7 @@ go-fmt-all:
# Formats the test coverage for the tools
.PHONY: $(BUILD_DIR)/tools/all_tools.coverage
$(BUILD_DIR)/tools/all_tools.coverage: $(call shell_real_build_only, find $(TOOLS_DIR)/ -type f -name '*.go') $(STATUS_FLAGS_DIR)/got_go_deps.flag
cd $(TOOLS_DIR) && go test -coverpkg=./... -test.short -covermode=atomic -coverprofile=$@ ./...
cd $(TOOLS_DIR) && go test -ldflags="$(go_ldflags)" -coverpkg=./... -test.short -covermode=atomic -coverprofile=$@ ./...
$(test_coverage_report): $(BUILD_DIR)/tools/all_tools.coverage
cd $(TOOLS_DIR) && go tool cover -html=$(BUILD_DIR)/tools/all_tools.coverage -o $@
##help:target:go-test-coverage=Run and publish test coverage for all go tools.

Просмотреть файл

@ -0,0 +1,11 @@
package exe
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestToolkitVersionIsNotEmpty(t *testing.T) {
assert.NotEmpty(t, ToolkitVersion)
}