Skip to content

Commit

Permalink
Move api & gen from internal to pkg (#575)
Browse files Browse the repository at this point in the history
This refactor will allow linking against Runme's proto API definitions.
  • Loading branch information
sourishkrout authored May 14, 2024
1 parent a144659 commit d714da3
Show file tree
Hide file tree
Showing 84 changed files with 100 additions and 99 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
internal/gen/**/* -diff
pkg/api/gen/**/* -diff
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ repos:
hooks:
- id: codespell
args: ["-L=ndoes,nd,clen"] # 2x words that are preceeded with "\n"; cLen
exclude: (package.*\.json$|go\.sum|internal/gen)
exclude: (package.*\.json$|go\.sum|pkg/api/gen)
- repo: https://github.com/TekWizely/pre-commit-golang
rev: v1.0.0-rc.1
hooks:
- id: go-fumpt
exclude: (^internal/gen/.*$|^internal/client/graphql/query/generated.go$)
exclude: (^pkg/api/gen/.*$|^internal/client/graphql/query/generated.go$)
- id: go-build-mod
- id: go-mod-tidy
- id: go-revive-repo-mod
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ proto/generate:

.PHONY: proto/clean
proto/clean:
rm -rf internal/gen/proto
rm -rf pkg/api/gen/proto

.PHONY: proto/dev
proto/dev: build proto/clean proto/generate
rm -rf $(RUNME_EXT_BASE)/node_modules/@buf/stateful_runme.community_timostamm-protobuf-ts/runme
cp -vrf internal/gen/proto/ts/runme $(RUNME_EXT_BASE)/node_modules/@buf/stateful_runme.community_timostamm-protobuf-ts
cp -vrf pkg/api/gen/proto/ts/runme $(RUNME_EXT_BASE)/node_modules/@buf/stateful_runme.community_timostamm-protobuf-ts

.PHONY: proto/dev/reset
proto/dev/reset:
Expand All @@ -113,7 +113,7 @@ proto/dev/reset:
# More: https://docs.buf.build/bsr/authentication
.PHONY: proto/publish
proto/publish:
@cd ./internal/api && buf push
@cd ./pkg/api && buf push

.PHONY: release
release: install/goreleaser
Expand Down
6 changes: 3 additions & 3 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ version: v1
plugins:
# Remote plugin. You can switch to a local one by using "go".
- plugin: buf.build/protocolbuffers/go
out: internal/gen/proto/go
out: pkg/api/gen/proto/go
opt: paths=source_relative

# Remote plugin. You can switch to a local one by using "go-grpc".
- plugin: buf.build/grpc/go
out: internal/gen/proto/go
out: pkg/api/gen/proto/go
opt: paths=source_relative

# Remote plugin. You can switch to a local one by using "timostamm-protobuf-ts".
- plugin: buf.build/community/timostamm-protobuf-ts
out: internal/gen/proto/ts
out: pkg/api/gen/proto/ts
opt: output_javascript,optimize_code_size,long_type_string,add_pb_suffix,ts_nocheck,eslint_disable
2 changes: 1 addition & 1 deletion buf.work.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version: v1
directories:
- internal/api
- pkg/api/proto
4 changes: 2 additions & 2 deletions examples/grpc-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"time"

"github.com/pkg/errors"
parserv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/parser/v1"
runnerv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v1"
runmetls "github.com/stateful/runme/v3/internal/tls"
parserv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/parser/v1"
runnerv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v1"
"golang.org/x/sync/errgroup"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (

"github.com/stateful/runme/v3/internal/document"
"github.com/stateful/runme/v3/internal/document/identity"
runnerv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v1"
"github.com/stateful/runme/v3/internal/project"
"github.com/stateful/runme/v3/internal/runner/client"
"github.com/stateful/runme/v3/internal/tui"
"github.com/stateful/runme/v3/internal/tui/prompt"
runnerv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v1"
)

const envStackDepth = "__RUNME_STACK_DEPTH"
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package cmd
import (
"testing"

runnerv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v1"
"github.com/stateful/runme/v3/internal/tui/prompt"
runnerv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v1"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

runnerv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v1"
"github.com/stateful/runme/v3/internal/runner/client"
runmetls "github.com/stateful/runme/v3/internal/tls"
runnerv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v1"
)

var osEnviron = os.Environ
Expand Down
8 changes: 4 additions & 4 deletions internal/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import (
"google.golang.org/grpc/reflection"

"github.com/stateful/runme/v3/internal/document/editor/editorservice"
parserv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/parser/v1"
projectv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/project/v1"
runnerv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v1"
runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
"github.com/stateful/runme/v3/internal/project/projectservice"
"github.com/stateful/runme/v3/internal/runner"
runnerv2service "github.com/stateful/runme/v3/internal/runnerv2service"
runmetls "github.com/stateful/runme/v3/internal/tls"
parserv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/parser/v1"
projectv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/project/v1"
runnerv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v1"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
)

func serverCmd() *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion internal/command/command_args_normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"go.uber.org/multierr"
"go.uber.org/zap"

runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion internal/command/command_docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/stateful/runme/v3/internal/dockerexec"
runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
)

func TestDockerCommand(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/command/command_native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion internal/command/command_terminal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"

runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
)

func TestTerminalCommand_Options_Stdinwriter_Nil(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/stateful/runme/v3/internal/document"
"github.com/stateful/runme/v3/internal/document/identity"
runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion internal/command/command_virtual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/stateful/runme/v3/internal/document"
"github.com/stateful/runme/v3/internal/document/identity"
runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
)

func TestVirtualCommand(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/command/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package command
import (
"strings"

runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
"google.golang.org/protobuf/proto"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/command/config_code_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"

"github.com/stateful/runme/v3/internal/document"
runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
)

func NewConfigFromCodeBlock(block *document.CodeBlock) (*Config, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/command/config_mode_normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package command
import (
"path/filepath"

runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
)

func modeNormalizer(cfg *Config) (func() error, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"google.golang.org/protobuf/reflect/protoreflect"
"gopkg.in/yaml.v3"

configv1alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/config/v1alpha1"
configv1alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/config/v1alpha1"
)

// Config is a flatten configuration of runme.yaml. The purpose of it is to
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/anypb"

configv1alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/config/v1alpha1"
configv1alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/config/v1alpha1"
)

func TestParseYAML(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/document/editor/editorservice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/stateful/runme/v3/internal/document"
"github.com/stateful/runme/v3/internal/document/editor"
"github.com/stateful/runme/v3/internal/document/identity"
parserv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/parser/v1"
parserv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/parser/v1"
)

type parserServiceServer struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/document/editor/editorservice/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"strings"
"testing"

parserv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/parser/v1"
"github.com/stateful/runme/v3/internal/ulid"
"github.com/stateful/runme/v3/internal/version"
parserv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/parser/v1"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"google.golang.org/grpc"
Expand Down
2 changes: 1 addition & 1 deletion internal/project/projectservice/project_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"go.uber.org/zap"

projectv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/project/v1"
"github.com/stateful/runme/v3/internal/project"
projectv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/project/v1"
)

type projectServiceServer struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/project/projectservice/project_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"testing"

"github.com/pkg/errors"
projectv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/project/v1"
"github.com/stateful/runme/v3/internal/project/projectservice"
"github.com/stateful/runme/v3/internal/project/testdata"
"github.com/stateful/runme/v3/internal/project/testutils"
projectv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/project/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
Expand Down
2 changes: 1 addition & 1 deletion internal/runner/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/muesli/cancelreader"
"github.com/pkg/errors"
"github.com/stateful/runme/v3/internal/document"
runnerv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v1"
"github.com/stateful/runme/v3/internal/project"
"github.com/stateful/runme/v3/internal/runner"
runnerv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v1"
"go.uber.org/zap"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/runner/client/client_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"github.com/muesli/cancelreader"
"github.com/pkg/errors"
"github.com/stateful/runme/v3/internal/document"
runnerv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v1"
"github.com/stateful/runme/v3/internal/project"
"github.com/stateful/runme/v3/internal/runner"
"github.com/stateful/runme/v3/internal/system"
runnerv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v1"
"go.uber.org/zap"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/runner/client/client_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/status"

runnerv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v1"
"github.com/stateful/runme/v3/internal/project"
"github.com/stateful/runme/v3/internal/runner"
runmetls "github.com/stateful/runme/v3/internal/tls"
runnerv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v1"
)

type RemoteRunner struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/runner/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"testing"

"github.com/oklog/ulid/v2"
runnerv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v1"
"github.com/stateful/runme/v3/internal/project"
"github.com/stateful/runme/v3/internal/runner"
runnerv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
Expand Down
2 changes: 1 addition & 1 deletion internal/runner/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"google.golang.org/protobuf/types/known/wrapperspb"

commandpkg "github.com/stateful/runme/v3/internal/command"
runnerv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v1"
"github.com/stateful/runme/v3/internal/owl"
"github.com/stateful/runme/v3/internal/project"
"github.com/stateful/runme/v3/internal/rbuffer"
"github.com/stateful/runme/v3/internal/ulid"
runnerv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v1"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion internal/runner/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"google.golang.org/grpc/test/bufconn"
"google.golang.org/protobuf/proto"

runnerv1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v1"
runnerv1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v1"
)

func testCreateLogger(t *testing.T) *zap.Logger {
Expand Down
2 changes: 1 addition & 1 deletion internal/runnerv2service/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"go.uber.org/zap"

"github.com/stateful/runme/v3/internal/command"
runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
"github.com/stateful/runme/v3/internal/rbuffer"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion internal/runnerv2service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"google.golang.org/grpc/status"

"github.com/stateful/runme/v3/internal/command"
runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
)

type runnerService struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/runnerv2service/service_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/wrapperspb"

runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
"github.com/stateful/runme/v3/internal/ulid"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
)

func (r *runnerService) Execute(srv runnerv2alpha1.RunnerService_ExecuteServer) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/runnerv2service/service_execute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"google.golang.org/grpc/test/bufconn"

"github.com/stateful/runme/v3/internal/command"
runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
)

func init() {
Expand Down
2 changes: 1 addition & 1 deletion internal/runnerv2service/service_resolve_program.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"google.golang.org/grpc/status"

"github.com/stateful/runme/v3/internal/command"
runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
)

func (r *runnerService) ResolveProgram(ctx context.Context, req *runnerv2alpha1.ResolveProgramRequest) (*runnerv2alpha1.ResolveProgramResponse, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/runnerv2service/service_resolve_program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"

runnerv2alpha1 "github.com/stateful/runme/v3/internal/gen/proto/go/runme/runner/v2alpha1"
runnerv2alpha1 "github.com/stateful/runme/v3/pkg/api/gen/proto/go/runme/runner/v2alpha1"
)

// todo(sebastian): port test cases from v1
Expand Down
Loading

0 comments on commit d714da3

Please sign in to comment.