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

github_packages: support --keep-old #11093

Merged
merged 1 commit into from Apr 9, 2021
Merged

Conversation

Bo98
Copy link
Member

@Bo98 Bo98 commented Apr 9, 2021

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

We need this to support any sort of workflow for adding bottles to an existing tag, including brew dispatch-build-bottle.

@BrewTestBot
Copy link
Member

Review period will end on 2021-04-12 at 15:41:15 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Apr 9, 2021
MikeMcQuaid
MikeMcQuaid previously approved these changes Apr 9, 2021
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Great work 👏🏻

@MikeMcQuaid MikeMcQuaid added the critical Critical change which should be shipped as soon as possible. label Apr 9, 2021
@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Apr 9, 2021
@BrewTestBot
Copy link
Member

Review period skipped due to critical label.

BrewTestBot
BrewTestBot previously approved these changes Apr 9, 2021
@dawidd6
Copy link
Member

dawidd6 commented Apr 9, 2021

Are you sure this won't break workflows in linuxbrew-core?

@Bo98
Copy link
Member Author

Bo98 commented Apr 9, 2021

What does linuxbrew-core do here? Use --keep-old on a non-existent package tag?

BrewTestBot
BrewTestBot previously approved these changes Apr 9, 2021
@dawidd6
Copy link
Member

dawidd6 commented Apr 9, 2021

Yes, I think that's what happens.

@Bo98
Copy link
Member Author

Bo98 commented Apr 9, 2021

I could do this so that it ignores --keep-old if a tag doesn't exist?

diff --git a/Library/Homebrew/github_packages.rb b/Library/Homebrew/github_packages.rb
index ad8839ca2..deb576d26 100644
--- a/Library/Homebrew/github_packages.rb
+++ b/Library/Homebrew/github_packages.rb
@@ -226,21 +226,22 @@ class GitHubPackages
     image_tag = GitHubPackages.image_version_rebuild(version_rebuild)
     image_uri = "#{GitHubPackages.root_url(org, repo, DOCKER_PREFIX)}/#{image_name}:#{image_tag}"
 
-    unless keep_old
-      puts
-      inspect_args = ["inspect", image_uri.to_s]
-      if dry_run
-        puts "#{skopeo} #{inspect_args.join(" ")} --creds=#{user}:$HOMEBREW_GITHUB_PACKAGES_TOKEN"
-      else
-        inspect_args << "--creds=#{user}:#{token}"
-        inspect_result = system_command(skopeo, print_stderr: false, args: inspect_args)
-        if inspect_result.status.success?
-          if warn_on_error
-            opoo "#{image_uri} already exists, skipping upload!"
-            return
-          else
-            odie "#{image_uri} already exists!"
-          end
+    puts
+    inspect_args = ["inspect", image_uri.to_s]
+    if dry_run
+      puts "#{skopeo} #{inspect_args.join(" ")} --creds=#{user}:$HOMEBREW_GITHUB_PACKAGES_TOKEN"
+    else
+      inspect_args << "--creds=#{user}:#{token}"
+      inspect_result = system_command(skopeo, print_stderr: false, args: inspect_args)
+      if keep_old
+        # Tag doesn't exist so ignore --keep-old
+        keep_old = false unless inspect_result.status.success?
+      elsif inspect_result.status.success?
+        if warn_on_error
+          opoo "#{image_uri} already exists, skipping upload!"
+          return
+        else
+          odie "#{image_uri} already exists!"
         end
       end
     end

@dawidd6
Copy link
Member

dawidd6 commented Apr 9, 2021

Guess that will do.

@MikeMcQuaid
Copy link
Member

@Bo98 that works for me too 👍🏻

MikeMcQuaid
MikeMcQuaid previously approved these changes Apr 9, 2021
BrewTestBot
BrewTestBot previously approved these changes Apr 9, 2021
MikeMcQuaid
MikeMcQuaid previously approved these changes Apr 9, 2021
puts
args = ["copy", "--all", image_uri.to_s, "oci:#{root}"]
if dry_run
puts "#{skopeo} #{args.join(" ")} --src-creds=#{user}:$HOMEBREW_GITHUB_PACKAGES_TOKEN"
Copy link
Member

Choose a reason for hiding this comment

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

Not saying we should but: could moving this skopeo with or without dry run logic into a method (as it's used three times now)

Copy link
Member Author

@Bo98 Bo98 Apr 9, 2021

Choose a reason for hiding this comment

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

The different args, even ones like print_stderr, make it a bit tricky.

Copy link
Member

Choose a reason for hiding this comment

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

Fine with me 👍🏻

@Bo98
Copy link
Member Author

Bo98 commented Apr 9, 2021

Added code to odie when a duplicate manifest is detected.

BrewTestBot
BrewTestBot previously approved these changes Apr 9, 2021
@Bo98 Bo98 merged commit 1f3be6f into Homebrew:master Apr 9, 2021
@Bo98 Bo98 deleted the ghp-keep-old branch April 9, 2021 18:52
@github-actions github-actions bot added the outdated PR was locked due to age label May 10, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
critical Critical change which should be shipped as soon as possible. outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants