-
-
Notifications
You must be signed in to change notification settings - Fork 15
Add Homebrew cask automation to release workflow #44
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| cask "autopip" do | ||
| version "2.1.0" | ||
| sha256 "1f7a0f647c577b44e51d0ac5e450804369ada9d522d75fe4371855d5e768f01a" | ||
|
|
||
| url "https://github.com/vordenken/AutoPiP/releases/download/v#{version}/AutoPiP.dmg" | ||
| name "AutoPiP" | ||
| desc "Safari extension for automatic Picture-in-Picture video playback" | ||
| homepage "https://github.com/vordenken/AutoPiP" | ||
|
|
||
| livecheck do | ||
| url "https://raw.githubusercontent.com/vordenken/AutoPiP/main/appcast.xml" | ||
| strategy :sparkle do |items| | ||
| items.find { |item| item.channel.nil? }&.short_version | ||
| end | ||
| end | ||
|
|
||
| auto_updates true | ||
| depends_on macos: :ventura | ||
|
|
||
| app "AutoPiP.app" | ||
|
|
||
| preflight_steps do | ||
| run "/usr/bin/xattr", | ||
| args: ["-dr", "com.apple.quarantine", "{{staged_path}}/AutoPiP.app"], | ||
| must_succeed: true | ||
| end | ||
|
sourcery-ai[bot] marked this conversation as resolved.
|
||
|
|
||
| uninstall quit: "com.vd.AutoPiP" | ||
|
|
||
| zap trash: [ | ||
| "~/Library/Application Scripts/com.vd.AutoPiP", | ||
| "~/Library/Application Scripts/com.vd.AutoPiP.Extension", | ||
| "~/Library/Containers/com.vd.AutoPiP", | ||
| "~/Library/Containers/com.vd.AutoPiP.Extension", | ||
| ] | ||
|
|
||
| caveats <<~EOS | ||
| AutoPiP is not notarized. This cask removes its quarantine attribute during | ||
| installation so macOS does not block the first launch. | ||
|
|
||
| Launch AutoPiP once, then enable the extension in Safari Settings > Extensions. | ||
| EOS | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import argparse | ||
| import hashlib | ||
| import os | ||
| import re | ||
| import stat | ||
| import tempfile | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def parse_arguments(): | ||
| parser = argparse.ArgumentParser(description="Update the Homebrew cask release") | ||
| parser.add_argument("--cask", type=Path, required=True) | ||
| parser.add_argument("--version", required=True) | ||
| parser.add_argument("--archive", type=Path, required=True) | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| def archive_sha256(path): | ||
| digest = hashlib.sha256() | ||
| with path.open("rb") as archive: | ||
| for chunk in iter(lambda: archive.read(1024 * 1024), b""): | ||
| digest.update(chunk) | ||
| return digest.hexdigest() | ||
|
|
||
|
|
||
| def update_cask(cask_path, version, archive_path): | ||
| if not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", version): | ||
| raise ValueError(f"Invalid version: {version}") | ||
| if not archive_path.is_file(): | ||
| raise ValueError(f"Archive does not exist: {archive_path}") | ||
|
|
||
| cask = cask_path.read_text(encoding="utf-8") | ||
| checksum = archive_sha256(archive_path) | ||
| cask, version_count = re.subn( | ||
| r'^ version "[^"]+"$', f' version "{version}"', cask, flags=re.M | ||
| ) | ||
| cask, checksum_count = re.subn( | ||
| r'^ sha256 "[0-9a-f]{64}"$', | ||
| f' sha256 "{checksum}"', | ||
| cask, | ||
| flags=re.M, | ||
| ) | ||
| if version_count != 1 or checksum_count != 1: | ||
| raise ValueError("Cask must contain exactly one version and SHA-256 stanza") | ||
|
sourcery-ai[bot] marked this conversation as resolved.
|
||
|
|
||
| mode = stat.S_IMODE(cask_path.stat().st_mode) | ||
| temporary_path = None | ||
| try: | ||
| with tempfile.NamedTemporaryFile( | ||
| mode="w", | ||
| encoding="utf-8", | ||
| dir=cask_path.parent, | ||
| delete=False, | ||
| prefix="autopip-cask-", | ||
| ) as temporary_file: | ||
| temporary_file.write(cask) | ||
| temporary_path = Path(temporary_file.name) | ||
| os.chmod(temporary_path, mode) | ||
| os.replace(temporary_path, cask_path) | ||
| finally: | ||
| if temporary_path is not None and temporary_path.exists(): | ||
| temporary_path.unlink() | ||
|
|
||
|
|
||
| def main(): | ||
| args = parse_arguments() | ||
| update_cask(args.cask, args.version, args.archive) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Homebrew does not recognize
preflight_stepsas a cask stanza, sobrew style/cask loading fails before installation and the cask cannot be installed.Suggested fix: Use Homebrew's supported
preflight dostanza and invoke the command with the supportedsystem_commandAPI.