From 3b87bcc55ed7a33ed4d2fa0fc6d8ad2b5eb705e3 Mon Sep 17 00:00:00 2001 From: "Mio." Date: Wed, 10 Dec 2025 23:24:08 +0100 Subject: [PATCH 1/5] Checkout branch to get the apk and add if release already exists --- .github/workflows/create_release.yml | 141 ++++++++++++++++----------- 1 file changed, 85 insertions(+), 56 deletions(-) diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 485ad9ee..0cbb5caf 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -20,107 +20,141 @@ jobs: ref: repo fetch-depth: 0 - # Get the merged PR info (only if not triggered manually) + # Get the merged PR info - name: Get PR information id: pr_info - if: github.event_name == 'push' run: | - # Check out the master branch to get the PR info + # Fetch and checkout master to analyze history git fetch origin master:master git checkout master - # Find the merge commit that triggered this workflow - MERGE_COMMIT=$(git rev-parse HEAD) + # Initialize variables + FOUND_PR=false - # Check if this is a merge commit - if git show --summary $MERGE_COMMIT | grep -q "Merge pull request"; then - # Extract PR number from merge commit message - PR_NUMBER=$(git log -1 --pretty=%B | grep -oP 'Merge pull request #\K\d+') + # Get the last 10 merge commits + MERGE_COMMITS=$(git log --merges --format='%H' -n 10) + + for COMMIT in $MERGE_COMMITS; do + # Extract PR number + PR_NUMBER=$(git show --format=%B -s $COMMIT | grep -oP 'Merge pull request #\K\d+') + if [ -z "$PR_NUMBER" ]; then + PR_NUMBER=$(git show --format=%B -s $COMMIT | grep -oP '\(#\K\d+(?=\))') + fi if [ -n "$PR_NUMBER" ]; then - echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT - - # Get PR details + echo "Checking PR #$PR_NUMBER..." PR_JSON=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER) - # Use heredoc for TITLE in case it has special chars PR_TITLE=$(echo "$PR_JSON" | jq -r .title) - echo "pr_title=$PR_TITLE" >> $GITHUB_OUTPUT - PR_AUTHOR=$(echo "$PR_JSON" | jq -r .user.login) - echo "pr_author=$PR_AUTHOR" >> $GITHUB_OUTPUT + # Check if title matches version pattern + if [[ "$PR_TITLE" == *"1.4."* ]]; then + echo "✅ Found Release PR: #$PR_NUMBER - $PR_TITLE" + echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT + echo "pr_title=$PR_TITLE" >> $GITHUB_OUTPUT - # Check if first-time contributor - CONTRIBUTOR_JSON=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - https://api.github.com/repos/${{ github.repository }}/contributors/$PR_AUTHOR) - CONTRIBUTIONS=$(echo "$CONTRIBUTOR_JSON" | jq -r .contributions) + PR_AUTHOR=$(echo "$PR_JSON" | jq -r .user.login) + echo "pr_author=$PR_AUTHOR" >> $GITHUB_OUTPUT - if [ "$CONTRIBUTIONS" = "1" ]; then - echo "is_first_contributor=true" >> $GITHUB_OUTPUT + # Check first-time contributor + CONTRIBUTOR_JSON=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + https://api.github.com/repos/${{ github.repository }}/contributors/$PR_AUTHOR) + CONTRIBUTIONS=$(echo "$CONTRIBUTOR_JSON" | jq -r .contributions) + if [ "$CONTRIBUTIONS" = "1" ]; then + echo "is_first_contributor=true" >> $GITHUB_OUTPUT + fi + + # Get PR body safely + PR_BODY=$(echo "$PR_JSON" | jq -r .body) + { + echo "pr_body<> $GITHUB_OUTPUT + + FOUND_PR=true + break fi - - # Get PR body - Use heredoc for multi-line strings - PR_BODY=$(echo "$PR_JSON" | jq -r .body) - { - echo "pr_body<> $GITHUB_OUTPUT fi + done + + if [ "$FOUND_PR" = "false" ]; then + echo "⚠️ No recent PR found matching '1.4.*'." fi - # Find the Kavita APK and extract version + # \Switch back to the 'repo' branch where APKs are stored + - name: Switch back to repo branch + run: | + echo "Switching git context back to 'repo' branch..." + git checkout repo + - name: Find APK and extract version id: apk_info run: | - # Find the Kavita APK in the apk folder + # Find the Kavita APK APK_PATH=$(find ./apk -name "tachiyomi-all.kavita-*.apk" -type f | head -n 1) if [ -z "$APK_PATH" ]; then - echo "No Kavita APK found in ./apk folder!" + echo "❌ No Kavita APK found in ./apk folder!" + echo "Current directory contents:" + ls -R exit 1 fi - echo "apk_path=$APK_PATH" >> $GITHUB_OUTPUT - - # Extract version from filename (tachiyomi-all.kavita-v1.4.21.apk -> v1.4.21) APK_FILENAME=$(basename "$APK_PATH") + # Extract version (e.g., v1.4.22) VERSION=$(echo "$APK_FILENAME" | grep -oP 'v\d+\.\d+\.\d+') if [ -z "$VERSION" ]; then - echo "Could not extract version from filename: $APK_FILENAME" - VERSION="v$(date +%Y%m%d-%H%M%S)" + echo "❌ Could not determine version from filename: $APK_FILENAME" + exit 1 fi - echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "apk_name=$APK_FILENAME" >> $GITHUB_OUTPUT - echo "Found APK: $APK_PATH" - echo "Extracted version: $VERSION" + echo "Detected Version: $VERSION" + + echo "apk_path=$APK_PATH" >> $GITHUB_OUTPUT + echo "version=$VERSION" >> $GITHUB_OUTPUT + + # Check if release already exists to prevent duplicates + - name: Check if release exists + id: check_release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + VERSION="${{ steps.apk_info.outputs.version }}" + echo "Checking if release $VERSION already exists..." + + if gh release view "$VERSION" > /dev/null 2>&1; then + echo "⚠️ Release $VERSION already exists! Skipping creation." + echo "exists=true" >> $GITHUB_OUTPUT + else + echo "✅ Release $VERSION does not exist. Proceeding." + echo "exists=false" >> $GITHUB_OUTPUT + fi - # Get commit messages since last tag - name: Get changelog + if: steps.check_release.outputs.exists == 'false' id: changelog run: | - # Switch to master branch to get git history + # We need master history again for the changelog git checkout master - - # Get the last tag LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") - if [ -n "$LAST_TAG" ]; then COMMITS=$(git log $LAST_TAG..HEAD --pretty=format:"- %s (%h)") else COMMITS=$(git log --pretty=format:"- %s (%h)" -n 20) fi - echo "changelog<> $GITHUB_OUTPUT - echo "$COMMITS" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT + { + echo "changelog<> $GITHUB_OUTPUT - # Create the release (on the repo branch) - name: Create Release + if: steps.check_release.outputs.exists == 'false' uses: softprops/action-gh-release@v2 with: name: Release ${{ steps.apk_info.outputs.version }} @@ -146,8 +180,3 @@ jobs: prerelease: false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Notify on failure - if: failure() - run: | - echo "Release creation failed. Check the logs for details." From f207b2a3c2753c765b499dc666fcfc652af071d7 Mon Sep 17 00:00:00 2001 From: "Mio." Date: Wed, 10 Dec 2025 23:29:27 +0100 Subject: [PATCH 2/5] checkout origin/master to be safe --- .github/workflows/create_release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 0cbb5caf..a8f39171 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -25,8 +25,8 @@ jobs: id: pr_info run: | # Fetch and checkout master to analyze history - git fetch origin master:master - git checkout master + git fetch origin master + git checkout -B master origin/master # Initialize variables FOUND_PR=false From 0168daab08c555b220c385be5b7ff466b93b52f4 Mon Sep 17 00:00:00 2001 From: "Mio." Date: Wed, 10 Dec 2025 23:36:01 +0100 Subject: [PATCH 3/5] Fix(release): Handle commits without PR numbers gracefully --- .github/workflows/create_release.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index a8f39171..6ccea6f4 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -36,9 +36,11 @@ jobs: for COMMIT in $MERGE_COMMITS; do # Extract PR number - PR_NUMBER=$(git show --format=%B -s $COMMIT | grep -oP 'Merge pull request #\K\d+') + PR_NUMBER=$(git show --format=%B -s $COMMIT | grep -oP 'Merge pull request #\K\d+' || true) + + # Fallback: Try to match squash merge pattern "Title (#123)" if [ -z "$PR_NUMBER" ]; then - PR_NUMBER=$(git show --format=%B -s $COMMIT | grep -oP '\(#\K\d+(?=\))') + PR_NUMBER=$(git show --format=%B -s $COMMIT | grep -oP '\(#\K\d+(?=\))' || true) fi if [ -n "$PR_NUMBER" ]; then From dd0f7dd4674b1e4abe8752b17bc474a561c6567b Mon Sep 17 00:00:00 2001 From: "Mio." Date: Wed, 10 Dec 2025 23:44:03 +0100 Subject: [PATCH 4/5] refactor(release): use
to avoid weird formatting --- .github/workflows/create_release.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 6ccea6f4..4e76f02f 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -165,15 +165,15 @@ jobs: body: | ## 🚀 Release ${{ steps.apk_info.outputs.version }} - ### 📝 Pull Request - ${{ steps.pr_info.outputs.pr_number && format('- Pull Request #%s by @%s', steps.pr_info.outputs.pr_number, steps.pr_info.outputs.pr_author) || 'Manual release' }} - ${{ steps.pr_info.outputs.pr_title && format('- Title: %s', steps.pr_info.outputs.pr_title) || '' }} - ${{ steps.pr_info.outputs.is_first_contributor == 'true' && format('### 🎉 Welcome @%s on their first contribution!', steps.pr_info.outputs.pr_author) || '' }} + ${{ steps.pr_info.outputs.pr_body }} - ${{ steps.pr_info.outputs.pr_body && format('### 📋 Description:\n%s', steps.pr_info.outputs.pr_body) || '' }} + --- + +
+ 📦 View Full Commit Log - ### 📦 Changes since last release: ${{ steps.changelog.outputs.changelog }} +
--- 🤖 *This release was automatically created* From 05bf6b5904fdcb062e231c1d078e3af16cc95c5a Mon Sep 17 00:00:00 2001 From: "Mio." Date: Wed, 10 Dec 2025 23:47:28 +0100 Subject: [PATCH 5/5] Fix: Switch back to repo branch before creating release --- .github/workflows/create_release.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 4e76f02f..d2e061ce 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -155,6 +155,12 @@ jobs: echo "EOF" } >> $GITHUB_OUTPUT + # Switch back to 'repo' branch to upload the APK + - name: Final Switch to repo branch + if: steps.check_release.outputs.exists == 'false' + run: | + git checkout repo + - name: Create Release if: steps.check_release.outputs.exists == 'false' uses: softprops/action-gh-release@v2