Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ jobs:
sudo xcode-select -s "$XCODE"
xcodebuild -version

# The release workflow renders the Homebrew casks with this script
- name: Test release scripts
run: python3 -m unittest discover -s scripts -p 'test_*.py' -v

- name: Build
run: >
xcodebuild -scheme "Focusrite Volume Control" -configuration Debug
Expand Down
79 changes: 52 additions & 27 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,24 @@ jobs:
xcodebuild -version

# Sparkle compares CFBundleVersion, so stamp both version keys from the tag.
# A hyphen marks a prerelease (v1.6.0-beta.1): a GitHub prerelease for testers,
# with no Homebrew tap update and no Sparkle appcast entry.
# A hyphen marks a beta (v1.6.0-beta.2): a GitHub prerelease that updates only the
# focusrite-volume-control@beta cask and skips the Sparkle appcast.
- name: Read version from tag
id: version
run: |
VERSION="${GITHUB_REF_NAME#v}"
# Fail here rather than after the GitHub release exists
if ! [[ "$VERSION" =~ ^[0-9]+(\.[0-9]+)*(-[0-9A-Za-z]+(\.[0-9A-Za-z]+)*)?$ ]]; then
echo "::error::Tag $GITHUB_REF_NAME isn't vX.Y.Z or vX.Y.Z-beta.N"
exit 1
fi
# Bundle versions must be dot-separated numbers, so drop the prerelease suffix there
BUNDLE_VERSION="${VERSION%%-*}"
echo "VERSION=$VERSION" >> "$GITHUB_ENV"
echo "BUNDLE_VERSION=$BUNDLE_VERSION" >> "$GITHUB_ENV"
if [[ "$VERSION" == *-* ]]; then
echo "prerelease=true" >> "$GITHUB_OUTPUT"
echo "::notice title=Prerelease::$GITHUB_REF_NAME is a prerelease: no Homebrew tap update, no Sparkle appcast entry"
echo "::notice title=Beta::$GITHUB_REF_NAME is a beta: GitHub prerelease, @beta cask only, no Sparkle appcast entry"
else
echo "prerelease=false" >> "$GITHUB_OUTPUT"
fi
Expand Down Expand Up @@ -203,31 +208,44 @@ jobs:
SIGNED: ${{ steps.signing.outputs.enabled }}
PRERELEASE: ${{ steps.version.outputs.prerelease }}
DMG_SHA256: ${{ steps.sha.outputs.sha256 }}
# Every release page offers both Homebrew and the DMG; betas point at the @beta cask
run: |
if [ "$PRERELEASE" = "true" ]; then
CASK="focusrite-volume-control@beta"
else
CASK="focusrite-volume-control"
fi
{
if [ "$PRERELEASE" = "true" ]; then
echo '**Test build for hardware testing.** Homebrew and in-app updates do not offer it.'
echo "**Beta.** A test build ahead of the next stable release. Regular Homebrew installs and in-app updates stay on the current stable version."
echo
echo '1. Download `VolumeControl.dmg` and drag **Volume Control** to Applications.'
if [ "$SIGNED" != "true" ]; then
echo '2. This build is not signed or notarized. On first launch, right-click the app and choose **Open**, or run:'
echo ' `xattr -dr com.apple.quarantine "/Applications/Volume Control.app"`'
else
echo '2. This build is signed and notarized; open it normally.'
fi
echo '3. Grant the **Accessibility** permission when prompted (System Settings → Privacy & Security → Accessibility).'
echo '4. **Focusrite Control 2** must be installed and running.'
echo
echo "Please report results in [Issues](https://github.com/${GITHUB_REPOSITORY}/issues) with your interface model and FC2 version."
fi
echo '## Install'
echo
echo '**Homebrew**'
echo
echo '```bash'
echo "brew install --cask enum-dot-dev/focusrite-volume-control/$CASK"
echo '```'
echo
if [ "$PRERELEASE" = "true" ]; then
echo 'On the regular cask? Run `brew uninstall --cask focusrite-volume-control` first, since both install the same app. The beta cask also gets every stable release, so you can stay on it.'
else
echo '**Homebrew:**'
echo '```'
echo 'brew install --cask enum-dot-dev/focusrite-volume-control/focusrite-volume-control'
echo '```'
if [ "$SIGNED" != "true" ]; then
echo
echo '> This build is not signed or notarized. On first launch, right-click the app and choose Open.'
fi
echo "Already installed? Run \`brew upgrade --cask $CASK\`."
fi
echo
echo '**DMG**'
echo
echo '1. Download `VolumeControl.dmg` below.'
echo '2. Open it and drag **Volume Control** to Applications.'
if [ "$SIGNED" != "true" ]; then
echo "3. This build isn't signed yet, so macOS blocks the first launch. Right-click the app and choose **Open**. Homebrew installs skip this step."
fi
echo
echo 'Needs [Focusrite Control 2](https://focusrite.com/downloads). Grant the **Accessibility** permission when the app asks on first launch.'
if [ "$PRERELEASE" = "true" ]; then
echo
echo "Found a problem? [Open an issue](https://github.com/${GITHUB_REPOSITORY}/issues) with your interface model and FC2 version."
fi
echo
echo "**DMG SHA256:** \`$DMG_SHA256\`"
Expand Down Expand Up @@ -272,24 +290,31 @@ jobs:
# Pushes made with GITHUB_TOKEN don't trigger workflows, but workflow_dispatch does
gh workflow run pages.yml --ref main

# Every release updates focusrite-volume-control@beta, so beta testers also move on to
# stable releases. Only stable releases update the regular cask.
- name: Update Homebrew tap
if: steps.version.outputs.prerelease != 'true'
env:
GH_TOKEN: ${{ secrets.TAP_GITHUB_TOKEN }}
DMG_SHA256: ${{ steps.sha.outputs.sha256 }}
SIGNED: ${{ steps.signing.outputs.enabled }}
SPARKLE: ${{ steps.sparkle.outputs.enabled }}
PRERELEASE: ${{ steps.version.outputs.prerelease }}
run: |
CASK_FLAGS=()
[ "$SIGNED" = "true" ] || CASK_FLAGS+=(--unsigned)
[ "$SPARKLE" = "true" ] && CASK_FLAGS+=(--auto-updates)
git clone "https://x-access-token:${GH_TOKEN}@github.com/enum-dot-dev/homebrew-focusrite-volume-control.git" tap
python3 scripts/render_cask.py --version "$VERSION" --sha256 "$DMG_SHA256" ${CASK_FLAGS[@]+"${CASK_FLAGS[@]}"} \
homebrew/Casks/focusrite-volume-control.rb tap/Casks/focusrite-volume-control.rb
SRC=homebrew/Casks/focusrite-volume-control.rb
python3 scripts/render_cask.py --version "$VERSION" --sha256 "$DMG_SHA256" --beta \
${CASK_FLAGS[@]+"${CASK_FLAGS[@]}"} "$SRC" "tap/Casks/focusrite-volume-control@beta.rb"
if [ "$PRERELEASE" != "true" ]; then
python3 scripts/render_cask.py --version "$VERSION" --sha256 "$DMG_SHA256" \
${CASK_FLAGS[@]+"${CASK_FLAGS[@]}"} "$SRC" "tap/Casks/focusrite-volume-control.rb"
fi
cd tap
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Casks/focusrite-volume-control.rb
git add Casks/
if ! git diff --cached --quiet; then
git commit -m "bump to v${VERSION}"
git push
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ build/

# IDE
.idea/

# Python
__pycache__/
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ brew install --cask enum-dot-dev/focusrite-volume-control/focusrite-volume-contr

Homebrew 6.0 and later only load casks from third-party taps you've trusted. Installing by the full name, as above, adds the tap and trusts just this cask. If you'd rather tap first and install by the short name, run `brew trust --cask enum-dot-dev/focusrite-volume-control/focusrite-volume-control` before `brew install --cask focusrite-volume-control`.

Want test builds before they ship? Install the beta cask instead. It also gets every stable release, so you can stay on it. Uninstall the regular cask first, since both install the same app.

```bash
brew install --cask enum-dot-dev/focusrite-volume-control/focusrite-volume-control@beta
```

### Manual

Download the latest DMG from [Releases](https://github.com/enum-dot-dev/focusrite-volume-control/releases/latest) and drag to Applications.
Expand Down
12 changes: 7 additions & 5 deletions homebrew/Casks/focusrite-volume-control.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Template: the release workflow renders this with scripts/render_cask.py (version, sha256,
# and a quarantine postflight for unsigned builds) and pushes it to the tap repository.
# The same template also renders focusrite-volume-control@beta (render_cask.py --beta).
cask "focusrite-volume-control" do
version "1.5.1"
sha256 :no_check
Expand All @@ -9,18 +10,19 @@
desc "Control Focusrite Scarlett 4th gen volume with media keys via Focusrite Control 2"
homepage "https://enum.dev/focusrite-volume-control/"

conflicts_with cask: "focusrite-volume-control@beta"
depends_on macos: ">= :sonoma"

app "Volume Control.app"

zap trash: [
"~/Library/Preferences/net.nickmorozov.FocusriteVolumeControl.plist",
"~/Library/Preferences/solutions.enum.FocusriteVolumeControl.plist",
]

caveats <<~EOS
If media keys stop working after an update, reset the accessibility permission:
tccutil reset Accessibility solutions.enum.FocusriteVolumeControl
Then relaunch the app and re-grant the permission when prompted.
EOS

zap trash: [
"~/Library/Preferences/net.nickmorozov.FocusriteVolumeControl.plist",
"~/Library/Preferences/solutions.enum.FocusriteVolumeControl.plist",
]
end
35 changes: 26 additions & 9 deletions scripts/render_cask.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
#!/usr/bin/env python3
"""Render the Homebrew cask for a release from homebrew/Casks/focusrite-volume-control.rb.
"""Render a Homebrew cask for a release from homebrew/Casks/focusrite-volume-control.rb.

The release workflow copies the rendered cask into the tap repository, so this repo's
The release workflow copies the rendered casks into the tap repository, so this repo's
cask stays the single source of truth. Unsigned builds get a postflight that clears
the quarantine attribute, since Gatekeeper blocks un-notarized apps downloaded by brew.

--beta renders focusrite-volume-control@beta instead. Both casks install the same app,
so each one conflicts with the other. Only the beta cask accepts prerelease versions
such as 1.6.0-beta.1.

Usage:
render_cask.py --version 1.6 --sha256 <hex> [--unsigned] [--auto-updates] SRC DEST
render_cask.py --version 1.6.0 --sha256 <hex> [--beta] [--unsigned] [--auto-updates] SRC DEST
"""

import argparse
import re
import sys

STABLE_TOKEN = "focusrite-volume-control"
BETA_TOKEN = f"{STABLE_TOKEN}@beta"

STABLE_VERSION = r"[0-9]+(\.[0-9]+)*"
PRERELEASE_VERSION = STABLE_VERSION + r"(-[0-9A-Za-z]+(\.[0-9A-Za-z]+)*)?"

QUARANTINE_POSTFLIGHT = '''
# Unsigned build: clear quarantine so Gatekeeper doesn't block the app
postflight do
Expand All @@ -22,22 +32,28 @@
'''


def render(source: str, version: str, sha256: str, unsigned: bool, auto_updates: bool) -> str:
if not re.fullmatch(r"[0-9]+(\.[0-9]+)*", version):
raise ValueError(f"unexpected version: {version!r}")
def render(source: str, version: str, sha256: str, unsigned: bool, auto_updates: bool,
beta: bool = False) -> str:
if not re.fullmatch(PRERELEASE_VERSION if beta else STABLE_VERSION, version):
hint = "" if beta else " (prerelease versions go to the beta cask only)"
raise ValueError(f"unexpected version: {version!r}{hint}")
if not re.fullmatch(r"[0-9a-f]{64}", sha256):
raise ValueError(f"unexpected sha256: {sha256!r}")

def sub(pattern: str, replacement: str, text: str) -> str:
def sub(pattern: str, replacement, text: str) -> str:
result, count = re.subn(pattern, replacement, text, count=1, flags=re.MULTILINE)
if count != 1:
raise ValueError(f"pattern not found in cask: {pattern}")
return result

cask = sub(r'^ version ".*"$', f' version "{version}"', source)
cask = sub(r'^ sha256 .*$', f' sha256 "{sha256}"', cask)
if beta:
cask = sub(rf'^cask "{re.escape(STABLE_TOKEN)}" do$', f'cask "{BETA_TOKEN}" do', cask)
cask = sub(r'^ conflicts_with cask: ".*"$', f' conflicts_with cask: "{STABLE_TOKEN}"', cask)
if auto_updates:
cask = sub(r'^( depends_on .*)$', r' auto_updates true\n\1', cask)
# Homebrew's stanza order puts auto_updates before conflicts_with and depends_on
cask = sub(r'^( (?:conflicts_with|depends_on) .*)$', r' auto_updates true\n\1', cask)
if unsigned:
cask = sub(r'^( app ".*")$', lambda m: m.group(1) + "\n" + QUARANTINE_POSTFLIGHT.rstrip("\n"), cask)
return cask
Expand All @@ -47,6 +63,7 @@ def main() -> int:
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("--version", required=True)
parser.add_argument("--sha256", required=True)
parser.add_argument("--beta", action="store_true", help=f"render {BETA_TOKEN} instead of {STABLE_TOKEN}")
parser.add_argument("--unsigned", action="store_true", help="add the quarantine-clearing postflight")
parser.add_argument("--auto-updates", action="store_true", help="the app updates itself (Sparkle)")
parser.add_argument("source")
Expand All @@ -56,7 +73,7 @@ def main() -> int:
with open(args.source) as f:
source = f.read()
try:
cask = render(source, args.version, args.sha256, args.unsigned, args.auto_updates)
cask = render(source, args.version, args.sha256, args.unsigned, args.auto_updates, args.beta)
except ValueError as error:
print(f"render_cask: {error}", file=sys.stderr)
return 1
Expand Down
78 changes: 78 additions & 0 deletions scripts/test_render_cask.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""Tests for render_cask.py. Run: python3 -m unittest discover -s scripts -p 'test_*.py'"""

import os
import shutil
import subprocess
import tempfile
import unittest

from render_cask import BETA_TOKEN, STABLE_TOKEN, render

TEMPLATE = os.path.join(os.path.dirname(__file__), "..", "homebrew", "Casks", "focusrite-volume-control.rb")
SHA = "a" * 64


def template() -> str:
with open(TEMPLATE) as f:
return f.read()


class RenderCaskTests(unittest.TestCase):
def test_stable(self):
cask = render(template(), "1.6.0", SHA, unsigned=False, auto_updates=False)
self.assertIn(f'cask "{STABLE_TOKEN}" do', cask)
self.assertIn(' version "1.6.0"', cask)
self.assertIn(f' sha256 "{SHA}"', cask)
self.assertIn(f' conflicts_with cask: "{BETA_TOKEN}"', cask)
self.assertNotIn("postflight do", cask)
self.assertNotIn("auto_updates", cask)

def test_beta_swaps_token_and_conflict(self):
cask = render(template(), "1.6.0-beta.2", SHA, unsigned=False, auto_updates=False, beta=True)
self.assertIn(f'cask "{BETA_TOKEN}" do', cask)
self.assertIn(f' conflicts_with cask: "{STABLE_TOKEN}"', cask)
self.assertNotIn(f'cask "{STABLE_TOKEN}" do', cask)
self.assertIn(' version "1.6.0-beta.2"', cask)

def test_beta_cask_also_takes_stable_versions(self):
cask = render(template(), "1.6.0", SHA, unsigned=False, auto_updates=False, beta=True)
self.assertIn(' version "1.6.0"', cask)

def test_stable_cask_rejects_prerelease_versions(self):
with self.assertRaises(ValueError):
render(template(), "1.6.0-beta.1", SHA, unsigned=False, auto_updates=False)

def test_rejects_bad_input(self):
for version in ["", "v1.6.0", "1.6.0-", "1.6.0-beta..1", '1.6"; system "x']:
with self.subTest(version=version), self.assertRaises(ValueError):
render(template(), version, SHA, unsigned=False, auto_updates=False, beta=True)
with self.assertRaises(ValueError):
render(template(), "1.6.0", "not-a-sha", unsigned=False, auto_updates=False)

def test_unsigned_adds_quarantine_postflight_after_app(self):
cask = render(template(), "1.6.0", SHA, unsigned=True, auto_updates=False)
self.assertIn(' app "Volume Control.app"\n\n # Unsigned build', cask)
self.assertIn('"/usr/bin/xattr"', cask)

def test_auto_updates_goes_before_conflicts_with(self):
for beta in (False, True):
cask = render(template(), "1.6.0", SHA, unsigned=False, auto_updates=True, beta=beta)
self.assertIn(" auto_updates true\n conflicts_with cask:", cask)

@unittest.skipUnless(shutil.which("ruby"), "ruby not installed")
def test_rendered_casks_are_valid_ruby(self):
for beta in (False, True):
for unsigned in (False, True):
cask = render(template(), "1.6.0-beta.2" if beta else "1.6.0", SHA,
unsigned=unsigned, auto_updates=True, beta=beta)
with tempfile.NamedTemporaryFile("w", suffix=".rb", delete=False) as f:
f.write(cask)
try:
result = subprocess.run(["ruby", "-c", f.name], capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stderr)
finally:
os.unlink(f.name)


if __name__ == "__main__":
unittest.main()
Loading