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

pr-upload: Upload bottles to the Internet Archive #10677

Merged
merged 8 commits into from
Feb 24, 2021

Conversation

sjackman
Copy link
Member

@sjackman sjackman commented Feb 23, 2021

--archive-item=… specifies the item identifier.
HOMEBREW_INTERNET_ARCHIVE_KEY=access:secret specifies the S3-like key. See https://archive.org/account/s3.php

  • 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?
  • Have you successfully run brew man locally and committed any changes?

--archive-item specifies the item identifier.
HOMEBREW_ARCHIVE_KEY=access:secret specifies the S3 key.
@sjackman sjackman self-assigned this Feb 23, 2021
@BrewTestBot
Copy link
Member

Review period will end on 2021-02-24 at 01:26:35 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Feb 23, 2021
@jonchang
Copy link
Contributor

Multiple cloud storage services support an S3-like API, including Amazon itself. Would it perhaps make more sense to have a utils/s3 that implements the needed APIs, then (if necessary) have utils/s3/archive to subclass/override the bits that are specific to e.g. the internet archive?

@sjackman
Copy link
Member Author

This implementation could pretty easily be adapted to a true S3 implementation like Amazon S3, but in its current form will not work out-of-the-box. I personally have no immediate use case for uploading bottles to Amazon S3, so I'm going to pass on doing this implementation myself.

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.

Looking good so far, nice work!

require "digest/md5"
require "utils/curl"

# Archive API client.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# Archive API client.
# The Internet Archive API client.


raise UsageError, "Must set the Archive item!" unless @archive_item

ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] = "1" if @archive_item == "homebrew" && !OS.mac?
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment explaining this?

Copy link
Member Author

Choose a reason for hiding this comment

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

This line is here on the foundational software engineering principles of cargo cult engineering and Chesterton's Fence, cribbed from

ENV["HOMEBREW_FORCE_HOMEBREW_ON_LINUX"] = "1" if @bintray_org == "homebrew" && !OS.mac?

I'm not sure of its purpose, so I sadly cannot comment it. I'm happy deleting this line, and we can add it back if we find that we need it.

Copy link
Member Author

Choose a reason for hiding this comment

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

If I were to guess, it was a hack for uploading and verifying (more likely the verifying step) macOS bottles running on a Linux CI runner.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've deleted this line. We can crib it from bintray.rb if needed.

warn_on_error: T.nilable(T::Boolean)).void
}
def upload(local_file, directory:, remote_file:, warn_on_error: false)
unless File.exist? local_file
Copy link
Member

Choose a reason for hiding this comment

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

Make local_file a Pathname and then you can use local_file.exist? here and local_file.read below.


sig { returns(String) }
def inspect
"#<Archive: item=#{@archive_item}>"
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to get some tests for this class.


sig { params(url: String).returns(T::Boolean) }
def stable_mirrored?(url)
headers, = curl_output("--connect-timeout", "15", "--location", "--head", url)
Copy link
Member

Choose a reason for hiding this comment

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

Why 15? Would be good to have a comment or shared constant if this is copied from elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

🤷‍♂️ Cribbed from bintray.rb

Copy link
Member Author

@sjackman sjackman Feb 23, 2021

Choose a reason for hiding this comment

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

Deleted this method stable_mirrored?

directory = bottle_hash["bintray"]["repository"]
bottle_count = bottle_hash["bottle"]["tags"].length

bottle_hash["bottle"]["tags"].each do |_tag, tag_hash|
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bottle_hash["bottle"]["tags"].each do |_tag, tag_hash|
bottle_hash["bottle"]["tags"].each_value do |tag_hash|

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch. Rubocop should have an audit for this case.

@@ -49,6 +49,8 @@ def pr_pull_args
description: "Message to include when autosquashing revision bumps, deletions, and rebuilds."
flag "--artifact=",
description: "Download artifacts with the specified name (default: `bottles`)."
flag "--archive-item=",
description: "Upload to the specified Archive item (default: `homebrew`)."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
description: "Upload to the specified Archive item (default: `homebrew`)."
description: "Upload to the specified Internet Archive item (default: `homebrew`)."

@@ -27,6 +28,8 @@ def pr_upload_args
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."
flag "--archive-item=",
description: "Upload to the specified Archive item (default: `homebrew`)."
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
description: "Upload to the specified Archive item (default: `homebrew`)."
description: "Upload to the specified Internet Archive item (default: `homebrew`)."

@@ -15,6 +15,10 @@ module EnvConfig
description: "Linux only: Pass this value to a type name representing the compiler's `-march` option.",
default: "native",
},
HOMEBREW_ARCHIVE_KEY: {
description: "Use this API key when accessing the Archive.org API (where bottles are stored). " \
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
description: "Use this API key when accessing the Archive.org API (where bottles are stored). " \
description: "Use this API key when accessing the Internet Archive API (where bottles are stored). " \

@@ -15,6 +15,10 @@ module EnvConfig
description: "Linux only: Pass this value to a type name representing the compiler's `-march` option.",
default: "native",
},
HOMEBREW_ARCHIVE_KEY: {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
HOMEBREW_ARCHIVE_KEY: {
HOMEBREW_INTERNET_ARCHIVE_KEY: {

@sjackman sjackman changed the title pr-upload: Upload bottles to Archive.org pr-upload: Upload bottles to the Internet Archive Feb 23, 2021
@BrewTestBot
Copy link
Member

Review period ended.

@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Feb 24, 2021
@sjackman sjackman merged commit bd75cfc into Homebrew:master Feb 24, 2021
@sjackman sjackman deleted the sj/pr-upload branch February 24, 2021 20:15
@sjackman
Copy link
Member Author

BrewTestBot approved my PR, and it automerged. That wasn't exactly intentional, but I'm happy with this PR. Happy to follow up with another PR if tweaks are needed.

@MikeMcQuaid
Copy link
Member

@sjackman pulling out some constants and adding any tests would be nice if possible!

@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Mar 28, 2021
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Mar 28, 2021
@MikeMcQuaid MikeMcQuaid removed the outdated PR was locked due to age label Jun 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants