From a2a1f4dfbdb7099e0bff71b769ca16b827d177b2 Mon Sep 17 00:00:00 2001 From: Dominic Wong Date: Wed, 24 Jun 2020 16:27:22 +0100 Subject: [PATCH] support mono repo deps (#1736) * support mono repo deps * add protoc --- .github/workflows/micro-examples.yml | 3 +++ .github/workflows/micro-main.yml | 3 +++ runtime/local/git/git.go | 20 +++++++++++++------- runtime/service.go | 24 +++++++++++++++++++++++- 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/.github/workflows/micro-examples.yml b/.github/workflows/micro-examples.yml index ebd91ef8..c1742c5d 100644 --- a/.github/workflows/micro-examples.yml +++ b/.github/workflows/micro-examples.yml @@ -16,6 +16,9 @@ jobs: with: go-version: 1.13 id: go + + - name: Install Protoc + uses: arduino/setup-protoc@master - name: Check out this code uses: actions/checkout@v2 diff --git a/.github/workflows/micro-main.yml b/.github/workflows/micro-main.yml index 311dc431..616a6630 100644 --- a/.github/workflows/micro-main.yml +++ b/.github/workflows/micro-main.yml @@ -16,6 +16,9 @@ jobs: with: go-version: 1.13 id: go + + - name: Install Protoc + uses: arduino/setup-protoc@master - name: Check out this code uses: actions/checkout@v2 diff --git a/runtime/local/git/git.go b/runtime/local/git/git.go index 246aa79c..88ec350e 100644 --- a/runtime/local/git/git.go +++ b/runtime/local/git/git.go @@ -264,8 +264,8 @@ func ParseSource(source string) (*Source, error) { return ret, nil } -// ParseSourceLocal detects and handles local pathes too -// workdir should be used only from the CLI @todo better interface for this function. +// ParseSourceLocal a version of ParseSource that detects and handles local paths. +// Workdir should be used only from the CLI @todo better interface for this function. // PathExistsFunc exists only for testing purposes, to make the function side effect free. func ParseSourceLocal(workDir, source string, pathExistsFunc ...func(path string) (bool, error)) (*Source, error) { var pexists func(string) (bool, error) @@ -274,13 +274,19 @@ func ParseSourceLocal(workDir, source string, pathExistsFunc ...func(path string } else { pexists = pathExistsFunc[0] } - var localFullPath string - if len(workDir) > 0 { - localFullPath = filepath.Join(workDir, source) - } else { + isLocal := false + localFullPath := "" + // Check for absolute path + // @todo "/" won't work for Windows + if exists, err := pexists(source); strings.HasPrefix(source, "/") && err == nil && exists { + isLocal = true localFullPath = source + // Check for path relative to workdir + } else if exists, err := pexists(filepath.Join(workDir, source)); err == nil && exists { + isLocal = true + localFullPath = filepath.Join(workDir, source) } - if exists, err := pexists(localFullPath); err == nil && exists { + if isLocal { localRepoRoot, err := GetRepoRoot(localFullPath) if err != nil { return nil, err diff --git a/runtime/service.go b/runtime/service.go index 8e28de1f..7098e240 100644 --- a/runtime/service.go +++ b/runtime/service.go @@ -3,6 +3,7 @@ package runtime import ( "fmt" "io" + "path/filepath" "strconv" "strings" "sync" @@ -46,6 +47,27 @@ func newService(s *Service, c CreateOptions) *service { exec = strings.Join(c.Command, " ") args = c.Args + dir := s.Source + + // For uploaded packages, we upload the whole repo + // so the correct working directory to do a `go run .` + // needs to include the relative path from the repo root + // which is the service name. + // + // Could use a better upload check. + if strings.Contains(s.Source, "uploads") { + // There are two cases to consider here: + // a., if the uploaded code comes from a repo - in this case + // the service name is the relative path. + // b., if the uploaded code comes from a non repo folder - + // in this case the service name is the folder name. + // Because of this, we only append the service name to the source in + // case `a` + if ex, err := exists(filepath.Join(s.Source, s.Name)); err == nil && ex { + dir = filepath.Join(s.Source, s.Name) + } + } + return &service{ Service: s, Process: new(proc.Process), @@ -56,7 +78,7 @@ func newService(s *Service, c CreateOptions) *service { }, Env: c.Env, Args: args, - Dir: s.Source, + Dir: dir, }, closed: make(chan bool), output: c.Output,