Skip to content

chore(merge): merge pull request #9 from MasuRii/feature/visual-impro… #12

chore(merge): merge pull request #9 from MasuRii/feature/visual-impro…

chore(merge): merge pull request #9 from MasuRii/feature/visual-impro… #12

Workflow file for this run

# GitHub Actions Workflow: Build and Release APK
# Triggers on push to main branch, builds Flutter APK, and creates GitHub Release
name: 📦 Build & Release APK
on:
push:
branches:
- main
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write
jobs:
build-and-release:
name: 🚀 Build & Release
runs-on: ubuntu-latest
steps:
# ============================================
# CHECKOUT & VERSION EXTRACTION
# ============================================
- name: 📥 Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: 🔍 Extract version info
id: version
run: |
# Extract version from pubspec.yaml
FULL_VERSION=$(grep '^version:' pubspec.yaml | sed 's/version: //' | tr -d ' \r')
VERSION_NAME=$(echo "$FULL_VERSION" | cut -d'+' -f1)
BUILD_NUMBER=$(echo "$FULL_VERSION" | cut -d'+' -f2)
# Default build number if not specified
if [ -z "$BUILD_NUMBER" ] || [ "$BUILD_NUMBER" = "$FULL_VERSION" ]; then
BUILD_NUMBER="1"
fi
# Get commit info
SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7)
BUILD_DATE=$(date -u +"%B %d, %Y")
# Set outputs
echo "full_version=$FULL_VERSION" >> $GITHUB_OUTPUT
echo "version_name=$VERSION_NAME" >> $GITHUB_OUTPUT
echo "build_number=$BUILD_NUMBER" >> $GITHUB_OUTPUT
echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT
echo "build_date=$BUILD_DATE" >> $GITHUB_OUTPUT
echo "tag_name=v${VERSION_NAME}" >> $GITHUB_OUTPUT
echo "::notice::📱 Version $VERSION_NAME (Build $BUILD_NUMBER)"
- name: 🏷️ Resolve release tag
id: tag_check
run: |
BASE_TAG="${{ steps.version.outputs.tag_name }}"
if git ls-remote --tags origin | grep -q "refs/tags/${BASE_TAG}$"; then
# Tag exists - append build number for uniqueness
UNIQUE_TAG="${BASE_TAG}.${BUILD_NUMBER}"
echo "is_duplicate=true" >> $GITHUB_OUTPUT
else
UNIQUE_TAG="$BASE_TAG"
echo "is_duplicate=false" >> $GITHUB_OUTPUT
fi
echo "unique_tag=$UNIQUE_TAG" >> $GITHUB_OUTPUT
echo "::notice::🏷️ Release tag: $UNIQUE_TAG"
env:
BUILD_NUMBER: ${{ steps.version.outputs.build_number }}
# ============================================
# JAVA & FLUTTER SETUP
# ============================================
- name: ☕ Set up Java JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'gradle'
- name: 💙 Set up Flutter SDK
uses: subosito/flutter-action@v2
with:
channel: 'stable'
cache: true
- name: ✅ Verify Flutter installation
run: flutter --version
# ============================================
# BUILD
# ============================================
- name: 📦 Get Flutter dependencies
run: flutter pub get
- name: 📝 Create .env placeholder
run: touch .env
- name: ⚙️ Generate code
run: dart run build_runner build --delete-conflicting-outputs
- name: 🔍 Run Flutter analyze
run: flutter analyze --no-fatal-infos
continue-on-error: true
- name: 🧪 Run tests
run: flutter test
continue-on-error: true
- name: 🏗️ Build release APKs
run: |
flutter build apk --release \
--split-per-abi \
--obfuscate \
--split-debug-info=build/debug-info \
--build-name=${{ steps.version.outputs.version_name }} \
--build-number=${{ steps.version.outputs.build_number }}
- name: 📋 Prepare APK files
id: apk_files
run: |
VERSION="${{ steps.version.outputs.version_name }}"
APK_DIR="build/app/outputs/flutter-apk"
# User-friendly APK names
mv "${APK_DIR}/app-arm64-v8a-release.apk" \
"${APK_DIR}/PH-Fare-Calculator-v${VERSION}-arm64.apk"
mv "${APK_DIR}/app-armeabi-v7a-release.apk" \
"${APK_DIR}/PH-Fare-Calculator-v${VERSION}-arm32.apk"
mv "${APK_DIR}/app-x86_64-release.apk" \
"${APK_DIR}/PH-Fare-Calculator-v${VERSION}-x86_64.apk"
# Set outputs
echo "apk_arm64=PH-Fare-Calculator-v${VERSION}-arm64.apk" >> $GITHUB_OUTPUT
echo "apk_arm32=PH-Fare-Calculator-v${VERSION}-arm32.apk" >> $GITHUB_OUTPUT
echo "apk_x86_64=PH-Fare-Calculator-v${VERSION}-x86_64.apk" >> $GITHUB_OUTPUT
ls -la "${APK_DIR}"/*.apk
# ============================================
# RELEASE
# ============================================
- name: 📝 Generate release notes
id: release_notes
run: |
VERSION="${{ steps.version.outputs.version_name }}"
BUILD_DATE="${{ steps.version.outputs.build_date }}"
SHORT_SHA="${{ steps.version.outputs.short_sha }}"
# Determine commit range
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
RANGE="${LAST_TAG}..HEAD"
else
RANGE="HEAD~10..HEAD"
fi
# Start building release notes
cat > RELEASE_NOTES.md << EOF
## 📱 What's New in v${VERSION}
EOF
# Get features (commits starting with ✨ or feat)
FEATURES=$(git log ${RANGE} --pretty=format:"%s" --no-merges | grep -E "^(✨|feat)" | sed -E 's/^✨ (feat[^:]*: )?//' | sed -E 's/^feat[^:]*: //' | sed 's/^/- /' | head -10)
if [ -n "$FEATURES" ]; then
echo "### ✨ New Features" >> RELEASE_NOTES.md
echo "$FEATURES" >> RELEASE_NOTES.md
echo "" >> RELEASE_NOTES.md
fi
# Get bug fixes (commits starting with 🐛 or fix)
FIXES=$(git log ${RANGE} --pretty=format:"%s" --no-merges | grep -E "^(🐛|fix)" | sed -E 's/^🐛 (fix[^:]*: )?//' | sed -E 's/^fix[^:]*: //' | sed 's/^/- /' | head -10)
if [ -n "$FIXES" ]; then
echo "### 🐛 Bug Fixes" >> RELEASE_NOTES.md
echo "$FIXES" >> RELEASE_NOTES.md
echo "" >> RELEASE_NOTES.md
fi
# Get improvements (commits with refactor emojis or keywords)
IMPROVEMENTS=$(git log ${RANGE} --pretty=format:"%s" --no-merges | grep -E "^(♻️|🎨|💄|🏗|refactor|perf)" | sed -E 's/^(♻️|🎨|💄|🏗) (refactor[^:]*: |perf[^:]*: )?//' | sed -E 's/^(refactor|perf)[^:]*: //' | sed 's/^/- /' | head -5)
if [ -n "$IMPROVEMENTS" ]; then
echo "### 🎨 Improvements" >> RELEASE_NOTES.md
echo "$IMPROVEMENTS" >> RELEASE_NOTES.md
echo "" >> RELEASE_NOTES.md
fi
# Add download guide
cat >> RELEASE_NOTES.md << EOF
---
### 📥 Download Guide
| Your Device | Recommended Download |
|-------------|---------------------|
| 🆕 Modern phones (2016+) | **arm64** - Most Android devices |
| 📱 Older phones (pre-2016) | **arm32** - Legacy devices |
| 💻 Emulators & Chromebooks | **x86_64** |
> 💡 **Tip:** Not sure? Download the **arm64** version first - it works on most devices!
---
📅 Released on ${BUILD_DATE} • Commit [\`${SHORT_SHA}\`](https://github.com/${{ github.repository }}/commit/${{ github.sha }})
EOF
cat RELEASE_NOTES.md
- name: 🚀 Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.tag_check.outputs.unique_tag }}
name: "📱 PH Fare Calculator v${{ steps.version.outputs.version_name }}"
body_path: RELEASE_NOTES.md
draft: false
prerelease: false
files: |
build/app/outputs/flutter-apk/${{ steps.apk_files.outputs.apk_arm64 }}
build/app/outputs/flutter-apk/${{ steps.apk_files.outputs.apk_arm32 }}
build/app/outputs/flutter-apk/${{ steps.apk_files.outputs.apk_x86_64 }}
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: 📊 Release summary
run: |
echo "## 🎉 Release Published!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| | |" >> $GITHUB_STEP_SUMMARY
echo "|---|---|" >> $GITHUB_STEP_SUMMARY
echo "| **Version** | v${{ steps.version.outputs.version_name }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Tag** | ${{ steps.tag_check.outputs.unique_tag }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Date** | ${{ steps.version.outputs.build_date }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "📦 [View Release](https://github.com/${{ github.repository }}/releases/tag/${{ steps.tag_check.outputs.unique_tag }})" >> $GITHUB_STEP_SUMMARY