github.com/nektos/act@v0.2.63-0.20240520024548-8acde99bfa9c/pkg/container/linux_container_environment_extensions.go (about) 1 package container 2 3 import ( 4 "context" 5 "path/filepath" 6 "regexp" 7 "runtime" 8 "strings" 9 10 log "github.com/sirupsen/logrus" 11 ) 12 13 type LinuxContainerEnvironmentExtensions struct { 14 } 15 16 // Resolves the equivalent host path inside the container 17 // This is required for windows and WSL 2 to translate things like C:\Users\Myproject to /mnt/users/Myproject 18 // For use in docker volumes and binds 19 func (*LinuxContainerEnvironmentExtensions) ToContainerPath(path string) string { 20 if runtime.GOOS == "windows" && strings.Contains(path, "/") { 21 log.Error("You cannot specify linux style local paths (/mnt/etc) on Windows as it does not understand them.") 22 return "" 23 } 24 25 abspath, err := filepath.Abs(path) 26 if err != nil { 27 log.Error(err) 28 return "" 29 } 30 31 // Test if the path is a windows path 32 windowsPathRegex := regexp.MustCompile(`^([a-zA-Z]):\\(.+)$`) 33 windowsPathComponents := windowsPathRegex.FindStringSubmatch(abspath) 34 35 // Return as-is if no match 36 if windowsPathComponents == nil { 37 return abspath 38 } 39 40 // Convert to WSL2-compatible path if it is a windows path 41 // NOTE: Cannot use filepath because it will use the wrong path separators assuming we want the path to be windows 42 // based if running on Windows, and because we are feeding this to Docker, GoLang auto-path-translate doesn't work. 43 driveLetter := strings.ToLower(windowsPathComponents[1]) 44 translatedPath := strings.ReplaceAll(windowsPathComponents[2], `\`, `/`) 45 // Should make something like /mnt/c/Users/person/My Folder/MyActProject 46 result := strings.Join([]string{"/mnt", driveLetter, translatedPath}, `/`) 47 return result 48 } 49 50 func (*LinuxContainerEnvironmentExtensions) GetActPath() string { 51 return "/var/run/act" 52 } 53 54 func (*LinuxContainerEnvironmentExtensions) GetPathVariableName() string { 55 return "PATH" 56 } 57 58 func (*LinuxContainerEnvironmentExtensions) DefaultPathVariable() string { 59 return "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" 60 } 61 62 func (*LinuxContainerEnvironmentExtensions) JoinPathVariable(paths ...string) string { 63 return strings.Join(paths, ":") 64 } 65 66 func (*LinuxContainerEnvironmentExtensions) GetRunnerContext(ctx context.Context) map[string]interface{} { 67 return map[string]interface{}{ 68 "os": "Linux", 69 "arch": RunnerArch(ctx), 70 "temp": "/tmp", 71 "tool_cache": "/opt/hostedtoolcache", 72 } 73 } 74 75 func (*LinuxContainerEnvironmentExtensions) IsEnvironmentCaseInsensitive() bool { 76 return false 77 }