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

Check if an import path is valid when it's a local path #3592

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

idodod
Copy link
Contributor

@idodod idodod commented Dec 12, 2023

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.

@idodod idodod requested a review from a team as a code owner December 12, 2023 17:29
@@ -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"},
Copy link
Contributor Author

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.

Copy link
Contributor Author

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
}
Copy link
Member

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.

Copy link
Contributor Author

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)

Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

@idodod
Copy link
Contributor Author

idodod commented Dec 13, 2023

This actually requires some more work to account for the path of the target's Earthfile that is being executed

@idodod idodod marked this pull request as draft December 14, 2023 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

None yet

2 participants