This commit is contained in:
parent
143676fcfb
commit
16520bb277
4 changed files with 66 additions and 3 deletions
|
@ -105,6 +105,7 @@ func (cr *containerReference) CopyDir(destPath string, srcPath string) common.Ex
|
|||
common.NewInfoExecutor("%sdocker cp src=%s dst=%s", logPrefix, srcPath, destPath),
|
||||
cr.connect(),
|
||||
cr.find(),
|
||||
cr.exec([]string{"mkdir", "-p", destPath}, nil),
|
||||
cr.copyDir(destPath, srcPath),
|
||||
).IfNot(common.Dryrun)
|
||||
}
|
||||
|
|
|
@ -113,12 +113,19 @@ func (rc *RunContext) startJobContainer() common.Executor {
|
|||
Stderr: logWriter,
|
||||
})
|
||||
|
||||
var copyWorkspace bool
|
||||
var copyToPath string
|
||||
if !rc.Config.BindWorkdir {
|
||||
copyToPath, copyWorkspace = rc.localCheckoutPath()
|
||||
copyToPath = filepath.Join("/github/workspace", copyToPath)
|
||||
}
|
||||
|
||||
return common.NewPipelineExecutor(
|
||||
rc.JobContainer.Pull(rc.Config.ForcePull),
|
||||
rc.JobContainer.Remove().IfBool(!rc.Config.ReuseContainers),
|
||||
rc.JobContainer.Create(),
|
||||
rc.JobContainer.Start(false),
|
||||
rc.JobContainer.CopyDir("/github/workspace", rc.Config.Workdir+"/.").IfBool(!rc.Config.BindWorkdir),
|
||||
rc.JobContainer.CopyDir(copyToPath, rc.Config.Workdir+"/.").IfBool(copyWorkspace),
|
||||
rc.JobContainer.Copy("/github/", &container.FileEntry{
|
||||
Name: "workflow/event.json",
|
||||
Mode: 644,
|
||||
|
@ -380,6 +387,24 @@ func (rc *RunContext) getGithubContext() *githubContext {
|
|||
return ghc
|
||||
}
|
||||
|
||||
func (ghc *githubContext) isLocalCheckout(step *model.Step) bool {
|
||||
if step.Type() != model.StepTypeUsesActionRemote {
|
||||
return false
|
||||
}
|
||||
remoteAction := newRemoteAction(step.Uses)
|
||||
if !remoteAction.IsCheckout() {
|
||||
return false
|
||||
}
|
||||
|
||||
if repository, ok := step.With["repository"]; ok && repository != ghc.Repository {
|
||||
return false
|
||||
}
|
||||
if repository, ok := step.With["ref"]; ok && repository != ghc.Ref {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func asString(v interface{}) string {
|
||||
if v == nil {
|
||||
return ""
|
||||
|
@ -421,5 +446,16 @@ func (rc *RunContext) withGithubEnv(env map[string]string) map[string]string {
|
|||
env["GITHUB_WORKSPACE"] = github.Workspace
|
||||
env["GITHUB_SHA"] = github.Sha
|
||||
env["GITHUB_REF"] = github.Ref
|
||||
env["GITHUB_TOKEN"] = github.Token
|
||||
return env
|
||||
}
|
||||
|
||||
func (rc *RunContext) localCheckoutPath() (string, bool) {
|
||||
ghContext := rc.getGithubContext()
|
||||
for _, step := range rc.Run.Job().Steps {
|
||||
if ghContext.isLocalCheckout(step) {
|
||||
return step.With["path"], true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ func (sc *StepContext) Executor() common.Executor {
|
|||
)
|
||||
case model.StepTypeUsesActionRemote:
|
||||
remoteAction := newRemoteAction(step.Uses)
|
||||
if remoteAction.Org == "actions" && remoteAction.Repo == "checkout" {
|
||||
if remoteAction.IsCheckout() && rc.getGithubContext().isLocalCheckout(step) {
|
||||
return func(ctx context.Context) error {
|
||||
common.Logger(ctx).Debugf("Skipping actions/checkout")
|
||||
return nil
|
||||
|
@ -232,7 +232,7 @@ func (sc *StepContext) runAction(actionDir string, actionPath string) common.Exe
|
|||
envKey := regexp.MustCompile("[^A-Z0-9-]").ReplaceAllString(strings.ToUpper(inputID), "_")
|
||||
envKey = fmt.Sprintf("INPUT_%s", envKey)
|
||||
if _, ok := sc.Env[envKey]; !ok {
|
||||
sc.Env[envKey] = input.Default
|
||||
sc.Env[envKey] = rc.ExprEval.Interpolate(input.Default)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -311,6 +311,13 @@ func (ra *remoteAction) CloneURL() string {
|
|||
return fmt.Sprintf("https://github.com/%s/%s", ra.Org, ra.Repo)
|
||||
}
|
||||
|
||||
func (ra *remoteAction) IsCheckout() bool {
|
||||
if ra.Org == "actions" && ra.Repo == "checkout" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func newRemoteAction(action string) *remoteAction {
|
||||
r := regexp.MustCompile(`^([^/@]+)/([^/@]+)(/([^@]*))?(@(.*))?$`)
|
||||
matches := r.FindStringSubmatch(action)
|
||||
|
|
19
pkg/runner/testdata/issue-122/main.yaml
vendored
Normal file
19
pkg/runner/testdata/issue-122/main.yaml
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
name: Checkout
|
||||
|
||||
on: push
|
||||
|
||||
jobs:
|
||||
|
||||
test:
|
||||
name: Test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
path: test-subdir1
|
||||
- run: grep "Checkout" test-subdir1/issue-122/main.yaml
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
repository: actions/checkout
|
||||
path: test-subdir2
|
||||
- run: grep "Checkout" test-subdir2/action.yml
|
Loading…
Reference in a new issue