Skip to content
69 changes: 66 additions & 3 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Show disk usage before cleanup
run: df -h /

- name: Free disk space on runner
uses: jlumbroso/free-disk-space@main
with:
tool-cache: true
android: false
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: true

- name: Show disk usage after cleanup
run: df -h /

- name: Setup Java
uses: actions/setup-java@v4
with:
Expand All @@ -37,6 +54,19 @@ jobs:
uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: stable

- name: Clean Flutter project
run: |
flutter clean
rm -rf build
cd android && ./gradlew clean && cd -
rm -rf ~/.gradle/caches
rm -rf ~/.gradle/daemon
rm -rf ~/.android/build-cache

- name: Show disk usage after cleanup
run: df -h /

- name: Decode Android keystore
run: echo "${{ secrets.ANDROID_KEYSTORE }}" | base64 --decode > ${{ env.KEYSTORE_PATH }}
Expand Down Expand Up @@ -77,17 +107,50 @@ jobs:
needs: build_android
permissions:
contents: write
env:
APK_RELEASE_PATH: apk-release/*.apk
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Parse Build Tag & Release Notes from CHANGELOG.md
id: parse_changelog
run: |
echo "Parsing CHANGELOG.md"

awk '
BEGIN {found=0}
/^##[[:space:]]*\[?v?[0-9]+\.[0-9]+\.[0-9]+.*\]?/ && found==0 {
line=$0
gsub(/^##[[:space:]]*/, "", line)
sub(/[[:space:]]+-[[:space:]]*.*$/, "", line)
gsub(/^\[|\]$/, "", line)
tag=line
if (tag !~ /^v/) tag = "v" tag
found=1
next
}
found==1 {
if (/^##[[:space:]]+/) exit
notes = notes $0 "\n"
}
END {
printf("build_tag=%s\n", tag)
printf("release_notes<<EOF\n%s\nEOF\n", notes)
}
' CHANGELOG.md >> $GITHUB_OUTPUT
Comment on lines +116 to +141

@coderabbitai coderabbitai Bot Dec 26, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# First, check if CHANGELOG.md exists and examine its format
git ls-files | grep -i changelog

Repository: AOSSIE-Org/Resonate

Length of output: 45


🏁 Script executed:

# Also check the workflow file context around the snippet
find . -name "build_and_deploy.yml" -o -name "*.yml" -path "*workflows*"

Repository: AOSSIE-Org/Resonate

Length of output: 316


🏁 Script executed:

# Check file size of build_and_deploy.yml
wc -l ./.github/workflows/build_and_deploy.yml

Repository: AOSSIE-Org/Resonate

Length of output: 107


🏁 Script executed:

# Read the workflow file around the snippet area (lines 100-150)
sed -n '100,150p' ./.github/workflows/build_and_deploy.yml

Repository: AOSSIE-Org/Resonate

Length of output: 1514


🏁 Script executed:

# Check if there are any changelog files with different names
find . -type f \( -name "*change*" -o -name "*CHANGE*" \) | head -20

Repository: AOSSIE-Org/Resonate

Length of output: 316


🏁 Script executed:

# Check the entire repository for any changelog file
find . -type f -name "*[Cc][Hh][Aa][Nn][Gg]*" 2>/dev/null

Repository: AOSSIE-Org/Resonate

Length of output: 316


🏁 Script executed:

# Check if CHANGELOG.md exists in the root
ls -la CHANGELOG.md 2>&1

Repository: AOSSIE-Org/Resonate

Length of output: 122


🏁 Script executed:

# Read the full workflow file to see all steps and understand the complete context
cat -n ./.github/workflows/build_and_deploy.yml

Repository: AOSSIE-Org/Resonate

Length of output: 5807


🏁 Script executed:

# Check if CHANGELOG.md exists in git history or other branches
git log --all --full-history --pretty=format:"%H %s" -- CHANGELOG.md 2>&1 | head -5

Repository: AOSSIE-Org/Resonate

Length of output: 45


🏁 Script executed:

# Check all branches to see if CHANGELOG.md exists anywhere
git branch -a --format='%(refname:short)' | xargs -I {} sh -c 'git ls-tree -r {} -- CHANGELOG.md >/dev/null 2>&1 && echo "Found in: {}"'

Repository: AOSSIE-Org/Resonate

Length of output: 205


🏁 Script executed:

# Let's trace what happens in the workflow if the file doesn't exist
# Simulate what awk does with a missing file
echo "Testing awk behavior with missing file:"
awk 'BEGIN {print "starting"}' /nonexistent/file 2>&1; echo "Exit code: $?"

Repository: AOSSIE-Org/Resonate

Length of output: 124


🏁 Script executed:

# Check which branch we're on and if CHANGELOG.md exists there
git branch -vv

Repository: AOSSIE-Org/Resonate

Length of output: 360


🏁 Script executed:

# Check git status
git status

Repository: AOSSIE-Org/Resonate

Length of output: 128


🏁 Script executed:

# Try to checkout or show CHANGELOG.md from master
git show master:CHANGELOG.md 2>&1 | head -30

Repository: AOSSIE-Org/Resonate

Length of output: 116


🏁 Script executed:

# Check if CHANGELOG.md exists in the current branch (coderabbit_602)
cat CHANGELOG.md 2>&1 | head -50

Repository: AOSSIE-Org/Resonate

Length of output: 107


🏁 Script executed:

# Also check the git log to understand the commit
git log --oneline -1

Repository: AOSSIE-Org/Resonate

Length of output: 129


🏁 Script executed:

# Show what files were changed in the current commit/branch
git diff --name-only coderabbit_602...master 2>/dev/null | grep -i change

Repository: AOSSIE-Org/Resonate

Length of output: 45


🏁 Script executed:

# Check the current commit to see what was changed
git show --stat HEAD

Repository: AOSSIE-Org/Resonate

Length of output: 24217


🏁 Script executed:

# List all files in the current directory to see what exists
ls -la

Repository: AOSSIE-Org/Resonate

Length of output: 1900


🏁 Script executed:

# Check if CHANGELOG.md was added in this commit
git show HEAD --name-status | head -20

Repository: AOSSIE-Org/Resonate

Length of output: 835


🏁 Script executed:

# Check if there's a git tag or version info in any other file
grep -r "version" . --include="*.yaml" --include="*.yml" --include="*.md" 2>/dev/null | grep -i "changelog\|release\|version" | head -20

Repository: AOSSIE-Org/Resonate

Length of output: 7110


🏁 Script executed:

# Simulate what happens with the awk script when CHANGELOG.md doesn't exist
# and check what gets output to GITHUB_OUTPUT
cat > /tmp/test_awk.sh << 'EOF'
#!/bin/bash

# Create a fake GITHUB_OUTPUT
GITHUB_OUTPUT=/tmp/github_output.txt
rm -f $GITHUB_OUTPUT

# Run the exact awk command from the workflow (without the file)
awk '
  BEGIN {found=0}
  /^##[[:space:]]*\[?v?[0-9]+\.[0-9]+\.[0-9]+.*\]?/ && found==0 {
    line=$0
    gsub(/^##[[:space:]]*/, "", line)
    sub(/[[:space:]]+-[[:space:]]*.*$/, "", line)
    gsub(/^\[|\]$/, "", line)
    tag=line
    if (tag !~ /^v/) tag = "v" tag
    found=1
    next
  }
  found==1 {
    if (/^##[[:space:]]+/) exit
    notes = notes $0 "\n"
  }
  END {
    printf("build_tag=%s\n", tag)
    printf("release_notes<<EOF\n%s\nEOF\n", notes)
  }
' /nonexistent/CHANGELOG.md >> $GITHUB_OUTPUT 2>&1

echo "Exit code: $?"
echo ""
echo "=== Content of GITHUB_OUTPUT ==="
cat $GITHUB_OUTPUT
echo ""
echo "=== Checking if tag is empty ==="
TAG=$(grep "build_tag=" $GITHUB_OUTPUT | cut -d'=' -f2)
if [ -z "$TAG" ]; then
  echo "ERROR: build_tag is empty!"
elif [ "$TAG" = "v" ]; then
  echo "ERROR: build_tag is just 'v' with no version!"
else
  echo "build_tag=$TAG"
fi
EOF
bash /tmp/test_awk.sh

Repository: AOSSIE-Org/Resonate

Length of output: 279


🏁 Script executed:

# Check the ncipollo/release-action documentation to see what happens with empty tag
# First, check if there are any test files or documentation in the repo about release
find . -name "*.md" -type f | xargs grep -l "release-action\|ncipollo" 2>/dev/null

Repository: AOSSIE-Org/Resonate

Length of output: 47


🏁 Script executed:

# Search for documentation or PRs related to the workflow
git log --all --oneline | grep -i "changelog\|release" | head -10

Repository: AOSSIE-Org/Resonate

Length of output: 723


🏁 Script executed:

# Check if there's a way to see what the release action does with empty tag
# Look at the full workflow again to see if there's any conditional logic
sed -n '149,156p' ./.github/workflows/build_and_deploy.yml

Repository: AOSSIE-Org/Resonate

Length of output: 403


🏁 Script executed:

# Let's verify the exact behavior: does awk exit with error when file missing?
echo "Testing awk exit behavior:"
awk 'BEGIN {print "test"}' /nonexistent/file >> /tmp/out.txt 2>&1
echo "AWK exit code when file missing: $?"
cat /tmp/out.txt

echo ""
echo "Checking if workflow would continue:"
set +e  # Don't exit on error
awk 'BEGIN {print "test"}' /nonexistent/file >> /tmp/out2.txt 2>&1
if [ $? -ne 0 ]; then
  echo "awk failed, but if set -e is not used, bash continues"
fi

Repository: AOSSIE-Org/Resonate

Length of output: 167


🏁 Script executed:

# This is critical - the workflow was added but CHANGELOG.md doesn't exist
# Let me check if the commit that added the workflow also added CHANGELOG.md
git show 1d5d5ee --name-status | grep -i changelog

Repository: AOSSIE-Org/Resonate

Length of output: 125


🏁 Script executed:

# Check if CHANGELOG.md was supposed to be in the commit
git show 1d5d5ee | grep -i "changelog" | head -20

Repository: AOSSIE-Org/Resonate

Length of output: 433


🏁 Script executed:

# Search the entire git history for any CHANGELOG file
git log --all --full-history --diff-filter=A --name-only --pretty=format: -- "*CHANGELOG*" | grep -v "^$"

Repository: AOSSIE-Org/Resonate

Length of output: 45


🏁 Script executed:

# Let's also verify: what happens when the release-action gets an empty or missing tag?
# Check ncipollo/release-action documentation or comments in the workflow
grep -A5 -B5 "ncipollo/release-action" ./.github/workflows/build_and_deploy.yml

Repository: AOSSIE-Org/Resonate

Length of output: 408


🏁 Script executed:

# Check if there are any other branches or recent changes that might have added CHANGELOG.md
git branch -a | xargs -I {} sh -c 'echo "=== Branch: {} ===" && git ls-tree -r {} -- CHANGELOG.md 2>/dev/null | head -1 || echo "Not found"'

Repository: AOSSIE-Org/Resonate

Length of output: 320


🏁 Script executed:

# Check the commit history around this workflow addition
git log --oneline --all -- ".github/workflows/build_and_deploy.yml" | head -10

Repository: AOSSIE-Org/Resonate

Length of output: 430


🏁 Script executed:

# Verify: what actually happens in the workflow when build_tag is empty
# Simulate the exact sequence in the workflow
cat > /tmp/simulate_workflow.sh << 'EOF'
#!/bin/bash
set +e

GITHUB_OUTPUT=/tmp/test_output.txt
rm -f $GITHUB_OUTPUT

echo "Step 1: Parse CHANGELOG.md (file doesn't exist)"
awk '
  BEGIN {found=0}
  /^##[[:space:]]*\[?v?[0-9]+\.[0-9]+\.[0-9]+.*\]?/ && found==0 {
    line=$0
    gsub(/^##[[:space:]]*/, "", line)
    sub(/[[:space:]]+-[[:space:]]*.*$/, "", line)
    gsub(/^\[|\]$/, "", line)
    tag=line
    if (tag !~ /^v/) tag = "v" tag
    found=1
    next
  }
  found==1 {
    if (/^##[[:space:]]+/) exit
    notes = notes $0 "\n"
  }
  END {
    printf("build_tag=%s\n", tag)
    printf("release_notes<<EOF\n%s\nEOF\n", notes)
  }
' CHANGELOG.md >> $GITHUB_OUTPUT 2>&1

PARSE_EXIT=$?
echo "AWK exit code: $PARSE_EXIT"

echo ""
echo "Step 2: Extract build_tag value"
BUILD_TAG=$(grep "^build_tag=" $GITHUB_OUTPUT 2>/dev/null | cut -d'=' -f2)
echo "BUILD_TAG value: '$BUILD_TAG'"

echo ""
echo "Step 3: What would be passed to release-action"
echo "Tag parameter: '$BUILD_TAG'"

if [ -z "$BUILD_TAG" ]; then
  echo "⚠️  ISSUE: Tag is empty - release-action will fail or use default tag"
fi

echo ""
echo "Full GITHUB_OUTPUT content:"
cat $GITHUB_OUTPUT
EOF
bash /tmp/simulate_workflow.sh

Repository: AOSSIE-Org/Resonate

Length of output: 441


🏁 Script executed:

# Final check: was CHANGELOG.md supposed to be created but forgotten?
# Look at the commit message and diff more carefully
git show 1d5d5ee | grep -A3 -B3 "CHANGELOG" || echo "No CHANGELOG mentioned in commit details"

Repository: AOSSIE-Org/Resonate

Length of output: 783


CHANGELOG.md is missing from the repository – workflow cannot function.

The AWK parsing step will fail immediately because the file doesn't exist. When awk tries to read CHANGELOG.md, it returns exit code 2 with error: cannot open file 'CHANGELOG.md' for reading: No such file or directory. This leaves build_tag as an empty string, which is then passed to the release-action, causing the release step to fail.

Two fixes are required:

  1. Create CHANGELOG.md in the repository root with version entries matching the regex pattern: ## [v]X.Y.Z
  2. Add error handling to validate file existence and non-empty parsed values before proceeding to the release step
🤖 Prompt for AI Agents
.github/workflows/build_and_deploy.yml around lines 116-141: the workflow
assumes CHANGELOG.md exists and AWK will fail (exit code 2) if the file is
missing, leaving build_tag empty and breaking the release step; fix by (1)
adding a CHANGELOG.md at the repository root with entries matching the expected
header pattern (## [v]X.Y.Z) so the parser has data, and (2) adding workflow
error handling before the release-action to check that CHANGELOG.md exists and
that parsed outputs (build_tag and release_notes) are non-empty — if the file is
missing or parsing yields empty values, fail fast with a clear error message (or
skip release) so the release step is not invoked with empty inputs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore this, the changelog file exists. Review the rest of the code, specifically the parsing step

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

echo "=== Checking CHANGELOG.md existence and format ==="
if [ -f CHANGELOG.md ]; then
    echo "✓ CHANGELOG.md exists"
    echo ""
    echo "=== First 50 lines of CHANGELOG.md ==="
    head -n 50 CHANGELOG.md
    echo ""
    echo "=== All version headers found ==="
    grep -n "^##" CHANGELOG.md | head -20
else
    echo "✗ CHANGELOG.md not found"
    exit 1
fi

echo ""
echo "=== Testing the AWK parsing script ==="
GITHUB_OUTPUT=/tmp/test_github_output.txt
rm -f $GITHUB_OUTPUT

awk '
  BEGIN {found=0}
  /^##[[:space:]]*\[?v?[0-9]+\.[0-9]+\.[0-9]+.*\]?/ && found==0 {
    line=$0
    gsub(/^##[[:space:]]*/, "", line)
    sub(/[[:space:]]+-[[:space:]]*.*$/, "", line)
    gsub(/^\[|\]$/, "", line)
    tag=line
    if (tag !~ /^v/) tag = "v" tag
    found=1
    next
  }
  found==1 {
    if (/^##[[:space:]]+/) exit
    notes = notes $0 "\n"
  }
  END {
    printf("build_tag=%s\n", tag)
    printf("release_notes<<EOF\n%s\nEOF\n", notes)
  }
' CHANGELOG.md > $GITHUB_OUTPUT

echo "Exit code: $?"
echo ""
echo "=== Parsed output ==="
cat $GITHUB_OUTPUT
echo ""
echo "=== Extracted values ==="
echo "build_tag: $(grep "^build_tag=" $GITHUB_OUTPUT | cut -d'=' -f2)"
echo ""
echo "release_notes (first 300 chars):"
sed -n '/release_notes<<EOF/,/^EOF$/p' $GITHUB_OUTPUT | head -n 15

Length of output: 75


🏁 Script executed:

#!/bin/bash

echo "=== Checking for CHANGELOG.md in different locations ==="

# Check if file exists on master branch
echo "1. Checking master branch:"
git ls-tree -r master --name-only | grep -i changelog

echo ""
echo "2. Checking dev branch:"
git ls-tree -r dev --name-only | grep -i changelog

echo ""
echo "3. Checking current branch:"
git ls-tree -r HEAD --name-only | grep -i changelog

echo ""
echo "4. Finding any changelog-like files in repo:"
find . -type f -iname "*change*" 2>/dev/null | grep -v ".git"

echo ""
echo "5. Checking if CHANGELOG.md exists on master:"
git show master:CHANGELOG.md 2>&1 | head -n 50

echo ""
echo "6. Current branch name:"
git branch --show-current

Length of output: 563


@M4dhav, I'll focus on the AWK parsing logic as requested.

Critical Issue: Regex Inconsistency

The AWK script has a regex pattern mismatch that will cause incorrect parsing:

Line 122 (version header matching):

/^##[[:space:]]*\[?v?[0-9]+\.[0-9]+\.[0-9]+.*\]?/

Uses [[:space:]]* — allows zero or more spaces after ##

Line 130 (exit condition for notes):

if (/^##[[:space:]]+/) exit

Uses [[:space:]]+ — requires one or more spaces after ##

Impact

If CHANGELOG.md contains headers without spaces (e.g., ##Features, ##[2.0.0], ##Fixes), the script will:

  1. ✅ Correctly match version header like ##v1.0.0
  2. Fail to stop at ##Features because it has zero spaces
  3. ❌ Include subsequent headers and content in release_notes

Recommended Fix

Make the patterns consistent:

# Option 1: Both require at least one space
/^##[[:space:]]+\[?v?[0-9]+\.[0-9]+\.[0-9]+.*\]?/  # Line 122
if (/^##[[:space:]]+/) exit                         # Line 130 (unchanged)

# Option 2: Both allow zero or more spaces (safer for varied formats)
/^##[[:space:]]*\[?v?[0-9]+\.[0-9]+\.[0-9]+.*\]?/  # Line 122 (unchanged)
if (/^##[[:space:]]*/) exit                         # Line 130 (change to *)

Recommendation: Use Option 2 to handle various CHANGELOG formats robustly.

Additional Issues

  1. No validation for empty tag: If no version is found, tag remains empty, outputting build_tag=v (just the prefix). Add validation in the END block:

    END {
      if (tag == "") {
        print "ERROR: No version found in CHANGELOG.md" > "/dev/stderr"
        exit 1
      }
      printf("build_tag=%s\n", tag)
      printf("release_notes<<EOF\n%s\nEOF\n", notes)
    }
  2. Trailing newline in notes: Each line appends \n, resulting in an extra trailing newline. While not critical, you could trim it:

    END {
      sub(/\n$/, "", notes)  # Remove final trailing newline
      printf("build_tag=%s\n", tag)
      printf("release_notes<<EOF\n%s\nEOF\n", notes)
    }

Would you like me to provide the complete corrected AWK script?


🧠 Learnings used
Learnt from: M4dhav
Repo: AOSSIE-Org/Resonate PR: 510
File: .github/workflows/build_and_deploy.yml:31-36
Timestamp: 2025-08-31T16:18:53.594Z
Learning: For the AOSSIE-Org/Resonate project, build system requirements like Java version setup are considered separate from dependency update PRs and should be handled in dedicated PRs focused on build system improvements.


- name: Download APK artifact
uses: actions/download-artifact@v4
with:
name: apk-release
path : apk-release

- name: Deploy to GitHub Release
uses: ncipollo/release-action@v1.14.0
with:
allowUpdates: true
artifacts: ${{ env.APK_PATH }}
artifacts: ${{ env.APK_RELEASE_PATH }}
artifactContentType: apk
generateReleaseNotes: true
tag: latest_build
tag: ${{ steps.parse_changelog.outputs.build_tag }}
body: ${{ steps.parse_changelog.outputs.release_notes }}