support mono repo deps (#1736)

* support mono repo deps

* add protoc
This commit is contained in:
Dominic Wong 2020-06-24 16:27:22 +01:00 committed by GitHub
parent 2b506b1a2a
commit a2a1f4dfbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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,