Skip to content

Update Homebrew Cask #18

Update Homebrew Cask

Update Homebrew Cask #18

name: Update Homebrew Cask
# Trigger when release workflow completes successfully
# Note: Using workflow_run instead of release:published because
# releases created by workflows using GITHUB_TOKEN don't trigger release events
on:
workflow_run:
workflows: ["Release SAM"]
types:
- completed
workflow_dispatch:
inputs:
version:
description: 'Version to update (e.g., 20260210.1)'
required: true
type: string
permissions:
contents: read
jobs:
update-cask:
name: Update SAM Homebrew Cask
runs-on: ubuntu-latest
# Only run if the release workflow succeeded (or manual dispatch)
if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Extract version from workflow run
id: version
env:
EVENT_NAME: ${{ github.event_name }}
INPUT_VERSION: ${{ github.event.inputs.version }}
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
run: |
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
VERSION="$INPUT_VERSION"
else
# Get the tag from the workflow run
# The release workflow runs on tag push, so we extract from head_branch
VERSION="$HEAD_BRANCH"
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Release version: $VERSION"
- name: Get DMG asset details
id: asset
uses: actions/github-script@v7
with:
script: |
const version = '${{ steps.version.outputs.version }}';
// Get release by tag (works for both release trigger and manual dispatch)
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: version,
});
// Find the DMG asset (the one users will download)
const dmgAsset = release.data.assets.find(a => a.name.endsWith('.dmg'));
if (!dmgAsset) {
throw new Error('No DMG asset found in release for version ' + version);
}
console.log('DMG Asset:', dmgAsset.name);
console.log('Download URL:', dmgAsset.browser_download_url);
core.setOutput('url', dmgAsset.browser_download_url);
- name: Download DMG and calculate SHA256
id: hash
run: |
DMG_URL="${{ steps.asset.outputs.url }}"
echo "Downloading: $DMG_URL"
curl -L -o /tmp/SAM.dmg "$DMG_URL"
# Calculate SHA256
SHA256=$(shasum -a 256 /tmp/SAM.dmg | cut -d' ' -f1)
echo "sha256=$SHA256" >> $GITHUB_OUTPUT
echo "SHA256: $SHA256"
- name: Checkout homebrew-SAM repo
uses: actions/checkout@v4
with:
repository: SyntheticAutonomicMind/homebrew-SAM
token: ${{ secrets.HOMEBREW_PAT }}
path: homebrew
- name: Update SAM cask
working-directory: homebrew
env:
VERSION: ${{ steps.version.outputs.version }}
SHA256: ${{ steps.hash.outputs.sha256 }}
run: |
echo "Updating Casks/sam.rb"
echo " Version: $VERSION"
echo " SHA256: $SHA256"
# Update the cask file with the new version and SHA256
# Use | as sed delimiter to avoid conflicts with URL slashes
sed -i.bak \
-e "s|version \"[^\"]*\"|version \"$VERSION\"|" \
-e "s|sha256 \"[^\"]*\"|sha256 \"$SHA256\"|" \
Casks/sam.rb
# Show the updated file
echo "Updated Casks/sam.rb:"
head -10 Casks/sam.rb
- name: Commit and push
working-directory: homebrew
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add Casks/sam.rb
if git diff --staged --quiet; then
echo "No changes detected"
else
git commit -m "chore(sam): update cask to version $VERSION"
git push
echo "[OK] Pushed homebrew cask update for SAM $VERSION"
fi
- name: Verify update
working-directory: homebrew
run: |
echo "Final Casks/sam.rb:"
grep -E "version|sha256" Casks/sam.rb | head -2