Skip to content

Commit

Permalink
refactor: migrate to new aperturerobotics/common pattern
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Stewart <[email protected]>
  • Loading branch information
paralin committed Apr 23, 2024
1 parent 84c4c54 commit a4daa22
Show file tree
Hide file tree
Showing 18 changed files with 47 additions and 2,431 deletions.
9 changes: 0 additions & 9 deletions .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@
"workarounds:all"
],
"branchConcurrentLimit": 0,
"ignorePaths": ["hack"],
"packageRules": [
{
"matchManagers": ["gomod"],
"matchDepTypes": ["replace"],
"enabled": false
},
{
"matchPackageNames": ["github.com/libp2p/go-libp2p"],
"allowedVersions": ["^v0.*"]
},
{
"matchPackageNames": ["github.com/pauleyj/gobee"],
"enabled": false
}
]
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ __debug*
.aider*

dist/
/.tools/
148 changes: 18 additions & 130 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,143 +1,31 @@
# https://github.com/aperturerobotics/template

PROJECT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SHELL:=bash
PROTOWRAP=hack/bin/protowrap
PROTOC_GEN_GO=hack/bin/protoc-gen-go-lite
PROTOC_GEN_STARPC=hack/bin/protoc-gen-go-starpc
GOIMPORTS=hack/bin/goimports
GOFUMPT=hack/bin/gofumpt
GOLANGCI_LINT=hack/bin/golangci-lint
GO_MOD_OUTDATED=hack/bin/go-mod-outdated
GOLIST=go list -f "{{ .Dir }}" -m
MAKEFLAGS += --no-print-directory

GORELEASER=hack/bin/goreleaser
GO_VENDOR_DIR := ./vendor
COMMON_DIR := $(GO_VENDOR_DIR)/github.com/aperturerobotics/common
COMMON_MAKEFILE := $(COMMON_DIR)/Makefile

export GO111MODULE=on
undefine GOARCH
undefine GOOS

all:

vendor:
go mod vendor

$(PROTOC_GEN_GO):
cd ./hack; \
go build -v \
-o ./bin/protoc-gen-go-lite \
github.com/aperturerobotics/protobuf-go-lite/cmd/protoc-gen-go-lite

$(GOIMPORTS):
cd ./hack; \
go build -v \
-o ./bin/goimports \
golang.org/x/tools/cmd/goimports

$(GOFUMPT):
cd ./hack; \
go build -v \
-o ./bin/gofumpt \
mvdan.cc/gofumpt

$(PROTOWRAP):
cd ./hack; \
go build -v \
-o ./bin/protowrap \
github.com/aperturerobotics/goprotowrap/cmd/protowrap

$(GOLANGCI_LINT):
cd ./hack; \
go build -v \
-o ./bin/golangci-lint \
github.com/golangci/golangci-lint/cmd/golangci-lint

$(GO_MOD_OUTDATED):
cd ./hack; \
go build -v \
-o ./bin/go-mod-outdated \
github.com/psampaz/go-mod-outdated
.PHONY: $(MAKECMDGOALS)

$(PROTOC_GEN_STARPC):
cd ./hack; \
go build -v \
-o ./bin/protoc-gen-go-starpc \
github.com/aperturerobotics/starpc/cmd/protoc-gen-go-starpc

node_modules:
yarn install

.PHONY: genproto
genproto: vendor node_modules $(GOIMPORTS) $(PROTOWRAP) $(PROTOC_GEN_GO) $(PROTOC_GEN_STARPC)
shopt -s globstar; \
set -eo pipefail; \
export PROJECT=$$(go list -m); \
export PATH=$$(pwd)/hack/bin:$${PATH}; \
export OUT=$$(pwd)/vendor; \
mkdir -p $${OUT}/$$(dirname $${PROJECT}); \
rm $$(pwd)/vendor/$${PROJECT} || true; \
ln -s $$(pwd) $$(pwd)/vendor/$${PROJECT} ; \
protogen() { \
$(PROTOWRAP) \
-I $${OUT} \
--plugin=./node_modules/.bin/protoc-gen-es \
--plugin=./node_modules/.bin/protoc-gen-es-starpc \
--go-lite_out=$${OUT} \
--go-lite_opt=features=marshal+unmarshal+size+equal+json+clone+text \
--go-starpc_out=$${OUT} \
--es_out=$${OUT} \
--es_opt target=ts \
--es_opt ts_nocheck=false \
--es-starpc_out=$${OUT} \
--es-starpc_opt target=ts \
--es-starpc_opt ts_nocheck=false \
--proto_path $${OUT} \
--print_structure \
--only_specified_files \
$$(\
git \
ls-files "$$1" |\
xargs printf -- \
"$$(pwd)/vendor/$${PROJECT}/%s "); \
}; \
protogen "./*.proto"; \
rm $$(pwd)/vendor/$${PROJECT} || true
$(GOIMPORTS) -w ./
npm run format:js

.PHONY: gen
gen: genproto

.PHONY: outdated
outdated: $(GO_MOD_OUTDATED)
go list -mod=mod -u -m -json all | $(GO_MOD_OUTDATED) -update -direct

.PHONY: list
list: $(GO_MOD_OUTDATED)
go list -mod=mod -u -m -json all | $(GO_MOD_OUTDATED)

.PHONY: lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run

.PHONY: fix
fix: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run --fix
all:

.PHONY: test
test:
go test -v ./...
$(COMMON_MAKEFILE): vendor
@if [ ! -f $(COMMON_MAKEFILE) ]; then \
echo "Please add github.com/aperturerobotics/common to your go.mod."; \
exit 1; \
fi

.PHONY: format
format: $(GOFUMPT) $(GOIMPORTS)
$(GOIMPORTS) -w ./
$(GOFUMPT) -w ./
$(MAKECMDGOALS): $(COMMON_MAKEFILE)
@$(MAKE) -C $(COMMON_DIR) PROJECT_DIR="$(PROJECT_DIR)" $@

$(GORELEASER):
cd ./hack; \
go build -v \
-o ./bin/goreleaser \
github.com/goreleaser/goreleaser
%: $(COMMON_MAKEFILE)
@$(MAKE) -C $(COMMON_DIR) PROJECT_DIR="$(PROJECT_DIR)" $@

.PHONY: release
release: $(GORELEASER)
$(GORELEASER) release --clean
vendor:
go mod vendor
9 changes: 9 additions & 0 deletions deps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build deps_only
// +build deps_only

package bifrost

import (
// _ imports common with the Makefile and tools
_ "github.com/aperturerobotics/common"
)
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ replace (

require (
filippo.io/edwards25519 v1.1.1-0.20231210192602-a7dfd8e4e6b4
github.com/aperturerobotics/common v0.12.0
github.com/blang/semver v3.5.1+incompatible
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/klauspost/compress v1.17.8
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/aperturerobotics/bifrost-nats-client v1.10.1-0.20200831103200-24c3d04
github.com/aperturerobotics/bifrost-nats-client v1.10.1-0.20200831103200-24c3d0464e58/go.mod h1:ougcjYEZDYV8pVtaNbA5sgYDukkYHyKtSsW/T3B13j0=
github.com/aperturerobotics/bifrost-nats-server/v2 v2.1.8-0.20221228081037-b7c2df0c151f h1:bmScByQNGDPPy9T+zdwu816XaCbFtD5UDyqZMRiHJ80=
github.com/aperturerobotics/bifrost-nats-server/v2 v2.1.8-0.20221228081037-b7c2df0c151f/go.mod h1:kIcZtLpq4UIZzOqduYLm1mYU1nuMBtN6XuDCtQ21QT8=
github.com/aperturerobotics/common v0.12.0 h1:kN4w2P5BAR5ingpeYDvnGjrW70MmsljbzuF3J7k4JOM=
github.com/aperturerobotics/common v0.12.0/go.mod h1:XAF6181CsLce+cercpaPUo0fWps0V6X1RPo8zQBytJA=
github.com/aperturerobotics/controllerbus v0.42.0 h1:Z9/sCCZvASqcQIuuWv8yAhMlFoTOsax/rtwxAYWpx8s=
github.com/aperturerobotics/controllerbus v0.42.0/go.mod h1:nOjqUOCt7mX8KOYFWOX0v/ytrE6cu6cyaHSZvqaUqxg=
github.com/aperturerobotics/entitygraph v0.8.2 h1:pNR5f6DJK+UF0IyXMJwtVXkjDI+KuoJdKiF2QuNH+iE=
Expand Down
2 changes: 0 additions & 2 deletions hack/.gitignore

This file was deleted.

14 changes: 0 additions & 14 deletions hack/Makefile

This file was deleted.

Loading

0 comments on commit a4daa22

Please sign in to comment.