Class: ProductTaxonomy::ReleaseAssetPublisher
- Inherits:
-
Object
- Object
- ProductTaxonomy::ReleaseAssetPublisher
- Defined in:
- lib/product_taxonomy/release_asset_publisher.rb
Defined Under Namespace
Classes: ExistingAssetsError
Instance Method Summary collapse
-
#initialize(command_executor:) ⇒ ReleaseAssetPublisher
constructor
A new instance of ReleaseAssetPublisher.
- #publish!(repository_root:, tag:, staged_files:, retry_command:) ⇒ Object
- #validate!(repository_root:, tag:, staged_files:) ⇒ Object
Constructor Details
#initialize(command_executor:) ⇒ ReleaseAssetPublisher
Returns a new instance of ReleaseAssetPublisher.
7 8 9 |
# File 'lib/product_taxonomy/release_asset_publisher.rb', line 7 def initialize(command_executor:) @command_executor = command_executor end |
Instance Method Details
#publish!(repository_root:, tag:, staged_files:, retry_command:) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/product_taxonomy/release_asset_publisher.rb', line 33 def publish!(repository_root:, tag:, staged_files:, retry_command:) validate!(repository_root:, tag:, staged_files:) begin @command_executor.run!( "gh", "release", "upload", tag, *staged_files, chdir: repository_root, failure_message: "Asset upload failed for GitHub release #{tag}.", ) verify!(repository_root:, tag:, staged_files:) rescue StandardError => error raise "#{error.}\n\n#{partial_upload_retry_instructions(tag, retry_command)}" end end |
#validate!(repository_root:, tag:, staged_files:) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/product_taxonomy/release_asset_publisher.rb', line 11 def validate!(repository_root:, tag:, staged_files:) existing_asset_output = @command_executor.run!( "gh", "release", "view", tag, "--json", "assets", "--jq", ".assets[].name", chdir: repository_root, failure_message: "Could not inspect existing assets on GitHub release #{tag}.", ) existing_asset_names = names_from(existing_asset_output) conflicting_asset_names = expected_names(staged_files) & existing_asset_names return if conflicting_asset_names.empty? raise ExistingAssetsError, "GitHub release #{tag} already contains expected assets: #{conflicting_asset_names.join(", ")}. " \ "Refusing to overwrite existing assets." end |