act: Issue: #567 breaks `act` on Windows

Act version

https://github.com/nektos/act/commit/6cde8f64dcc0f54619168b4f3883afccc5539a9d https://github.com/nektos/act/releases/tag/v0.2.21

Expected behaviour

act doesn’t fail

Actual behaviour

act fails because paths on Windows (C:\users\something\path\) differ from paths on Linux (/home/something/path)

Workflow and/or repository

workflow
on:
  push:
jobs:
  tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

Steps to reproduce

Run act on Windows

act output

Log
cat  ~\..\..\..\..\act git: (6c258cf...) ≢ +1 ~0 -0 ! 
❯❯❯ go run main.go -W .\.github\workflows\test.yml
[test.yml/tests-1] 🧪  Matrix: map[deno:1.1.0 os:ubuntu-latest]
[test.yml/tests-2] 🚧  Skipping unsupported platform 'macos-latest'
[test.yml/tests-1] 🚀  Start image=catthehacker/ubuntu:act-latest
[test.yml/tests-1]   🐳  docker run image=catthehacker/ubuntu:act-latest platform=linux/amd64 entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[test.yml/tests-1]   🐳  docker cp src=C:\Users\cat\go\src\github.com\nektos\act\. dst=\github\workspace
[test.yml/tests-1] ⭐  Run actions/checkout@v2
[test.yml/tests-1]   ✅  Success - actions/checkout@v2
Error: context canceled
exit status 1
cat  ~\..\..\..\..\act git: (6c258cf...) ≢ +1 ~0 -0 !
❯❯❯
cat  ~\..\..\..\..\act git: (6cde8f6...) ≢ +1 ~0 -0 !
❯❯❯ go run main.go -W .\.github\workflows\test.yml
[test.yml/tests-1] 🧪  Matrix: map[deno:1.1.0 os:ubuntu-latest]
[test.yml/tests-2] 🚧  Skipping unsupported platform 'macos-latest'
[test.yml/tests-1] 🚀  Start image=catthehacker/ubuntu:act-latest
Error: Error response from daemon: the working directory 'C:\Users\cat\go\src\github.com\nektos\act' is invalid, it needs to be an absolute path
exit status 1
cat  ~\..\..\..\..\act git: (6cde8f6...) ≢ +1 ~0 -0 !
❯❯❯

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 13
  • Comments: 26 (24 by maintainers)

Commits related to this issue

Most upvoted comments

While waiting on the PRs to land, attached is a build that fixes all known issues I can tell on the windows side, as well as updated workers that run jobs in /home/runner as a non-root user to more closely match the actual github actions runner. To use these just update your .actrc with the following:

-P ubuntu-latest=ghcr.io/justingrote/act-pwsh-dotnet
-P ubuntu-20.04=ghcr.io/justingrote/act-pwsh-dotnet
-P ubuntu-18.04=ghcr.io/justingrote/act-pwsh-dotnet
-P ubuntu-16.04=ghcr.io/justingrote/act-pwsh-dotnet

(Remove the -dotnet if you want a smaller image that is just pwsh)

https://github.com/JustinGrote/act/tree/release/ActForWindows act.zip

Related Dockerfile repo: https://github.com/JustinGrote/act-dockerimage/

Recommendation to fix the issue for windows:

  1. The CWD (working directory) of the docker commands that get executed should always be from the perspective of “inside” the container, so it should be the variable which resolves to /github/workspace or /home/runner/work/PROJECT or whatever regardless of if it is linux or windows. Docs: https://docs.docker.com/engine/reference/commandline/exec/ image

  2. The Copy action to copy the working dir into the workspace via a docker command. Since act runs on windows there’s no path translation that has to happen here. Example: https://stackoverflow.com/a/40313917/5511129

  3. The Bind action (act -b) should mount the workspace dir to the docker volume. You can totally use the windows path in the docker command for making the volume and/or the binding. Example: https://stackoverflow.com/a/57553028/5511129

Your WIP seems to be trying to translate the windows path into the WSL /mnt/c/etc. path and that should not be necessary. I’ll attempt a PR of the above if I have some time today.

@catthehacker I basically have this method now to translate the paths. I was going to put it on Input however I think it would make more sense either on Config or RunContext but then I’d either have to import input for the initial absolute path resolution or just duplicate it to avoid the dependency, do you have a preference or recommendation?

// Resolves the equivalent path in the container
// This is required for windows and WSL 2 to translate things like C:\Users\Myproject to /mnt/c/Users/Myproject
// For use in docker volumes and binds
func (i *Input) ResolveContainerPath(path string) string {
	var rpath = i.resolve(path) //extends existing resolve
	if rpath == "" {
		return rpath
	}

	//Test if the path is a windows path
	windowsPathRegex := regexp.MustCompile(`^([a-zA-Z]):\\(.+)$`)
	windowsPathComponents := windowsPathRegex.FindStringSubmatch(rpath)

	//Return as-is if no match
	if windowsPathComponents == nil {
		return rpath
	}

	//Convert to WSL2-compatible path
	//NOTE: Cannot use filepath because this runs on Windows and we need linux paths
	driveLetter := strings.ToLower(windowsPathComponents[1])
	translatedPath := strings.ReplaceAll(windowsPathComponents[2], `\`, `/`)
	// Should make something like /mnt/c/Users/person/My Folder/MyActProject
	result := filepath.Join("/mnt", driveLetter, translatedPath, `/`)
	return result
}

Work in progress: https://github.com/catthehacker/act-fork/tree/windows-fix

cat  ~\githubactions git: master ↓3
❯❯❯ act -j build -W .\.github\workflows\test.yml -v
time="2021-03-29T21:56:15+02:00" level=debug msg="Loading environment from C:\\Users\\cat\\githubactions\\.env"
time="2021-03-29T21:56:15+02:00" level=debug msg="Loading secrets from C:\\Users\\cat\\githubactions\\.secrets"
time="2021-03-29T21:56:15+02:00" level=debug msg="Loading workflow 'C:\\Users\\cat\\githubactions\\.github\\workflows\\test.yml'"
time="2021-03-29T21:56:15+02:00" level=debug msg="Reading workflow 'C:\\Users\\cat\\githubactions\\.github\\workflows\\test.yml'"
time="2021-03-29T21:56:15+02:00" level=debug msg="Planning job: build"
time="2021-03-29T21:56:15+02:00" level=debug msg="Loading slug from git directory 'C:\\Users\\cat\\githubactions\\.git'"
time="2021-03-29T21:56:15+02:00" level=debug msg="Found revision: 2cccdeba5c75811a18f55ce9609eb7015c0e36ec\n"
time="2021-03-29T21:56:15+02:00" level=debug msg="Loading revision from git directory 'C:\\Users\\cat\\githubactions\\.git'"
time="2021-03-29T21:56:15+02:00" level=debug msg="Found revision: 2cccdeba5c75811a18f55ce9609eb7015c0e36ec\n"
time="2021-03-29T21:56:15+02:00" level=debug msg="HEAD points to '2cccdeba5c75811a18f55ce9609eb7015c0e36ec'"
time="2021-03-29T21:56:15+02:00" level=debug msg="HEAD matches refs/heads/master"
time="2021-03-29T21:56:15+02:00" level=debug msg="using github ref: refs/heads/master"
time="2021-03-29T21:56:15+02:00" level=debug msg="context env => map[ACT:true ImageOS:ubuntu18 MY_2ND_ENV_VAR:my 2nd env var value MY_ENV_VAR:MY_ENV_VAR_VALUE]"
[test.yml/build] 🚀  Start image=catthehacker/ubuntu:act-latest
[test.yml/build] 🚀  Workdir=C:\Users\cat\githubactions
[test.yml/build] 🚀  Split=[C \Users\cat\githubactions]
[test.yml/build] 🚀  Workdir=/mnt/c/Users/cat/githubactions
time="2021-03-29T21:56:15+02:00" level=warning msg="unable to get git repo: CreateFile C:\\mnt\\c\\Users\\cat\\githubactions: The system cannot find the path specified."
time="2021-03-29T21:56:15+02:00" level=warning msg="unable to get git revision: CreateFile C:\\mnt\\c\\Users\\cat\\githubactions: The system cannot find the path specified."
time="2021-03-29T21:56:15+02:00" level=warning msg="unable to get git ref: CreateFile C:\\mnt\\c\\Users\\cat\\githubactions: The system cannot find the path specified."
[test.yml/build]   🐳  docker pull catthehacker/ubuntu:act-latest
time="2021-03-29T21:56:15+02:00" level=debug msg="Image exists? true"
[test.yml/build] Removed container: f35e4f82297cc50f1753c6a3a6893946fa685372f95eadb413a34f0187eacc5a
[test.yml/build]   🐳  docker volume rm act-test-yml-build
[test.yml/build]   🐳  docker create image=catthehacker/ubuntu:act-latest platform=linux/amd64 entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[test.yml/build] Created container name=act-test-yml-build id=fa58ad1905b72b05addae0b9f4e9f3a27ad6c2bc12bc97e218667a7e595eb68a from image catthehacker/ubuntu:act-latest (platform: linux/amd64)
[test.yml/build] ENV ==> [RUNNER_TOOL_CACHE=/opt/hostedtoolcache RUNNER_OS=Linux RUNNER_TEMP=/tmp]
[test.yml/build]   🐳  docker run image=catthehacker/ubuntu:act-latest platform=linux/amd64 entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[test.yml/build] Starting container: fa58ad1905b72b05addae0b9f4e9f3a27ad6c2bc12bc97e218667a7e595eb68a
[test.yml/build] Started container: fa58ad1905b72b05addae0b9f4e9f3a27ad6c2bc12bc97e218667a7e595eb68a
[test.yml/build]   🐳  docker cp src=/mnt/c/Users/cat/githubactions\. dst=\mnt\c\Users\cat\githubactions
[test.yml/build] Exec command '[mkdir -p /mnt/c/Users/cat/githubactions]'
time="2021-03-29T21:56:16+02:00" level=debug msg="Writing tarball C:\\Users\\cat\\AppData\\Local\\Temp\\act243004607 from /mnt/c/Users/cat/githubactions\\."
time="2021-03-29T21:56:16+02:00" level=debug msg="Stripping prefix:\\mnt\\c\\Users\\cat\\githubactions\\ src:/mnt/c/Users/cat/githubactions\\."
time="2021-03-29T21:56:16+02:00" level=debug msg="Error loading .gitignore: open \\mnt\\c\\Users\\cat\\githubactions: The system cannot find the path specified."
time="2021-03-29T21:56:16+02:00" level=debug msg="CreateFile /mnt/c/Users/cat/githubactions\\.: The system cannot find the path specified."
time="2021-03-29T21:56:16+02:00" level=debug msg="CreateFile /mnt/c/Users/cat/githubactions\\.: The system cannot find the path specified."
time="2021-03-29T21:56:16+02:00" level=debug msg="CreateFile /mnt/c/Users/cat/githubactions\\.: The system cannot find the path specified."
time="2021-03-29T21:56:16+02:00" level=debug msg="CreateFile /mnt/c/Users/cat/githubactions\\.: The system cannot find the path specified."
Error: CreateFile /mnt/c/Users/cat/githubactions\.: The system cannot find the path specified.
cat  ~\githubactions git: master ↓3
❯❯❯

@jsoref no the latest release introduced a regression due to the pathing of the exec commands in docker not being interpreted properly.