Skip to content

Commit

Permalink
Upgrade to Go 1.13.4 and set up for use with Go modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mhagger committed Dec 4, 2019
1 parent f0f1c1d commit 5c10272
Show file tree
Hide file tree
Showing 62 changed files with 38 additions and 10,806 deletions.
2 changes: 0 additions & 2 deletions .gitignore
@@ -1,4 +1,2 @@
/.gopath
/bin
/releases
/vendor/go1.*
36 changes: 0 additions & 36 deletions Gopkg.lock

This file was deleted.

13 changes: 0 additions & 13 deletions Gopkg.toml

This file was deleted.

28 changes: 14 additions & 14 deletions Makefile
@@ -1,7 +1,7 @@
PACKAGE := github.com/github/git-sizer
ROOTDIR := $(abspath $(CURDIR))
GOPATH := $(ROOTDIR)/.gopath
export GOPATH
GO111MODULES := 1
export GO111MODULES

GO := $(CURDIR)/script/go
GOFMT := $(CURDIR)/script/gofmt
Expand All @@ -13,12 +13,12 @@ ifdef USE_ISATTY
GOFLAGS := $(GOFLAGS) --tags isatty
endif

GO_SRCS := $(sort $(shell cd $(GOPATH)/src/$(PACKAGE) && $(GO) list -f ' \
{{$$ip := .ImportPath}} \
{{range .GoFiles }}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}} \
{{range .CgoFiles }}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}} \
{{range .TestGoFiles }}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}} \
{{range .XTestGoFiles}}{{printf ".gopath/src/%s/%s\n" $$ip .}}{{end}} \
GO_SRCS := $(sort $(shell $(GO) list -f ' \
{{$$ip := .Dir}} \
{{range .GoFiles }}{{printf "%s/%s\n" $$ip .}}{{end}} \
{{range .CgoFiles }}{{printf "%s/%s\n" $$ip .}}{{end}} \
{{range .TestGoFiles }}{{printf "%s/%s\n" $$ip .}}{{end}} \
{{range .XTestGoFiles}}{{printf "%s/%s\n" $$ip .}}{{end}} \
' ./...))

.PHONY: all
Expand All @@ -27,7 +27,7 @@ all: bin/git-sizer
.PHONY: bin/git-sizer
bin/git-sizer:
mkdir -p bin
cd $(GOPATH)/src/$(PACKAGE) && $(GO) build $(GOFLAGS) -o $(ROOTDIR)/$@ $(PACKAGE)
$(GO) build $(GOFLAGS) -o $(ROOTDIR)/$@ $(PACKAGE)

# Cross-compile for a bunch of common platforms. Note that this
# doesn't work with USE_ISATTY:
Expand All @@ -51,8 +51,7 @@ define PLATFORM_template =
.PHONY: bin/git-sizer-$(1)-$(2)$(3)
bin/git-sizer-$(1)-$(2)$(3):
mkdir -p bin
cd $$(GOPATH)/src/$$(PACKAGE) && \
GOOS=$(1) GOARCH=$(2) $$(GO) build $$(GOFLAGS) -ldflags "-X main.ReleaseVersion=$$(VERSION)" -o $$(ROOTDIR)/$$@ $$(PACKAGE)
GOOS=$(1) GOARCH=$(2) $$(GO) build $$(GOFLAGS) -ldflags "-X main.ReleaseVersion=$$(VERSION)" -o $$(ROOTDIR)/$$@ $$(PACKAGE)
common-platforms: bin/git-sizer-$(1)-$(2)$(3)

# Note that releases don't include code from vendor (they're only used
Expand All @@ -63,7 +62,8 @@ releases/git-sizer-$$(VERSION)-$(1)-$(2).zip: bin/git-sizer-$(1)-$(2)$(3)
mkdir -p releases/tmp-$$(VERSION)-$(1)-$(2)
cp README.md LICENSE.md releases/tmp-$$(VERSION)-$(1)-$(2)
cp bin/git-sizer-$(1)-$(2)$(3) releases/tmp-$$(VERSION)-$(1)-$(2)/git-sizer$(3)
cp vendor/github.com/spf13/pflag/LICENSE releases/tmp-$$(VERSION)-$(1)-$(2)/LICENSE-spf13-pflag
cp $$$$($$(GO) list -f '{{.Dir}}' github.com/spf13/pflag)/LICENSE \
releases/tmp-$$(VERSION)-$(1)-$(2)/LICENSE-spf13-pflag
rm -f $$@
zip -j $$@ releases/tmp-$$(VERSION)-$(1)-$(2)/*
rm -rf releases/tmp-$$(VERSION)-$(1)-$(2)
Expand All @@ -84,7 +84,7 @@ test: bin/git-sizer gotest

.PHONY: gotest
gotest:
cd $(GOPATH)/src/$(PACKAGE) && $(GO) test -timeout 60s $(GOFLAGS) ./...
$(GO) test -timeout 60s $(GOFLAGS) ./...

.PHONY: gofmt
gofmt:
Expand All @@ -102,7 +102,7 @@ govet:
clean:
rm -rf bin

# List all of this project's Go sources, excluding vendor, within .gopath:
# List all of this project's Go sources:
.PHONY: srcs
srcs:
@printf "%s\n" $(GO_SRCS)
8 changes: 0 additions & 8 deletions docs/BUILDING.md
Expand Up @@ -45,14 +45,6 @@ This procedure is intended for experts and people who want to help develop `git-

It is also possible to cross-compile for other platforms that are supported by Go. See the comments in the `Makefile` for more information.

Note that this procedure uses a project-local `GOPATH`. This means that you can clone the repository anywhere. The disadvantage is that Go tools need to know about this `GOPATH`. The `Makefile` and the scripts under `scripts/` take care of this automatically. But if you want to run `go` commands by hand, either first set your `GOPATH`:

export GOPATH="$(pwd)/.gopath"

Or use `script/go` and `script/gofmt` rather than `go` and `gofmt`, respectively.

Unfortunately, some Go tools get confused by the symlink that is used to make the project-local `GOPATH` work. If you have this problem, it sometimes helps to run such commands from `.gopath/src/github.com/github/git-sizer/`. Alternatively, clone the project into the traditional place in your normal `GOPATH`.


## Making a release

Expand Down
10 changes: 10 additions & 0 deletions go.mod
@@ -0,0 +1,10 @@
module github.com/github/git-sizer

go 1.13

require (
github.com/davecgh/go-spew v1.1.0
github.com/pmezard/go-difflib v1.0.0
github.com/spf13/pflag v1.0.0
github.com/stretchr/testify v1.2.1
)
8 changes: 8 additions & 0 deletions go.sum
@@ -0,0 +1,8 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/spf13/pflag v1.0.0 h1:oaPbdDe/x0UncahuwiPxW1GYJyilRAdsPnq3e1yaPcI=
github.com/spf13/pflag v1.0.0/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/testify v1.2.1 h1:52QO5WkIUcHGIR7EnGagH88x1bUzqGXTC5/1bDTUQ7U=
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
6 changes: 0 additions & 6 deletions script/bootstrap
Expand Up @@ -5,14 +5,8 @@ set -e
cd "$(dirname "$0")/.."

export ROOTDIR="$(pwd)"
export GOPATH="$ROOTDIR/.gopath"

if [[ "$(uname -s)" = "Darwin" ]]; then
brew bundle
fi
. script/ensure-go-installed.sh

BASE="$GOPATH/src/github.com/github/git-sizer"
rm -f "$BASE"
mkdir -p $(dirname "$BASE")
ln -s "$(pwd)" "$BASE"
6 changes: 3 additions & 3 deletions script/ensure-go-installed.sh
Expand Up @@ -4,17 +4,17 @@ if [ -z "$ROOTDIR" ]; then
echo 1>&2 'ensure-go-installed.sh invoked without ROOTDIR set!'
fi

# Is go installed, and at least 1.9?
# Is go installed, and at least 1.13?
go_ok() {
set -- $(go version 2>/dev/null |
sed -n 's/.*go\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1 \2/p' |
head -n 1)
[ $# -eq 2 ] && [ "$1" -eq 1 ] && [ "$2" -ge 9 ]
[ $# -eq 2 ] && [ "$1" -eq 1 ] && [ "$2" -ge 13 ]
}

# If a local go is installed, use it.
set_up_vendored_go() {
GO_VERSION=go1.9.2
GO_VERSION=go1.13.4
VENDORED_GOROOT="$ROOTDIR/vendor/$GO_VERSION/go"
if [ -x "$VENDORED_GOROOT/bin/go" ]; then
export GOROOT="$VENDORED_GOROOT"
Expand Down
1 change: 0 additions & 1 deletion script/go
Expand Up @@ -4,6 +4,5 @@ set -e

export ROOTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
. $ROOTDIR/script/ensure-go-installed.sh
export GOPATH=$ROOTDIR/.gopath

exec "$(basename $0)" "$@"
6 changes: 3 additions & 3 deletions script/install-vendored-go
@@ -1,14 +1,14 @@
#!/bin/sh

# The checksums below must correspond to the downloads for this version.
GO_VERSION=go1.9.2
GO_VERSION=go1.13.4

if [ $(uname -s) = "Darwin" ]; then
GO_PKG=${GO_VERSION}.darwin-amd64.tar.gz
GO_PKG_SHA=8b4f6ae6deae1150d2e341d02c247fd18a99af387516540eeb84702ffd76d3a1
GO_PKG_SHA=9f0721551a24a1eb43d2005cd58bd7b17574e50384b8da8896b0754259790752
elif [ $(uname -s) = "Linux" ]; then
GO_PKG=${GO_VERSION}.linux-amd64.tar.gz
GO_PKG_SHA=de874549d9a8d8d8062be05808509c09a88a248e77ec14eb77453530829ac02b
GO_PKG_SHA=692d17071736f74be04a72a06dab9cac1cd759377bd85316e52b2227604c004c
else
echo 1>&2 "I don't know how to install Go on your platform."
echo 1>&2 "Please install $GO_VERSION or later and add it to your PATH."
Expand Down
15 changes: 0 additions & 15 deletions vendor/github.com/davecgh/go-spew/LICENSE

This file was deleted.

152 changes: 0 additions & 152 deletions vendor/github.com/davecgh/go-spew/spew/bypass.go

This file was deleted.

0 comments on commit 5c10272

Please sign in to comment.