From a710c0433f4d9d3805f1ecfaf9ecc3390e18180b Mon Sep 17 00:00:00 2001 From: Shripal Jain Date: Sun, 12 Apr 2026 17:42:23 +0200 Subject: [PATCH] Introduce new "prepare release" workflow - Add publish release job to main workflow --- .../{build.yml => build_and_release.yml} | 95 ++++++++++++++++++- .github/workflows/prepare_release.yml | 76 +++++++++++++++ 2 files changed, 167 insertions(+), 4 deletions(-) rename .github/workflows/{build.yml => build_and_release.yml} (54%) create mode 100644 .github/workflows/prepare_release.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build_and_release.yml similarity index 54% rename from .github/workflows/build.yml rename to .github/workflows/build_and_release.yml index b1b51b1..a9320df 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build_and_release.yml @@ -1,4 +1,4 @@ -name: Build Flutter Desktop Apps +name: Build (and release) Flutter Desktop Apps on: push: @@ -31,7 +31,7 @@ jobs: - name: Install dependencies run: | sudo apt-get update - + # For FastForge sudo apt-get install locate wget -O appimagetool "https://github.com/AppImage/appimagetool/releases/download/continuous/appimagetool-x86_64.AppImage" @@ -123,7 +123,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v4 with: - node-version: '18' + node-version: "18" - name: Install create-dmg run: npm install --global create-dmg @@ -157,5 +157,92 @@ jobs: uses: actions/upload-artifact@v4 with: name: dmg - path: '*.dmg' + path: "*.dmg" if-no-files-found: error + + publish_release: + name: Publish Release & Update Brew + needs: [ build-linux, build-windows, build-macos ] + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Check if Release is Needed + id: check_release + run: | + VERSION=$(grep '^version: ' pubspec.yaml | awk '{print $2}' | cut -d '+' -f 1) + echo "VERSION=$VERSION" >> $GITHUB_ENV + + if git show-ref --tags "v$VERSION" --quiet; then + echo "Tag v$VERSION already exists. Skipping release." + echo "skip=true" >> $GITHUB_OUTPUT + else + echo "Tag v$VERSION does not exist. Proceeding with release." + echo "skip=false" >> $GITHUB_OUTPUT + fi + + - name: Create Git Tag + if: steps.check_release.outputs.skip == 'false' + run: | + git config user.name "github-actions[bot]" + git config user.email "action@github.com" + git tag "v${{ env.VERSION }}" + git push origin "v${{ env.VERSION }}" + + - name: Download Artifacts + if: steps.check_release.outputs.skip == 'false' + uses: actions/download-artifact@v4 + with: + path: artifacts + + - name: Extract Release Notes + if: steps.check_release.outputs.skip == 'false' + run: | + awk '/^# v/{if (p) exit; p=1; next} p' CHANGELOG.md > release_notes.txt + echo "NOTES_FILE=release_notes.txt" >> $GITHUB_ENV + + - name: Create GitHub Release + if: steps.check_release.outputs.skip == 'false' + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release create "v${{ env.VERSION }}" \ + --title "scrcpy buddy v${{ env.VERSION }}" \ + --notes-file ${{ env.NOTES_FILE }} \ + artifacts/*/* || echo "Release already exists" + + - name: Update Homebrew Cask + if: steps.check_release.outputs.skip == 'false' + env: + PAT: ${{ secrets.PAT }} + run: | + DMG_FILE=$(find artifacts -name "*.dmg" | head -n 1) + if [ -z "$DMG_FILE" ]; then + echo "DMG file not found!" + exit 1 + fi + + SHA256=$(sha256sum "$DMG_FILE" | awk '{print $1}') + echo "SHA256 for DMG: $SHA256" + + if [ -z "$PAT" ]; then + echo "PAT secret is missing. Cannot update Homebrew tap." + exit 1 + fi + + git clone https://x-access-token:${PAT}@github.com/Codertainment/homebrew-scrcpy_buddy.git tap + cd tap + + sed -i -E "s/version \".*\"/version \"${{ env.VERSION }}\"/" Casks/scrcpy_buddy.rb + sed -i -E "s/sha256 \".*\"/sha256 \"$SHA256\"/" Casks/scrcpy_buddy.rb + + git config user.name "github-actions[bot]" + git config user.email "action@github.com" + git commit -am "chore: update scrcpy_buddy to v${{ env.VERSION }}" + git push diff --git a/.github/workflows/prepare_release.yml b/.github/workflows/prepare_release.yml new file mode 100644 index 0000000..2429f15 --- /dev/null +++ b/.github/workflows/prepare_release.yml @@ -0,0 +1,76 @@ +name: Prepare Release + +on: + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + prepare_release: + name: Prepare Release PR + if: github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get version from pubspec.yaml + id: get_version + run: | + VERSION=$(grep '^version: ' pubspec.yaml | awk '{print $2}' | cut -d '+' -f 1) + if [ -z "$VERSION" ]; then + echo "Failed to extract version from pubspec.yaml" + exit 1 + fi + echo "VERSION=$VERSION" >> $GITHUB_ENV + + - name: Update snapcraft.yaml + run: | + sed -i "s/^version: .*/version: \"${{ env.VERSION }}\"/" snap/snapcraft.yaml + + - name: Generate Notes Since Last Tag + id: notes + run: | + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") + if [ -n "$LATEST_TAG" ]; then + # Get date of latest tag + LAST_DATE=$(git log -1 --format=%cI "$LATEST_TAG") + CHANGES=$(gh pr list --state merged --search "merged:>$LAST_DATE" --limit 100 --json title,number,author | jq -r '.[] | "- \(.title) (#\(.number)) by @\(.author.login)"') + else + CHANGES=$(gh pr list --state merged --limit 100 --json title,number,author | jq -r '.[] | "- \(.title) (#\(.number)) by @\(.author.login)"') + fi + + if [ -z "$CHANGES" ]; then + CHANGES="- No new pull requests merged." + fi + + echo "$CHANGES" > changes.txt + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Update CHANGELOG.md + run: | + DATE=$(date +'%d-%m-%Y') + TEMP_CHANGELOG=$(mktemp) + echo "# v${{ env.VERSION }}: $DATE" > "$TEMP_CHANGELOG" + cat changes.txt >> "$TEMP_CHANGELOG" + echo "" >> "$TEMP_CHANGELOG" + if [ -f CHANGELOG.md ]; then + cat CHANGELOG.md >> "$TEMP_CHANGELOG" + fi + mv "$TEMP_CHANGELOG" CHANGELOG.md + rm changes.txt + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "chore: Release v${{ env.VERSION }}" + title: "Release v${{ env.VERSION }}" + body: "Automated release preparation for v${{ env.VERSION }}\n\nOnce this PR is approved and merged, the release tag will be created, artifacts built, and the GitHub release published along with the Homebrew Cask update." + branch: "release/v${{ env.VERSION }}" + base: "main"