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

fix: match the golang version in go.mod #493

Merged
merged 1 commit into from
May 10, 2021
Merged
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

GO_VERSION ?= 1.15
GO_VERSION ?= $(shell go run ./scripts/detectgoversion/detect.go 2>/dev/null || printf '1.16')
BINNAME ?= move2kube
PLUGIN_BINNAME ?= kubectl-translate
BINDIR := $(CURDIR)/bin
Expand Down Expand Up @@ -73,7 +73,7 @@ build: get $(BINDIR)/$(BINNAME) ## Build go code
@printf "\033[32m-------------------------------------\n BUILD SUCCESS\n-------------------------------------\033[0m\n"

$(BINDIR)/$(BINNAME): $(SRC)
go build -tags excludecodegen,excludedist -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(BINNAME) ./cmd/${BINNAME}
go build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(BINNAME) ./cmd/${BINNAME}
ifeq ($(HAS_UPX),true)
@echo 'upx detected. compressing binary...'
upx $(BINDIR)/$(BINNAME)
Expand All @@ -89,7 +89,7 @@ endif
build-kubectl-translate: get $(BINDIR)/$(PLUGIN_BINNAME) ## Build translate plugin for kubectl https://github.com/kubernetes-sigs/krew

$(BINDIR)/$(PLUGIN_BINNAME): $(SRC)
go build -tags excludecodegen,excludedist -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(PLUGIN_BINNAME) ./cmd/kubectltranslate
go build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(PLUGIN_BINNAME) ./cmd/kubectltranslate

.PHONY: get
get: go.mod
Expand Down
2 changes: 1 addition & 1 deletion internal/common/generator/generator.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !excludecodegen
// +build ignore

/*
Copyright IBM Corporation 2020
Expand Down
2 changes: 1 addition & 1 deletion internal/common/generator/generator_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !excludecodegen
// +build ignore

/*
Copyright IBM Corporation 2020
Expand Down
2 changes: 1 addition & 1 deletion scripts/builddist.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !excludedist
// +build ignore

/*
Copyright IBM Corporation 2020
Expand Down
46 changes: 46 additions & 0 deletions scripts/detectgoversion/detect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// +build ignore

/*
Copyright IBM Corporation 2020

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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.
*/

package main

import (
"fmt"
"io/ioutil"
"os"

"golang.org/x/mod/modfile"
)

func main() {
modFilePath := "go.mod"
if len(os.Args) == 2 && os.Args[1] != "" {
modFilePath = os.Args[1]
}
data, err := ioutil.ReadFile(modFilePath)
if err != nil {
panic(err)
}
modFile, err := modfile.Parse(modFilePath, data, nil)
if err != nil {
panic(err)
}
if modFile.Go == nil {
panic(fmt.Sprintf("didn't find the go version in the go.mod file at path %s", modFilePath))
}
fmt.Print(modFile.Go.Version)
}