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

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

Closed
lanzafame opened this issue Jan 29, 2019 · 9 comments
Closed

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

lanzafame opened this issue Jan 29, 2019 · 9 comments
Assignees

Comments

@lanzafame
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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
Copy link
Member

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

@Stebalien
Copy link
Member

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

@lanzafame
Copy link
Contributor Author

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
Copy link
Contributor Author

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

Will that actually build the files?

@Stebalien
Copy link
Member

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

@lanzafame
Copy link
Contributor Author

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

@Stebalien
Copy link
Member

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

@ghost ghost assigned lanzafame Jan 29, 2019
@ghost ghost added the status/in-progress In progress label Jan 29, 2019
@ghost ghost removed the status/in-progress In progress label Jan 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants