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

Add bin/packs lint_deprecated_references command #55

Merged
merged 5 commits into from
Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
callback invocation
  • Loading branch information
Alex Evanczuk committed Nov 17, 2022
commit d2a5c2b52763e6123f0754696d1b0bb268b66b83
1 change: 1 addition & 0 deletions lib/use_packwerk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def self.lint_deprecated_references!
OUTPUT

puts output
UsePackwerk.config.on_deprecated_references_lint_failure.call(output)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

At Gusto, we can configure this like this:

--- /dev/null
+++ b/config/use_packwerk.rb
@@ -0,0 +1,7 @@
+require 'gusto_packwerk'
+
+module GustoPackwerk
+  UsePackwerk.configure do |config|
+    config.on_deprecated_references_lint_failure = -> (output) { Private.post_buildkite_annotation(output) }
+  end
+end

I don't love this exactly... some alternative ideas were to have this method return a Result type with the output, and we could just do whatever we want with that result. However, I liked the idea that we can use the vanilla bin stub (bin/packs lint_deprecated_references) without needing to orchestrate anything else.


exit 1
end
Expand Down
8 changes: 8 additions & 0 deletions lib/use_packwerk/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,18 @@ class Configuration
sig { returns(UserEventLogger) }
attr_accessor :user_event_logger

OnDeprecatedReferencesLintFailure = T.type_alias do
T.proc.params(output: String).void
end

sig { returns(OnDeprecatedReferencesLintFailure) }
attr_accessor :on_deprecated_references_lint_failure

sig { void }
def initialize
@enforce_dependencies = T.let(default_enforce_dependencies, T::Boolean)
@user_event_logger = T.let(DefaultUserEventLogger.new, UserEventLogger)
@on_deprecated_references_lint_failure = T.let(-> (output) {}, OnDeprecatedReferencesLintFailure)
end

sig { returns(T::Boolean) }
Expand Down
5 changes: 5 additions & 0 deletions spec/use_packwerk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,10 @@ def expect_files_to_not_exist(files)

context 'some formatting changes after running update-deprecations' do
it 'exits in a failure' do
callback_invocation = false
UsePackwerk.configure do |config|
config.on_deprecated_references_lint_failure = -> (output) { callback_invocation = output }
end
write_file('packs/my_pack/package.yml', <<~CONTENTS)
enforce_privacy: true
enforce_dependnecy: true
Expand Down Expand Up @@ -1416,6 +1420,7 @@ def expect_files_to_not_exist(files)

expect(UsePackwerk).to receive(:exit).with(1)
UsePackwerk.lint_deprecated_references!
expect(callback_invocation).to include('All `deprecated_references.yml` files must be up-to-date')
end
end
end
Expand Down