ipfs / ci-helpers

Helper scripts for C.I.
6 stars 8 forks source link

travis ci script doesn't work with go modules #11

Closed lanzafame closed 5 years ago

lanzafame commented 5 years ago

The script outputs the following log and error:

$ bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh)
*** cd /tmp/tmp.bMIKMLkCCH
*** git -c advice.detachedHead=false clone -q -s /home/travis/gopath/src/github.com/libp2p/go-libp2p-secio .
*** go fmt ./...
*** cd /home/travis/gopath/src/github.com/libp2p/go-libp2p-secio
*** go vet ./...
*** Setting up test environment
net.ipv6.conf.lo.disable_ipv6 = 0
net.ipv6.conf.default.disable_ipv6 = 0
net.ipv6.conf.all.disable_ipv6 = 0
*** go build github.com/libp2p/go-libp2p-secio/v3
go: cannot find main module; see 'go help modules'

Source: https://travis-ci.org/libp2p/go-libp2p-secio/jobs/485661465

lanzafame commented 5 years ago

Another example output, running just the build step locally:

bash -c 'display_and_run() {
      echo "***" "$@"
      "$@"
}
env GO111MODULE=on go list -f \'{{if (len .GoFiles)}}{{.ImportPath}}{{end}}\' ./... | grep -v /vendor/ | \
  while read pkg; do
  (
    cd "$(mktemp -d)" && display_and_run go build "$pkg"
  )
done'
*** go build github.com/libp2p/go-libp2p-kad-dht/v5
can't load package: package github.com/libp2p/go-libp2p-kad-dht/v5: cannot find package "github.com/libp2p/go-libp2p-kad-dht/v5" in any of:
        /usr/lib/go/src/github.com/libp2p/go-libp2p-kad-dht/v5 (from $GOROOT)
        /home/lanzafame/src/github.com/libp2p/go-libp2p-kad-dht/v5 (from $GOPATH)
*** go build github.com/libp2p/go-libp2p-kad-dht/v5/opts
can't load package: package github.com/libp2p/go-libp2p-kad-dht/v5/opts: cannot find package "github.com/libp2p/go-libp2p-kad-dht/v5/opts" in any of:
        /usr/lib/go/src/github.com/libp2p/go-libp2p-kad-dht/v5/opts (from $GOROOT)
        /home/lanzafame/src/github.com/libp2p/go-libp2p-kad-dht/v5/opts (from $GOPATH)
*** go build github.com/libp2p/go-libp2p-kad-dht/v5/pb
can't load package: package github.com/libp2p/go-libp2p-kad-dht/v5/pb: cannot find package "github.com/libp2p/go-libp2p-kad-dht/v5/pb" in any of:
        /usr/lib/go/src/github.com/libp2p/go-libp2p-kad-dht/v5/pb (from $GOROOT)
        /home/lanzafame/src/github.com/libp2p/go-libp2p-kad-dht/v5/pb (from $GOPATH)
*** go build github.com/libp2p/go-libp2p-kad-dht/v5/providers
can't load package: package github.com/libp2p/go-libp2p-kad-dht/v5/providers: cannot find package "github.com/libp2p/go-libp2p-kad-dht/v5/providers" in any of:
        /usr/lib/go/src/github.com/libp2p/go-libp2p-kad-dht/v5/providers (from $GOROOT)
        /home/lanzafame/src/github.com/libp2p/go-libp2p-kad-dht/v5/providers (from $GOPATH)
lanzafame commented 5 years ago

Update, missed env GO111MODULE=on for go build:

bash -c 'display_and_run() {
      echo "***" "$@"
      "$@"
}
env GO111MODULE=on go list -f \'{{if (len .GoFiles)}}{{.ImportPath}}{{end}}\' ./... | grep -v /vendor/ | \
  while read pkg; do
  (
    cd "$(mktemp -d)" && display_and_run env GO111MODULE=on go build "$pkg"
  )
done'
go: cannot find main module; see 'go help modules'
*** env GO111MODULE=on go build github.com/libp2p/go-libp2p-kad-dht/v5/opts
go: cannot find main module; see 'go help modules'
*** env GO111MODULE=on go build github.com/libp2p/go-libp2p-kad-dht/v5/pb
go: cannot find main module; see 'go help modules'
*** env GO111MODULE=on go build github.com/libp2p/go-libp2p-kad-dht/v5/providers
go: cannot find main module; see 'go help modules'
Stebalien commented 5 years ago

Ah... That's because it switches to a different directory. This may be a bug in go but I'm not sure.

Stebalien commented 5 years ago

We can probably use go build -o /dev/null "$pkg" instead.

lanzafame commented 5 years ago

Reading the go help modules section on main modules, it appears that everything is considered from the context of the root module directory. If that is the case is this script still valid in a modules world?

lanzafame commented 5 years ago

We can probably use go build -o /dev/null "$pkg" instead.

Will that actually build the files?

Stebalien commented 5 years ago

Hm, you're probably right. We can probably get away with building with respect to the root module (for now, at least).

lanzafame commented 5 years ago

@Stebalien The other option is we have a new modules aware script that we pull into newly migrated repos?

Stebalien commented 5 years ago

We can probably use go build -o /dev/null "$pkg" instead.

Will that actually build the files?

Yes.

@Stebalien The other option is we have a new modules aware script that we pull into newly migrated repos?

We can actually do it all in one script:

go list -f '{{if (len .GoFiles)}}{{.ImportPath}} {{if .Module}}{{.Module.Dir}}{{else}}{{.Dir}}{{end}}{{end}}' ./... | while read pkg dir; do
  cd "$dir"
  go build -o /dev/null "$pkg"
done