Skip to content

Commit 91d68e0

Browse files
committed
Support sketch paths outside of workspace
Some code that is used to provide user-friendly paths relative to the root of the repository, rather than unfamiliar absolute paths that expose the full folder structure of the docker container in log messages was written under the assumption that the paths provided by the user to the sketch-paths input will always be within the repository (GITHUB_WORKSPACE). The user may wish to compile example sketches of installed libraries, which are located outside GITHUB_WORKSPACE. Previously, this would result in a workflow failure: ValueError: '/github/home/Arduino/libraries/FooLibrary/examples/Bar' does not start with '/github/workspace'
1 parent 8332993 commit 91d68e0

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

compilesketches/compilesketches.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,8 +1047,14 @@ def path_relative_to_workspace(path):
10471047
Keyword arguments:
10481048
path -- the path to make relative
10491049
"""
1050-
path = pathlib.PurePath(path)
1051-
return path.relative_to(os.environ["GITHUB_WORKSPACE"])
1050+
path = pathlib.Path(path)
1051+
try:
1052+
relative_path = path.relative_to(os.environ["GITHUB_WORKSPACE"])
1053+
except ValueError:
1054+
# Path is outside workspace, so just use the given path
1055+
relative_path = path
1056+
1057+
return relative_path
10521058

10531059

10541060
def absolute_path(path):

compilesketches/tests/test_compilesketches.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,8 @@ def test_path_relative_to_workspace(monkeypatch):
15061506
assert compilesketches.path_relative_to_workspace(path=pathlib.PurePath("/fooWorkspace", "baz")
15071507
) == pathlib.PurePath("baz")
15081508
assert compilesketches.path_relative_to_workspace(path="/fooWorkspace/baz") == pathlib.PurePath("baz")
1509+
# Test path outside workspace
1510+
assert compilesketches.path_relative_to_workspace(path="/bar/foo") == pathlib.PurePath("/bar/foo")
15091511

15101512

15111513
@pytest.mark.parametrize("path, expected_absolute_path", [("/asdf", "/asdf"), ("asdf", "/fooWorkspace/asdf")])

0 commit comments

Comments
 (0)