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

tk tool importers: Handle deleted files #872

Merged
merged 2 commits into from
Jul 5, 2023

Conversation

julienduchesne
Copy link
Member

One of the issues we are facing with this command is whenever someone deletes a file and it's still being used somewhere:

  • We can't pass this file to the importers command because it will fail trying to find symlinks
  • Jsonnet main files which are using this file will not be found
  • We end up with erroring projects that are only found out the next time they are evaluated

This PR adds support for deleted files via a deleted: prefix that can be added to files that were deleted. In that case, a simple filepath.Abs logic is used instead of trying to find symlinks and the same import resolution process happens as with existing files

Ex:

tk tool importers deleted:lib/external-secrets/main.libsonnet

@github-actions
Copy link

github-actions bot commented Jun 1, 2023

PR Preview Action v1.4.4
Preview removed because the pull request was closed.
2023-07-05 19:54 UTC

@julienduchesne julienduchesne requested a review from a team June 2, 2023 12:03
@julienduchesne julienduchesne marked this pull request as ready for review June 2, 2023 12:03
@julienduchesne julienduchesne force-pushed the julienduchesne/tool-importers-deleted-files branch 2 times, most recently from 8c33773 to 20bac77 Compare June 26, 2023 14:03
One of the issues we are facing with this command is whenever someone deletes a file and it's still being used somewhere:
- We can't pass this file to the `importers` command because it will fail trying to find symlinks
- Jsonnet main files which are using this file will not be found
- We end up with erroring projects that are only found out the next time they are evaluated

This PR adds support for deleted files via a `deleted:` prefix that can be added to files that were deleted. In that case, a simple filepath.Abs logic is used instead of trying to find symlinks and the same import resolution process happens as with existing files

Ex:
```console
tk tool importers deleted:lib/external-secrets/main.libsonnet
```
@julienduchesne julienduchesne force-pushed the julienduchesne/tool-importers-deleted-files branch from 20bac77 to dcf9018 Compare June 27, 2023 18:44
pkg/jsonnet/find_importers.go Outdated Show resolved Hide resolved
@@ -154,6 +208,11 @@ func TestFindImportersForFiles(t *testing.T) {
require.NoError(t, err)
require.NotEmpty(t, files)
for _, file := range files {
// This project is known to be invalid (as the name suggests)
if strings.Contains(file, "using-deleted-stuff") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be part of findImportersTestCase? That way you can have next to the test information if you should skip here or rather, expect an error or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, I don't think so. It's a sanity check. The command to find importers does not eval jsonnet (because that would be too expensive), and for that that reason, it does not necessarily throw errors on invalid jsonnet (it's not its purpose). So this eval is there to check that the test cases are actually valid

@julienduchesne julienduchesne requested a review from a team July 5, 2023 19:42
Copy link
Contributor

@jvrplmlmn jvrplmlmn left a comment

Choose a reason for hiding this comment

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

👍

@julienduchesne julienduchesne merged commit e0bb1eb into main Jul 5, 2023
@julienduchesne julienduchesne deleted the julienduchesne/tool-importers-deleted-files branch July 5, 2023 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants