Skip to content

Commit

Permalink
support mono repo deps (micro#1736)
Browse files Browse the repository at this point in the history
* support mono repo deps

* add protoc
  • Loading branch information
domwong authored Jun 24, 2020
1 parent 2b506b1 commit a2a1f4d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/micro-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/micro-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions runtime/local/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
24 changes: 23 additions & 1 deletion runtime/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package runtime
import (
"fmt"
"io"
"path/filepath"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand Down

0 comments on commit a2a1f4d

Please sign in to comment.