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
Check if an import path is valid when it's a local path #3592
base: main
Are you sure you want to change the base?
Conversation
@@ -120,6 +120,7 @@ func TestAvailableFlags(t *testing.T) { | |||
{"arg-scope-and-set", "ArgScopeSet"}, | |||
{"earthly-ci-runner-arg", "EarthlyCIRunnerArg"}, | |||
{"use-docker-ignore", "UseDockerIgnore"}, | |||
{"use-function-keyword", "UseFunctionKeyword"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated, but forgotten in previous PR.
domain/importtracker_test.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff isn't great here, it might be easier to view commit by commit:
First commit => Add more tests
Second commit => Change existing tests to include a name and run in parallel
return hint.Wrapf(errors.Errorf("path %q does contains an %s which is not a file", path, earthlyFileName), "The local IMPORT path %q contains an %q directory and not a file", path, earthlyFileName) | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work when this is in a remote context? E.g. I call the target github.com/foo/bar+target
and that Earthfile imports ./buz
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question.
So it seems to not have a negative or positive impact.
Some options I tested inside the remote Earthfile:
- If the local IMPORT exists - it works.
- If the local IMPORT is an absolute path - it returns an errors (~ absolute paths are not supported in the context of remote ref)
- if the local import is a relative path that does not exist - returns an error (but not as pretty as this PR tries to make it, because it's checked when the path is resolved)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting... it might be nice to throw an error for that case too. But that could be a separate PR.
return hint.Wrapf(errors.Errorf("path %q does not contain an %s", path, earthlyFileName), "Verify the path %q contains an %s", path, earthlyFileName) | ||
} | ||
if res == dir { | ||
return hint.Wrapf(errors.Errorf("path %q does contains an %s which is not a file", path, earthlyFileName), "The local IMPORT path %q contains an %q directory and not a file", path, earthlyFileName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return hint.Wrapf(errors.Errorf("path %q does contains an %s which is not a file", path, earthlyFileName), "The local IMPORT path %q contains an %q directory and not a file", path, earthlyFileName) | |
return hint.Wrapf(errors.Errorf("path %q contains an %s which is not a file", path, earthlyFileName), "The local IMPORT path %q contains an %q directory and not a file", path, earthlyFileName) |
This actually requires some more work to account for the path of the target's Earthfile that is being executed |
Addresses #3470
When the import path is a local path, check that it's a valid existing path or display a helpful error otherwise.
Also modify existing tests for consistency.