Skip to content

Commit

Permalink
Add comment about ordering of architectures, remove unnecessary metho…
Browse files Browse the repository at this point in the history
…d call
  • Loading branch information
Nishnha committed Mar 25, 2022
1 parent db9bf82 commit a8aeac1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions terraform/lib/dependabot/terraform/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def lookup_hash_architecture
split("\n").map { |hash| hash.match(hashes_string_regex).to_s }.
select { |h| h&.match?(/^h1:/) }

# These are ordered in assumed popularity
# We try to exit early if we have detected all of the hashes
architectures = %w(
linux_amd64
darwin_amd64
Expand All @@ -140,7 +142,7 @@ def lookup_hash_architecture
updated_dependency = updated_lockfile.scan(declaration_regex).first

updated_hashes = updated_dependency.match(hashes_object_regex).to_s.
split("\n").map { |hash| hash.match(hashes_string_regex).to_s }.
split("\n").map { |hash| hash.match(hashes_string_regex).to_s }.
select { |a| a&.match?(/^h1:/) }

architecture_hashes[arch.to_sym] = updated_hashes unless updated_hashes.nil?
Expand Down Expand Up @@ -193,16 +195,14 @@ def update_lockfile_declaration(updated_manifest_files) # rubocop:disable Metric
declaration_regex = lockfile_declaration_regex(provider_source)
lockfile_dependency_removed = content.sub(declaration_regex, "")

architecture = architecture_type

base_dir = dependency_files.first.directory
SharedHelpers.in_a_temporary_repo_directory(base_dir, repo_contents_path) do
# Update the provider requirements in case the previous requirement doesn't allow the new version
updated_manifest_files.each { |f| File.write(f.name, f.content) }

File.write(".terraform.lock.hcl", lockfile_dependency_removed)

platforms = architecture.map { |arch| "-platform=#{arch}" }.join(" ")
platforms = architecture_type.map { |arch| "-platform=#{arch}" }.join(" ")
SharedHelpers.run_shell_command("terraform providers lock #{platforms} #{provider_source} -no-color")

updated_lockfile = File.read(".terraform.lock.hcl")
Expand Down
1 change: 1 addition & 0 deletions terraform/spec/dependabot/terraform/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,7 @@ module "consul" {
)
end
end

context "when using a lockfile that requires access to an unreachable module" do
let(:project_name) { "lockfile_unreachable_module" }
let(:dependencies) do
Expand Down

0 comments on commit a8aeac1

Please sign in to comment.