Skip to content

feat: add GitHub workflows for automated releases and Homebrew deploy… #9

feat: add GitHub workflows for automated releases and Homebrew deploy…

feat: add GitHub workflows for automated releases and Homebrew deploy… #9

name: Automated Release Workflow
on:
push:
branches: [main]
workflow_dispatch:
jobs:
# Job: Create automated release using semantic-release
create-release:
if: github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
ref: main
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run semantic-release
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
GH_TOKEN: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
run: |
# Capture the version before semantic-release
VERSION_BEFORE=$(node -p "require('./package.json').version")
echo "VERSION_BEFORE=${VERSION_BEFORE}" >> $GITHUB_ENV
# Run semantic-release
npx semantic-release
# Capture the version after semantic-release
VERSION_AFTER=$(node -p "require('./package.json').version")
echo "VERSION_AFTER=${VERSION_AFTER}" >> $GITHUB_ENV
# Check if version changed
if [ "$VERSION_BEFORE" != "$VERSION_AFTER" ]; then
echo "NEW_VERSION_CREATED=true" >> $GITHUB_ENV
echo "NEW_VERSION=${VERSION_AFTER}" >> $GITHUB_OUTPUT
echo "Version bumped from ${VERSION_BEFORE} to ${VERSION_AFTER}"
else
echo "NEW_VERSION_CREATED=false" >> $GITHUB_ENV
echo "No version bump occurred (still at ${VERSION_BEFORE})"
fi
- name: Update Homebrew Tap
if: env.NEW_VERSION_CREATED == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
VERSION="${{ env.VERSION_AFTER }}"
# Check if GH_TOKEN is available
if [ -z "$GITHUB_TOKEN" ]; then
echo "⚠️ Homebrew tap update skipped: GH_TOKEN secret not configured"
echo "To enable automatic Homebrew tap updates, add a GH_TOKEN secret with repo write permissions"
exit 0
fi
echo "Updating Homebrew tap for ra2mp3 version ${VERSION}..."
# Wait for GitHub release to be created
echo "Waiting for GitHub release to be available..."
sleep 5
# Configure git
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
# Clone the tap repository
git clone https://x-access-token:${GITHUB_TOKEN}@github.com/wiiiimm/homebrew-tap.git tap-repo
cd tap-repo
# Check if formula exists, if not create it
FORMULA="Formula/ra2mp3.rb"
if [ ! -f "$FORMULA" ]; then
echo "Creating new Homebrew formula for ra2mp3..."
mkdir -p Formula
cat > "$FORMULA" << 'EOF'
class Ra2mp3 < Formula

Check failure on line 95 in .github/workflows/automated-release.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/automated-release.yml

Invalid workflow file

You have an error in your yaml syntax on line 95
desc "Convert RealAudio (.ra/.ram/.rm) files to MP3 format using FFmpeg"
homepage "https://github.com/wiiiimm/ra2mp3"
url "https://github.com/wiiiimm/ra2mp3/archive/v0.0.0.tar.gz"
sha256 "placeholder"
license "MIT"
depends_on "ffmpeg"
def install
bin.install "ra2mp3"
end
test do
system "#{bin}/ra2mp3", "--version"
end
end
EOF
fi
# Calculate SHA256 for the release tarball
RELEASE_URL="https://github.com/wiiiimm/ra2mp3/archive/v${VERSION}.tar.gz"
echo "Downloading release tarball from: $RELEASE_URL"
# Download and calculate SHA256
curl -L -o release.tar.gz "$RELEASE_URL"
if [ -f release.tar.gz ]; then
if [[ "$OSTYPE" == "darwin"* ]]; then
SHA256=$(shasum -a 256 release.tar.gz | cut -d' ' -f1)
else
SHA256=$(sha256sum release.tar.gz | cut -d' ' -f1)
fi
echo "SHA256: $SHA256"
# Update the formula
sed -i.bak -E "s|url \"https://github.com/wiiiimm/ra2mp3/archive/v[0-9.]+\.tar\.gz\"|url \"https://github.com/wiiiimm/ra2mp3/archive/v${VERSION}.tar.gz\"|" "$FORMULA"
sed -i.bak -E "s|sha256 \"[a-f0-9]*\"|sha256 \"${SHA256}\"|" "$FORMULA"
rm -f "${FORMULA}.bak"
# Check if changes were made
if git diff --quiet; then
echo "No changes to formula (version might already be updated)"
exit 0
fi
# Commit and push
git add "$FORMULA"
git commit -m "Update ra2mp3 to ${VERSION}"
git push origin main
echo "✅ Homebrew formula updated to version ${VERSION}"
else
echo "❌ Failed to download release tarball"
exit 1
fi