Skip to content

Add a "tidy" command to find files that might be missing or unneeded.#305

Merged
mipearson merged 3 commits intomasterfrom
mp-stackmaster-tidy
Feb 18, 2020
Merged

Add a "tidy" command to find files that might be missing or unneeded.#305
mipearson merged 3 commits intomasterfrom
mp-stackmaster-tidy

Conversation

@mipearson
Copy link
Copy Markdown
Contributor

Sometimes you delete stacks but don't remove their parameter files or templates.

Sometimes a template is renamed or removed, but stacks still depend on it.

stack_master tidy (I feel like it needs a better name) helps you find these things.

Copy link
Copy Markdown
Contributor

@viraptor viraptor left a comment

Choose a reason for hiding this comment

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

Looks good / useful!

templates = Set.new(find_templates())
parameter_files = Set.new(find_parameter_files())

status = @config.stacks.each do |stack_definition|
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I feel like this could be a separate method like def remove_used(templates, parameter_files) for clarity. (or maybe even one for each?) But that's just nitpicking :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Had a go at this but as it's referencing multiple sets (and has side effects where it prints missing templates) it complicates things a bit. Decided it's not worth it for this length of method.

Comment thread lib/stack_master/commands/tidy.rb Outdated
end
end

def rel_path path
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the rest of the code uses parens around parameters.

parameter_files.each do |path|
StackMaster.stdout.puts "#{rel_path(path)}: no stack found for this parameter file"
end
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we return a non-zero exit code if any of them is not empty? That would be nice for CI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thought about it, but they're mostly indications rather than errors - eg in the data platform repositories, there's multiple stack_master.yml files that share a template directory.

They'll both find "extra" files as some templates are only used by one of the two configs .. but they're exceptions rather than the rule.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if we should have a flag to enable or disable checking for orphaned templates?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe - my intention for this wasn't as a CI pass/fail tool but a convenience one, especially as the method for knowing which directories/files are referenced is not 100% reliable.

Copy link
Copy Markdown
Contributor

@patrobinson patrobinson left a comment

Choose a reason for hiding this comment

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

Approved with comments 👍

parameter_files = Set.new(find_parameter_files())

status = @config.stacks.each do |stack_definition|
parameter_files.subtract(stack_definition.parameter_files)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's ok to have a missing parameter file though right, if the stack takes no parameters or has defaults?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh nevermind,I understand what's going on here now. parameter files - (stacks)

@mipearson mipearson merged commit 323ef22 into master Feb 18, 2020
@mipearson mipearson deleted the mp-stackmaster-tidy branch February 18, 2020 22:27
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.

3 participants