diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 894f6a0..07a723a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,6 +18,8 @@ jobs: build: name: Build and Release runs-on: macos-15 + outputs: + version: ${{ steps.version.outputs.VERSION }} steps: - name: Checkout @@ -30,12 +32,32 @@ jobs: - name: Get version id: version + env: + GH_TOKEN: ${{ github.token }} run: | if [ -n "${{ inputs.version }}" ]; then - echo "VERSION=${{ inputs.version }}" >> $GITHUB_OUTPUT + VERSION="${{ inputs.version }}" + VERSION="${VERSION#v}" # Remove 'v' prefix if present + elif [ "${{ github.event_name }}" == "push" ]; then + VERSION="${GITHUB_REF#refs/tags/v}" # Extract from tag ref else - echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT + VERSION=$(gh release view --repo ${{ github.repository }} --json tagName -q '.tagName' 2>/dev/null || echo "") + if [ -z "$VERSION" ]; then + echo "Error: No version found. Please specify a version or create a release first." + exit 1 + fi + VERSION="${VERSION#v}" # Remove 'v' prefix + fi + + PROJECT_VERSION=$(sed -n 's/.*MARKETING_VERSION = \([0-9]\+\.[0-9]\+\.[0-9]\+\);.*/\1/p' MiddleDrag.xcodeproj/project.pbxproj | head -n 1) + if [ "$VERSION" != "$PROJECT_VERSION" ]; then + echo "Error: Version mismatch! Workflow version: $VERSION, Xcode project version: $PROJECT_VERSION" + echo "Please ensure project.pbxproj is updated (try running ./bump-version.sh)" + exit 1 fi + + echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT + echo "Using version: ${VERSION}" - name: Build Release run: | @@ -72,11 +94,23 @@ jobs: SHA=$(shasum -a 256 MiddleDrag-${{ steps.version.outputs.VERSION }}.zip | awk '{print $1}') echo "SHA256=$SHA" >> $GITHUB_OUTPUT echo "SHA256: $SHA" - + - name: Create Release uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' with: tag_name: v${{ steps.version.outputs.VERSION }} - name: MiddleDrag v${{ steps.version.outputs.VERSION }} - body: "## MiddleDrag v${{ steps.version.outputs.VERSION }}\n\n### SHA256\n```\n${{ steps.sha.outputs.SHA256 }}\n```\n\n### Requirements\n- macOS 14.0 or later\n- Accessibility permissions" + name: v${{ steps.version.outputs.VERSION }} + target_commitish: ${{ github.sha }} + body: | + SHA256: ${{ steps.sha.outputs.SHA256 }} files: MiddleDrag-${{ steps.version.outputs.VERSION }}.zip + + - name: Trigger Homebrew Update workflow + env: + VERSION: ${{ steps.version.outputs.VERSION }} + curl -f -X POST \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository }}/dispatches \ + -d "{\"event_type\":\"homebrew_release\",\"client_payload\":{\"version\":\"$VERSION\"}}" + echo "✓ Triggered Homebrew update workflow" diff --git a/.github/workflows/update-homebrew.yml b/.github/workflows/update-homebrew.yml index d84ab6c..3477488 100644 --- a/.github/workflows/update-homebrew.yml +++ b/.github/workflows/update-homebrew.yml @@ -4,6 +4,8 @@ permissions: contents: read on: + repository_dispatch: + types: [homebrew_release] release: types: [published] workflow_dispatch: diff --git a/bump-version.sh b/bump-version.sh new file mode 100755 index 0000000..d5d3b03 --- /dev/null +++ b/bump-version.sh @@ -0,0 +1,66 @@ +#!/bin/bash +# bump-version.sh - Update version in Xcode project and create git tag + +set -e + +VERSION=$1 + +if [ -z "$VERSION" ]; then + echo "Usage: ./bump-version.sh " + echo "Example: ./bump-version.sh 1.2.3" + exit 1 +fi + +# Remove 'v' prefix if provided +VERSION="${VERSION#v}" + +# Validate semver format +if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Error: Version must be in semver format (e.g., 1.2.3)" + exit 1 +fi + +# Ensure working directory is clean +if ! git diff-index --quiet HEAD --; then + echo "Error: Working directory has uncommitted changes. Please commit or stash them first." + exit 1 +fi +echo "Bumping version to $VERSION..." + +# Update Xcode project MARKETING_VERSION (both Debug and Release configs) +if [ ! -f "MiddleDrag.xcodeproj/project.pbxproj" ]; then + echo "Error: MiddleDrag.xcodeproj/project.pbxproj not found. Are you in the project root?" + exit 1 +fi +sed -i '' -E "s/MARKETING_VERSION = [0-9]+\.[0-9]+\.[0-9]+/MARKETING_VERSION = $VERSION/g" \ + MiddleDrag.xcodeproj/project.pbxproj + +# Verify exactly 2 instances were updated +COUNT=$(grep -c "MARKETING_VERSION = $VERSION" MiddleDrag.xcodeproj/project.pbxproj || echo "0") +if [ "$COUNT" -ne 2 ]; then + echo "Error: Expected exactly 2 MARKETING_VERSION updates, found $COUNT" + exit 1 +fi +echo "✓ Updated MARKETING_VERSION in Xcode project" + +# Check if tag already exists (local or remote) +if git rev-parse "v$VERSION" >/dev/null 2>&1; then + echo "Error: Tag v$VERSION already exists locally" + exit 1 +fi +if git ls-remote --tags origin | grep -q "refs/tags/v$VERSION$"; then + echo "Error: Tag v$VERSION already exists on remote" + exit 1 +fi + +# Stage and commit +git add MiddleDrag.xcodeproj/project.pbxproj +git commit -m "Bump version to $VERSION" +echo "✓ Committed version change" + +# Create tag +git tag "v$VERSION" +echo "✓ Created tag v$VERSION" +echo "" +echo "Done! To trigger the release workflow, run:" +echo " git push && git push --tags"