Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow local actions outside the workspace #2108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 9 additions & 17 deletions pkg/runner/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,31 +445,23 @@
actionName := ""
containerActionDir := "."
if step.Type() != model.StepTypeUsesActionRemote {
actionName = getOsSafeRelativePath(actionDir, rc.Config.Workdir)
containerActionDir = rc.JobContainer.ToContainerPath(rc.Config.Workdir) + "/" + actionName
actionName = "./" + actionName
actionName = "./" + getOsSafeRelativePath(actionDir, rc.Config.Workdir)
containerActionDir = rc.JobContainer.ToContainerPath(actionDir)
} else if step.Type() == model.StepTypeUsesActionRemote {
actionName = getOsSafeRelativePath(actionDir, rc.ActionCacheDir())
containerActionDir = rc.JobContainer.GetActPath() + "/actions/" + actionName
}

if actionName == "" {
actionName = filepath.Base(actionDir)
if runtime.GOOS == "windows" {
actionName = strings.ReplaceAll(actionName, "\\", "/")
}
}
return actionName, containerActionDir
}

func getOsSafeRelativePath(s, prefix string) string {
actionName := strings.TrimPrefix(s, prefix)
if runtime.GOOS == "windows" {
actionName = strings.ReplaceAll(actionName, "\\", "/")
func getOsSafeRelativePath(s, basepath string) string {
if relpath, err := filepath.Rel(basepath, s); err == nil {
if runtime.GOOS == "windows" {
relpath = strings.ReplaceAll(relpath, "\\", "/")

Check warning on line 460 in pkg/runner/action.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/action.go#L460

Added line #L460 was not covered by tests
}
return relpath
}
actionName = strings.TrimPrefix(actionName, "/")

return actionName
return filepath.Base(s)

Check warning on line 464 in pkg/runner/action.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/action.go#L464

Added line #L464 was not covered by tests
}

func shouldRunPreStep(step actionStep) common.Conditional {
Expand Down
7 changes: 5 additions & 2 deletions pkg/runner/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"context"
"fmt"
"io"
"io/fs"
"strings"
Expand Down Expand Up @@ -224,8 +225,10 @@
t.Run(tt.name, func(t *testing.T) {
ctx := context.Background()

actionDir := fmt.Sprintf("%s/dir", tt.step.getRunContext().ActionCacheDir())

cm := &containerMock{}
cm.On("CopyDir", "/var/run/act/actions/dir/", "dir/", false).Return(func(ctx context.Context) error { return nil })
cm.On("CopyDir", "/var/run/act/actions/dir/", actionDir+"/", false).Return(func(ctx context.Context) error { return nil })

Check failure on line 231 in pkg/runner/action_test.go

View workflow job for this annotation

GitHub Actions / lint

cm.On undefined (type *containerMock has no field or method On) (typecheck)

envMatcher := mock.MatchedBy(func(env map[string]string) bool {
for k, v := range tt.expectedEnv {
Expand All @@ -240,7 +243,7 @@

tt.step.getRunContext().JobContainer = cm

err := runActionImpl(tt.step, "dir", newRemoteAction("org/repo/path@ref"))(ctx)
err := runActionImpl(tt.step, actionDir, newRemoteAction("org/repo/path@ref"))(ctx)

assert.Nil(t, err)
cm.AssertExpectations(t)
Expand Down
1 change: 1 addition & 0 deletions pkg/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ func TestRunEvent(t *testing.T) {
{workdir, "local-action-dockerfile", "push", "", platforms, secrets},
{workdir, "local-action-via-composite-dockerfile", "push", "", platforms, secrets},
{workdir, "local-action-js", "push", "", platforms, secrets},
{workdir, "local-action-outside-workspace", "push", "", platforms, secrets},

// Uses
{workdir, "uses-composite", "push", "", platforms, secrets},
Expand Down
17 changes: 17 additions & 0 deletions pkg/runner/testdata/local-action-outside-workspace/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: local-action-outside-workspace
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- run: mkdir ../action-outside-workspace
- run: |
cat <<-ACTIONEOF > ../action-outside-workspace/action.yml
name: test
runs:
using: composite
steps:
- run: echo hello
shell: bash
ACTIONEOF
- uses: ./../action-outside-workspace
Loading