Skip to content

chore(release): 1.5.2 #6

chore(release): 1.5.2

chore(release): 1.5.2 #6

name: Release on Version Change
on:
push:
branches: [main]
paths:
- 'package.json'
workflow_dispatch:
jobs:
check-version:
# Skip if this is an automated release commit
if: ${{ !startsWith(github.event.head_commit.message, 'chore(release):') }}
runs-on: ubuntu-latest
outputs:
version_changed: ${{ steps.version-check.outputs.changed }}
new_version: ${{ steps.version-check.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check if version changed
id: version-check
run: |
# Get current version
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "Current version: $CURRENT_VERSION"
# Get previous version
git checkout HEAD~1 2>/dev/null || true
if [ -f package.json ]; then
PREVIOUS_VERSION=$(node -p "require('./package.json').version" 2>/dev/null || echo "0.0.0")
else
PREVIOUS_VERSION="0.0.0"
fi
git checkout - 2>/dev/null || true
echo "Previous version: $PREVIOUS_VERSION"
# Check if version changed
if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
echo "changed=true" >> $GITHUB_OUTPUT
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
else
echo "Version unchanged ($CURRENT_VERSION)"
echo "changed=false" >> $GITHUB_OUTPUT
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
fi
update-scripts:
needs: check-version
if: needs.check-version.outputs.version_changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN || secrets.GITHUB_TOKEN }}
- name: Update version in scripts
run: |
VERSION=${{ needs.check-version.outputs.new_version }}
echo "Updating version to $VERSION in all scripts..."
# Update version in the main script
sed -i "s/VERSION=\"[^\"]*\"/VERSION=\"$VERSION\"/g" ra2mp3
# Update version in install scripts
sed -i "s/VERSION=\"[^\"]*\"/VERSION=\"$VERSION\"/g" install_macos.sh
sed -i "s/VERSION=\"[^\"]*\"/VERSION=\"$VERSION\"/g" install_linux.sh
# Commit changes if any were made
if ! git diff --quiet; then
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add ra2mp3 install_macos.sh install_linux.sh
git commit -m "chore: update version to $VERSION in scripts [skip ci]"
git push
fi
create-github-release:
needs: [check-version, update-scripts]
if: needs.check-version.outputs.version_changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if release exists
id: release-check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=${{ needs.check-version.outputs.new_version }}
if gh release view "v$VERSION" 2>/dev/null; then
echo "Release v$VERSION already exists"
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "Release v$VERSION not found, will create"
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Generate Release Notes
if: steps.release-check.outputs.exists == 'false'
id: release-notes
run: |
VERSION=${{ needs.check-version.outputs.new_version }}
# Get the previous tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
# Generate release notes
if [ -z "$PREVIOUS_TAG" ]; then
NOTES="Initial release v$VERSION"
else
# Get commit messages since last tag
NOTES="## What's Changed\n\n"
# Group commits by type
FEATURES=$(git log $PREVIOUS_TAG..HEAD --pretty=format:"%s" | grep "^feat:" | sed 's/^feat: /- /' || true)
FIXES=$(git log $PREVIOUS_TAG..HEAD --pretty=format:"%s" | grep "^fix:" | sed 's/^fix: /- /' || true)
DOCS=$(git log $PREVIOUS_TAG..HEAD --pretty=format:"%s" | grep "^docs:" | sed 's/^docs: /- /' || true)
OTHERS=$(git log $PREVIOUS_TAG..HEAD --pretty=format:"%s" | grep -v "^feat:\|^fix:\|^docs:\|^chore:" | sed 's/^/- /' || true)
if [ ! -z "$FEATURES" ]; then
NOTES="$NOTES### ✨ Features\n$FEATURES\n\n"
fi
if [ ! -z "$FIXES" ]; then
NOTES="$NOTES### 🐛 Bug Fixes\n$FIXES\n\n"
fi
if [ ! -z "$DOCS" ]; then
NOTES="$NOTES### 📚 Documentation\n$DOCS\n\n"
fi
if [ ! -z "$OTHERS" ]; then
NOTES="$NOTES### 🔧 Other Changes\n$OTHERS\n\n"
fi
NOTES="$NOTES**Full Changelog**: https://github.com/wiiiimm/ra2mp3/compare/$PREVIOUS_TAG...v$VERSION"
fi
# Save notes to file for release creation
echo -e "$NOTES" > release-notes.md
- name: Create Release
if: steps.release-check.outputs.exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=${{ needs.check-version.outputs.new_version }}
# Create the release
gh release create "v$VERSION" \
--title "v$VERSION" \
--notes-file release-notes.md \
--latest
update-homebrew:
needs: [check-version, create-github-release]
if: needs.check-version.outputs.version_changed == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Update Homebrew Formula
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
VERSION=${{ needs.check-version.outputs.new_version }}
# Check if GH_TOKEN is available
if [ -z "$GITHUB_TOKEN" ]; then
echo "⚠️ Homebrew update skipped: GH_TOKEN secret not configured"
exit 0
fi
echo "Updating Homebrew tap for ra2mp3 version $VERSION..."
# 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
# Create formula if it doesn't exist
FORMULA="Formula/ra2mp3.rb"
if [ ! -f "$FORMULA" ]; then
mkdir -p Formula
cat > "$FORMULA" << 'FORMULA_END'
class Ra2mp3 < Formula
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
FORMULA_END
fi
# Calculate SHA256 for the release tarball
RELEASE_URL="https://github.com/wiiiimm/ra2mp3/archive/v${VERSION}.tar.gz"
# Download and calculate SHA256
curl -L -o release.tar.gz "$RELEASE_URL"
SHA256=$(sha256sum release.tar.gz | cut -d' ' -f1)
echo "SHA256: $SHA256"
# Update URL and SHA256
sed -i "s|url \"https://github.com/wiiiimm/ra2mp3/archive/v.*\.tar\.gz\"|url \"https://github.com/wiiiimm/ra2mp3/archive/v${VERSION}.tar.gz\"|" "$FORMULA"
sed -i "s|sha256 \"[a-f0-9]*\"|sha256 \"${SHA256}\"|" "$FORMULA"
# Check if changes were made
if git diff --quiet; then
echo "No changes to formula"
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"