Skip to content

Commit

Permalink
cah
Browse files Browse the repository at this point in the history
  • Loading branch information
chandrareddyp committed Feb 12, 2024
1 parent 91f2182 commit 2f7d3e1
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 40 deletions.
64 changes: 49 additions & 15 deletions .github/workflows/cli_core_e2e_windows_test_msys2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,35 @@ jobs:
restore-keys: |
${{ runner.os }}-go-${{ steps.go.outputs.go-version }}-
- name: Set and Echo GOPATH and GOBIN
run: |
$GOPATH = go env GOPATH
$GOBIN = "$GOPATH\bin"
echo "GOPATH 1 is set to $GOPATH"
echo "GOBIN 1 is set to $GOBIN"
echo "GOPATH=$GOPATH" | Out-File -Append -FilePath $env:GITHUB_ENV
echo "GOBIN=$GOBIN" | Out-File -Append -FilePath $env:GITHUB_ENV
echo "GOPATH 2 is set to $GOPATH"
echo "GOBIN 2 is set to $GOBIN"
shell: pwsh

- name: Echo Go installation path
run: |
echo "Go installation path: $(go env GOROOT)"
ls "$(go env GOROOT)"
ls "$(go env GOROOT)\bin"
shell: bash

- name: Echo GOPATH and GOBIN
run: |
echo "GOPATH=$env:GOPATH"
echo "GOBIN=$env:GOBIN"
echo "Contents of GOPATH:"
Get-ChildItem -Path $env:GOPATH
echo "Contents of GOBIN:"
Get-ChildItem -Path $env:GOBIN
shell: pwsh

- name: Install MSYS2
run: choco install msys2
shell: powershell
Expand All @@ -49,30 +78,35 @@ jobs:
run: C:\tools\msys64\usr\bin\bash -lc "echo 'Hello from MSYS2'"
shell: powershell

- name: Install Make in MSYS2
- name: Install Make and Unzip in MSYS2
run: |
C:\tools\msys64\usr\bin\bash -lc "pacman -S make --noconfirm"
C:\tools\msys64\usr\bin\bash -lc "pacman -S unzip --noconfirm"
C:\tools\msys64\usr\bin\bash -lc "pacman -S make unzip --noconfirm"
C:\tools\msys64\usr\bin\bash -lc "pacman -S make wget --noconfirm"
C:\tools\msys64\usr\bin\bash -lc "pacman -S make bzip2 --noconfirm"
C:\tools\msys64\usr\bin\bash -lc "wget --version"
C:\tools\msys64\usr\bin\bash -lc "bzip2 --version"
shell: powershell

- name: Run Unix Commands in MSYS2
run: |
C:\tools\msys64\usr\bin\bash -lc "echo 'Hello from MSYS2'"
C:\tools\msys64\usr\bin\bash -lc "ls"
C:\tools\msys64\usr\bin\bash -lc "pwd"
C:\tools\msys64\usr\bin\bash -lc "go version"
C:\tools\msys64\usr\bin\bash -lc "wget --version"
C:\tools\msys64\usr\bin\bash -lc "bzip2 --version"
$WGET = $(Get-Command wget).Source
$BZIP2 = $(Get-Command bzip2).Source
echo "WGET_PATH=$WGET" >> $env:GITHUB_ENV
echo "BZIP2_PATH=$BZIP2" >> $env:GITHUB_ENV
echo "WGET_PATH: $WGET"
echo "BZIP2_PATH: $BZIP2"
$msysBin = "C:\tools\msys64\usr\bin"
echo "MSYS_BIN=$msysBin" >> $env:GITHUB_ENV
shell: powershell

- name: Setup dependencies
- name: E2E Tests
run: |
topLevel=$(git rev-parse --show-toplevel)
echo "Top level: $topLevel"
# Set up PATH to include Go binaries
export PATH=$PATH:/c/go/bin:$(go env GOPATH)/bin
C:/tools/msys64/usr/bin/bash -lc "cd '$topLevel' && make tools"
C:\tools\msys64\usr\bin\bash -lc "wget --version"
C:\tools\msys64\usr\bin\bash -lc "bzip2 --version"
make e2e-cli-core
shell: powershell
env:
MSYS2_PATH_TYPE: inherit # This might help inheriting the PATH correctly

43 changes: 39 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,34 @@ GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOHOSTOS ?= $(shell go env GOHOSTOS)
GOHOSTARCH ?= $(shell go env GOHOSTARCH)
HOST_OS=$(shell go env GOOS)

WGET := $(shell which wget)
BZIP2 := $(shell which bzip2)
TAR := $(shell which tar)

# Load environment variables from GitHub workflow
ifeq ($(GITHUB_ACTIONS),true)
ifeq ($(GOOS),windows)
# Use the values from GitHub Actions
MSYS_BIN ?= $(shell echo $MSYS_BIN)
WGET = $(MSYS_BIN)/wget
BZIP2 = $(MSYS_BIN)/bzip2
TAR = $(MSYS_BIN)/tar
GITHUB_INFO := Running in GitHub Actions on Windows
endif
endif

# Ensure $(GOPATH) uses forward slashes
WGET := $(subst \,/,$(WGET))
BZIP2 := $(subst \,/,$(BZIP2))
TAR := $(subst \,/,$(TAR))

$(info WGET after update: $(WGET))
$(info BZIP2 after update: $(BZIP2))
$(info TAR after update: $(TAR))
$(info $(GITHUB_INFO))


# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -49,7 +77,10 @@ COSIGN := $(TOOLS_BIN_DIR)/cosign
GOJUNITREPORT := $(TOOLS_BIN_DIR)/go-junit-report

#TOOLING_BINARIES := $(GOIMPORTS) $(GOLANGCI_LINT) $(VALE) $(MISSPELL) $(CONTROLLER_GEN) $(IMGPKG) $(KUBECTL) $(KIND) $(GINKGO) $(COSIGN) $(GOJUNITREPORT)
TOOLING_BINARIES := $(GOLANGCI_LINT)
TOOLING_BINARIES := $(GOIMPORTS) $(GOLANGCI_LINT) $(VALE) $(MISSPELL) $(CONTROLLER_GEN) $(IMGPKG) $(KUBECTL) $(KIND) $(GINKGO) $(COSIGN) $(GOJUNITREPORT)
#TOOLING_BINARIES := $(GOIMPORTS)

#TOOLING_BINARIES := $(GOLANGCI_LINT)

# Build and version information

Expand Down Expand Up @@ -244,9 +275,13 @@ e2e-cli-core: tools start-test-central-repo start-airgapped-local-registry e2e-c

.PHONY: setup-custom-cert-for-test-central-repo
setup-custom-cert-for-test-central-repo: ## Setup up the custom ca cert for test-central-repo in the config file
@echo "ROOT_DIR inside setup-custom-cert-for-test-central-repo: $(ROOT_DIR)"
@echo "WGET inside setup-custom-cert-for-test-central-repo: $(WGET)"
@echo "BZIP2 inside setup-custom-cert-for-test-central-repo: $(BZIP2)"
@if [ ! -d $(ROOT_DIR)/hack/central-repo/certs ]; then \
wget https://storage.googleapis.com/tanzu-cli/data/testcerts/local-central-repo-testcontent.bz2 -O $(ROOT_DIR)/hack/central-repo/local-central-repo-testcontent.bz2;\
tar xjf $(ROOT_DIR)/hack/central-repo/local-central-repo-testcontent.bz2 -C $(ROOT_DIR)/hack/central-repo/;\
$(WGET) https://storage.googleapis.com/tanzu-cli/data/testcerts/local-central-repo-testcontent.bz2 -O $(ROOT_DIR)/hack/central-repo/local-central-repo-testcontent.bz2;\
TAR_BZ2_FILE:=$(shell cygpath -w $(ROOT_DIR)/hack/central-repo/local-central-repo-testcontent.bz2)
$(TAR) xjf ${TAR_BZ2_FILE} -C $(ROOT_DIR)/hack/central-repo/;\
fi
echo "Adding docker test central repo cert to the config file"
TANZU_CLI_CEIP_OPT_IN_PROMPT_ANSWER="No" TANZU_CLI_EULA_PROMPT_ANSWER="Yes" $(ROOT_DIR)/bin/tanzu config cert delete localhost:9876 || true
Expand All @@ -255,7 +290,7 @@ setup-custom-cert-for-test-central-repo: ## Setup up the custom ca cert for test
.PHONY: start-test-central-repo
start-test-central-repo: stop-test-central-repo setup-custom-cert-for-test-central-repo ## Starts up a test central repository locally with docker
@if [ ! -d $(ROOT_DIR)/hack/central-repo/registry-content ]; then \
(cd $(ROOT_DIR)/hack/central-repo && tar xjf registry-content.bz2 || true;) \
(cd $(ROOT_DIR)/hack/central-repo && $(TAR) xjf registry-content.bz2 || true;) \
fi
@docker run --rm -d -p 9876:443 --name central \
-v $(ROOT_DIR)/hack/central-repo/certs:/certs \
Expand Down
74 changes: 53 additions & 21 deletions hack/tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,51 @@ VAL_URL := https://github.com/errata-ai/vale/releases/download/v$(VALE_VERSION)/
sed 's,darwin,macOS,g'| sed 's,linux,Linux,g'| sed 's,windows,Windows,g')_$(shell echo $(HOST_ARCH) | sed 's,amd64,64-bit,g')$(shell echo $(HOST_OS) | \
sed 's,darwin,.tar.gz,g'| sed 's,linux,.tar.gz,g'| sed 's,windows,.zip,g')

ifeq ($(CI),true)
GOBIN := $(subst /,\,$(ROOT_DIR)/hack/tools/$(BIN_DIR))

ifeq ($(GITHUB_ACTIONS),true)
# Use the values from GitHub Actions
GOPATH := $(shell echo $$GOPATH)
GOBIN := $(shell echo $$GOBIN)
GITHUB_INFO := Running in GitHub Actions
else
GOBIN := $(ROOT_DIR)/hack/tools/$(BIN_DIR)
# Use the system's GOPATH and GOBIN; if they're not set, use defaults
GOPATH ?= $(HOME)/go
GOBIN ?= $(GOPATH)/bin
GITHUB_INFO := Not running in GitHub Actions
endif

$(info GOPATH before update: $(GOPATH))
$(info GOBIN before update: $(GOBIN))
$(info $(GITHUB_INFO))

# Normalize $(ROOT_DIR) and ensure no double slashes before appending
GOBIN := $(patsubst %/,%,$(subst \,/,${ROOT_DIR}))/hack/tools/$(BIN_DIR)

# Ensure $(GOPATH) uses forward slashes
GOPATH := $(subst \,/,$(GOPATH))


# It's best to use these echo commands in an actual recipe, not directly in the conditional logic
# For demonstration purposes, they are kept here but consider moving them into a rule's command
$(info GOBIN after update: $(GOBIN))
$(info GOPATH after update: $(GOPATH))


golangci-lint: $(GOLANGCI_LINT) ## Install golangci-lint
$(GOLANGCI_LINT):
@echo "GOPATH current: $(GOPATH)"
@echo "GOBIN current: $(GOBIN)"
mkdir -p $(BIN_DIR)
@ls $(GOPATH)
@ls $(GOPATH)/bin
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$(GOLANGCI_LINT_VERSION)
@ls $(GOPATH)
@ls $(GOPATH)/bin
@echo "GOBIN files: $(GOBIN)"
@ls $(GOBIN)
#mv $(GOPATH)/$(GOLANGCI_LINT) $(GOBIN) && chmod a+x $(GOBIN)/$(notdir $(GOLANGCI_LINT))


## --------------------------------------
## Help
## --------------------------------------
Expand All @@ -70,11 +109,11 @@ help: ## Display this help

goimports: $(GOIMPORTS) ## Install goimports
$(GOIMPORTS):
@echo "BIN_DIR: $(BIN_DIR)"
@echo "ROOT_DIR: $(ROOT_DIR)"
@echo "GOBIN path: $(ROOT_DIR)/hack/tools/$(BIN_DIR)"
@mkdir -p $(BIN_DIR)
@GOBIN=$(subst \,/,$(ROOT_DIR)/hack/tools/$(BIN_DIR)) go install golang.org/x/tools/cmd/goimports@v$(GOIMPORTS_VERSION)
@echo "gobin in goimports: $(GOBIN)"
mkdir -p $(BIN_DIR)
go install golang.org/x/tools/cmd/goimports@v$(GOIMPORTS_VERSION)
@echo "GOBIN files: $(GOBIN)"
@ls $(GOBIN)

#mkdir -p $(BIN_DIR)
#GOBIN=$(ROOT_DIR)/hack/tools/$(BIN_DIR) go install golang.org/x/tools/cmd/goimports@v$(GOIMPORTS_VERSION)
Expand All @@ -84,13 +123,6 @@ $(GOIMPORTS):
#mv $(GOPATH)/bin/goimports $(GOIMPORTS)
#GOBIN=$(ROOT_DIR)/hack/tools/$(BIN_DIR) go install golang.org/x/tools/cmd/goimports@v$(GOIMPORTS_VERSION)

golangci-lint: $(GOLANGCI_LINT) ## Install golangci-lint
$(GOLANGCI_LINT):
@echo "Installing golangci-lint to $(GOLANGCI_LINT)"
@echo "GOBIN path: $(ROOT_DIR)/hack/tools/$(BIN_DIR)"
@echo "GOBIN will be set to $(GOBIN)"
mkdir -p $(BIN_DIR)
GOBIN=$(ROOT_DIR)/hack/tools/$(BIN_DIR) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$(GOLANGCI_LINT_VERSION)

vale: $(VALE)
$(VALE):
Expand All @@ -112,18 +144,17 @@ $(VALE):
controller-gen: $(CONTROLLER_GEN) ## Build controller-gen
$(CONTROLLER_GEN):
mkdir -p $(BIN_DIR)
#go build -tags=tools -o $@ sigs.k8s.io/controller-tools/cmd/controller-gen
GOBIN=$(ROOT_DIR)/hack/tools/$(BIN_DIR) go install sigs.k8s.io/controller-tools/cmd/controller-gen@v$(CONTROLLER_TOOLS_VERSION)
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v$(CONTROLLER_TOOLS_VERSION)

cosign: $(COSIGN) ## Install cosign
$(COSIGN):
mkdir -p $(BIN_DIR)
GOBIN=$(ROOT_DIR)/hack/tools/$(BIN_DIR) go install github.com/sigstore/cosign/v2/cmd/cosign@v$(COSIGN_VERSION)
go install github.com/sigstore/cosign/v2/cmd/cosign@v$(COSIGN_VERSION)

misspell: $(MISSPELL) ## Install misspell
$(MISSPELL):
mkdir -p $(BIN_DIR)
GOBIN=$(ROOT_DIR)/hack/tools/$(BIN_DIR) go install github.com/client9/misspell/cmd/misspell@v$(MISSPELL_VERSION)
go install github.com/client9/misspell/cmd/misspell@v$(MISSPELL_VERSION)

imgpkg: $(IMGPKG) ## Install imgpkg
$(IMGPKG):
Expand Down Expand Up @@ -152,12 +183,13 @@ $(KIND):
ginkgo: $(GINKGO) ## Install ginkgo
$(GINKGO):
mkdir -p $(BIN_DIR)
GOBIN=$(ROOT_DIR)/hack/tools/$(BIN_DIR) go install github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION)
go install github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION)

go-junit-report: $(GOJUNITREPORT) ## Install go-junit-report
$(GOJUNITREPORT):
mkdir -p $(BIN_DIR)
GOBIN=$(ROOT_DIR)/hack/tools/$(BIN_DIR) go install github.com/jstemmer/go-junit-report@latest
go install github.com/jstemmer/go-junit-report@latest
@ls $(GOBIN)

## --------------------------------------
## Cleanup
Expand Down

0 comments on commit 2f7d3e1

Please sign in to comment.