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

Make go.thethings.network/lorawan-stack/v3/cmd a module #2495

Closed
wants to merge 4 commits into from
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ node_modules/
/pkg/webui/locales/.backend

# Development tooling
/.bin
/mage

# Keypair
Expand Down
2 changes: 1 addition & 1 deletion .mage/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (Dev) Misspell() error {
if mg.Verbose() {
fmt.Printf("Fixing common spelling mistakes in files\n")
}
return execGo("run", "github.com/client9/misspell/cmd/misspell", "-w", "-i", "mosquitto",
return execGoTool("misspell", "-w", "-i", "mosquitto",
".editorconfig",
".gitignore",
".goreleaser.yml",
Expand Down
2 changes: 1 addition & 1 deletion .mage/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
type Docs mg.Namespace

func execHugo(args ...string) error {
return execGo("run", append([]string{"-tags", "extended", "github.com/gohugoio/hugo", "-s", "./doc"}, args...)...)
return execGoTool("hugo", append([]string{"-s", "./doc"}, args...)...)
}

func (d Docs) yarn() (func(args ...string) error, error) {
Expand Down
22 changes: 16 additions & 6 deletions .mage/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ func execGo(cmd string, args ...string) error {
return err
}

func execGoTool(cmd string, args ...string) error {
if goTags != "" {
args = append([]string{fmt.Sprintf("-tags=%s", goTags)}, args...)
}
_, err := sh.Exec(nil, os.Stdout, os.Stderr, fmt.Sprintf("./.bin/%s", cmd), args...)
return err
}

func outputGo(cmd string, args ...string) (string, error) {
if goTags != "" {
args = append([]string{fmt.Sprintf("-tags=%s", goTags)}, args...)
Expand Down Expand Up @@ -140,7 +148,7 @@ func (g Go) Lint() error {
if mg.Verbose() {
fmt.Printf("Linting %d Go packages\n", len(dirs))
}
return execGo("run", append([]string{"github.com/mgechev/revive", "-config=.revive.toml", "-formatter=stylish"}, dirs...)...)
return execGoTool("revive", append([]string{"-config=.revive.toml", "-formatter=stylish"}, dirs...)...)
}

// Unconvert removes unnecessary type conversions from Go files.
Expand All @@ -155,11 +163,11 @@ func (g Go) Unconvert() error {
if mg.Verbose() {
fmt.Printf("Removing unnecessary type conversions from %d Go packages\n", len(dirs))
}
args := []string{"github.com/mdempsky/unconvert", "-safe", "-apply"}
args := []string{"-safe", "-apply"}
if goTags != "" {
args = append(args, "-tags", strings.Join(strings.Split(goTags, ","), " "))
}
return execGo("run", append(args, dirs...)...)
return execGoTool("unconvert", append(args, dirs...)...)
}

// Quality runs code quality checks on Go files.
Expand All @@ -184,13 +192,15 @@ func (Go) Test() error {
return execGoTest("./...")
}

var goBinaries = []string{"./cmd/ttn-lw-cli", "./cmd/ttn-lw-stack"}
var goBinaries = []string{"./ttn-lw-cli", "./ttn-lw-stack"}

// TestBinaries tests the Go binaries by executing them with the --help flag.
func (Go) TestBinaries() error {
if mg.Verbose() {
fmt.Println("Testing Go binaries")
}
os.Chdir("./cmd")
defer os.Chdir("..")
for _, binary := range goBinaries {
_, err := outputGo("run", binary, "--help")
if err != nil {
Expand Down Expand Up @@ -258,10 +268,10 @@ nextLine:
if mg.Verbose() {
fmt.Println("Sending Go coverage to Coveralls")
}
return execGo("run", "github.com/mattn/goveralls", "-coverprofile=coveralls_"+goCoverageFile, "-service="+service, "-repotoken="+os.Getenv("COVERALLS_TOKEN"))
return execGoTool("goveralls", "-coverprofile=coveralls_"+goCoverageFile, "-service="+service, "-repotoken="+os.Getenv("COVERALLS_TOKEN"))
}

// Messages builds the file with translatable messages in Go code.
func (g Go) Messages() error {
return execGo("run", "./cmd/internal/generate_i18n.go")
return execGoTool("generate_i18n")
}
2 changes: 1 addition & 1 deletion .mage/js_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,5 @@ func (k JsSDK) AllowedFieldMaskPaths() error {
if !changed {
return nil
}
return execGo("run", "./cmd/internal/generate_allowed_field_mask_paths.go")
return execGoTool("generate_allowed_field_mask_paths")
}
11 changes: 8 additions & 3 deletions .mage/mage.make
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

MAKE ?= make
MAGE ?= ./mage
GOBIN = $(PWD)/.bin
export GOBIN

$(MAGE): magefile.go $(wildcard .mage/*.go)
GO111MODULE=on go install github.com/magefile/mage
GO111MODULE=on go run github.com/magefile/mage -compile $(MAGE)
$(GOBIN):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we turn this into $(GOBIN): tools/go.mod for it to track that file for changes to the tools and versions?

@$(MAKE) -C tools

$(MAGE): magefile.go $(wildcard .mage/*.go) $(GOBIN)
$(GOBIN)/mage -compile $(MAGE)

.PHONY: init
init: $(MAGE)
Expand Down
4 changes: 2 additions & 2 deletions .mage/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ func (p Proto) Go(context.Context) error {
if err != nil {
return xerrors.Errorf("failed to construct absolute path to pkg/ttnpb: %w", err)
}
if err := execGo("run", "golang.org/x/tools/cmd/goimports", "-w", ttnpb); err != nil {
if err := execGoTool("goimports", "-w", ttnpb); err != nil {
return xerrors.Errorf("failed to run goimports on generated code: %w", err)
}
if err := execGo("run", "github.com/mdempsky/unconvert", "-apply", ttnpb); err != nil {
if err := execGoTool("unconvert", "-apply", ttnpb); err != nil {
return xerrors.Errorf("failed to run unconvert on generated code: %w", err)
}
return sh.RunV("gofmt", "-w", "-s", ttnpb)
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ after_success:
docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD"
snapcraft login --with snapcraft.login
if [[ ! -z "$TRAVIS_TAG" && "$TRAVIS_TAG" =~ ^v3\.[0-9]+\.[0-9]+ ]]; then
GO111MODULE=on go run github.com/goreleaser/goreleaser --release-notes <(printf "[Release notes](https://github.com/TheThingsNetwork/lorawan-stack/blob/${TRAVIS_TAG}/CHANGELOG.md#$(echo ${TRAVIS_TAG} | sed "s/v\([1-9]\+\)\.\([1-9]\+\)\.\([1-9]\+\)/\1\2\3---$(date +%Y-%m-%d)/"))")
./.bin/goreleaser --release-notes <(printf "[Release notes](https://github.com/TheThingsNetwork/lorawan-stack/blob/${TRAVIS_TAG}/CHANGELOG.md#$(echo ${TRAVIS_TAG} | sed "s/v\([1-9]\+\)\.\([1-9]\+\)\.\([1-9]\+\)/\1\2\3---$(date +%Y-%m-%d)/"))")
else
GO111MODULE=on go run github.com/goreleaser/goreleaser --snapshot
./.bin/goreleaser --snapshot
docker push $DOCKER_IMAGE_DEV:$TRAVIS_COMMIT
fi
fi
Expand Down
50 changes: 50 additions & 0 deletions cmd/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module go.thethings.network/lorawan-stack/v3/cmd

go 1.14

replace go.thethings.network/lorawan-stack/v3 => ../

// Use our fork of grpc-gateway.
replace github.com/grpc-ecosystem/grpc-gateway => github.com/TheThingsIndustries/grpc-gateway v1.14.4-gogo

// Use our fork of otto.
replace github.com/robertkrimen/otto => github.com/TheThingsIndustries/otto v0.0.0-20181129100957-6ddbbb60554a

// github.com/blang/semver doesn't have a v3 semantic import.
replace github.com/blang/semver => github.com/blang/semver v0.0.0-20190414182527-1a9109f8c4a1

// Dependency of Goreleaser that causes problems with module management.
// See https://github.com/Azure/go-autorest/issues/414.
replace github.com/Azure/go-autorest => github.com/Azure/go-autorest v14.1.0+incompatible

// Do not upgrade Echo beyond v4.1.2.
// See https://github.com/TheThingsNetwork/lorawan-stack/issues/977.
replace github.com/labstack/echo/v4 => github.com/labstack/echo/v4 v4.1.2

// Do not upgrade go-sqlmock beyond v1.3.0.
// See https://github.com/heptiolabs/healthcheck/issues/23.
replace gopkg.in/DATA-DOG/go-sqlmock.v1 => gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0

// Dependency of Hugo that causes problems with module management.
replace github.com/russross/blackfriday => github.com/russross/blackfriday v1.5.2

// Dependency of Hugo that causes problems with module management.
replace github.com/nicksnyder/go-i18n => github.com/nicksnyder/go-i18n v1.10.0

require (
github.com/disintegration/imaging v1.6.2
github.com/getsentry/sentry-go v0.5.1
github.com/gogo/protobuf v1.3.1
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c
github.com/jinzhu/gorm v1.9.12
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5
go.thethings.network/lorawan-stack/v3 v3.0.0-00010101000000-000000000000
gocloud.dev v0.19.0
golang.org/x/crypto v0.0.0-20200429183012-4b2356b1ed79
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
google.golang.org/grpc v1.29.1
gopkg.in/sourcemap.v1 v1.0.5 // indirect
gopkg.in/yaml.v2 v2.2.8
)
Loading