From 0b0d9a6066c4fc2194b73ad389b306dd186c278e Mon Sep 17 00:00:00 2001 From: Joseph Sweeney Date: Thu, 25 Jan 2024 10:31:22 -0500 Subject: [PATCH 1/3] Add option to retain tmpdir on pr-pull This option will be used to generate build provenance in the `publish-commit-bottles.yml` workflow in `Homebrew/homebrew-core`. It adds a single flag that controls whether or not the temporary directory where bottles are downloaded is retained. --- Library/Homebrew/dev-cmd/pr-pull.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb index 82a60194c7..f0af2df1aa 100644 --- a/Library/Homebrew/dev-cmd/pr-pull.rb +++ b/Library/Homebrew/dev-cmd/pr-pull.rb @@ -43,6 +43,8 @@ module Homebrew switch "--warn-on-upload-failure", description: "Warn instead of raising an error if the bottle upload fails. " \ "Useful for repairing bottle uploads that previously failed." + switch "--retain-bottle-dir", + description: "Does not clean up the tmp directory for the bottle so it can be used later." flag "--committer=", description: "Specify a committer name and email in `git`'s standard author format." flag "--message=", @@ -444,7 +446,8 @@ module Homebrew pr_check_conflicts("#{user}/#{repo}", pr) ohai "Fetching #{tap} pull request ##{pr}" - Dir.mktmpdir pr do |dir| + dir = Dir.mktmpdir pr + begin cd dir do current_branch_head = ENV["GITHUB_SHA"] || tap.git_head original_commit = if args.no_cherry_pick? @@ -501,6 +504,12 @@ module Homebrew upload_args << "--root-url-using=#{args.root_url_using}" if args.root_url_using safe_system HOMEBREW_BREW_FILE, *upload_args end + ensure + if args.retain_bottle_dir? + puts "::set-output name=bottle_path::#{dir}" + else + FileUtils.remove_entry dir + end end end end From a61cb1a4d0ebb33772da52d8f77d6db66c1a8ed7 Mon Sep 17 00:00:00 2001 From: Joe Sweeney Date: Thu, 25 Jan 2024 11:45:20 -0500 Subject: [PATCH 2/3] Set GitHub workflow output correctly Co-authored-by: Bo Anderson --- Library/Homebrew/dev-cmd/pr-pull.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb index f0af2df1aa..92def55855 100644 --- a/Library/Homebrew/dev-cmd/pr-pull.rb +++ b/Library/Homebrew/dev-cmd/pr-pull.rb @@ -506,7 +506,12 @@ module Homebrew end ensure if args.retain_bottle_dir? - puts "::set-output name=bottle_path::#{dir}" + ohai "Bottle files retained at:", dir + return unless ENV["GITHUB_ACTIONS"] + + File.open(ENV.fetch("GITHUB_OUTPUT"), "a") do |f| + f.puts "bottle_path=#{dir}" + end else FileUtils.remove_entry dir end From b261dc77982b3305d29e66948233074bfaec600e Mon Sep 17 00:00:00 2001 From: Joseph Sweeney Date: Thu, 25 Jan 2024 11:50:19 -0500 Subject: [PATCH 3/3] Fix style --- Library/Homebrew/dev-cmd/pr-pull.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb index 92def55855..3ec9abbacb 100644 --- a/Library/Homebrew/dev-cmd/pr-pull.rb +++ b/Library/Homebrew/dev-cmd/pr-pull.rb @@ -505,10 +505,8 @@ module Homebrew safe_system HOMEBREW_BREW_FILE, *upload_args end ensure - if args.retain_bottle_dir? + if args.retain_bottle_dir? && ENV["GITHUB_ACTIONS"] ohai "Bottle files retained at:", dir - return unless ENV["GITHUB_ACTIONS"] - File.open(ENV.fetch("GITHUB_OUTPUT"), "a") do |f| f.puts "bottle_path=#{dir}" end