Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions .github/workflows/android-ci.yml

This file was deleted.

187 changes: 187 additions & 0 deletions .github/workflows/build_apk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
name: Build Signed Release APK & Play Store AAB

on:
push:
branches: [ main, master ]
workflow_dispatch:
inputs:
version_name:
description: 'Version Name (e.g. 1.0.2 - leave empty for auto 1.0.X)'
required: false
default: ''
version_code:
description: 'Version Code (Integer, e.g. 12 - leave blank for auto increment)'
required: false
default: ''

permissions:
contents: write

jobs:
build:
name: Build & Sign APK & AAB
runs-on: ubuntu-latest

steps:
- name: Checkout Source Code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Java 17 (JDK)
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Make Gradle Wrapper Executable
run: chmod +x ./gradlew

- name: Determine Version Code and Name
id: versioning
run: |
if [ -n "${{ inputs.version_code }}" ]; then
V_CODE="${{ inputs.version_code }}"
else
# Uses github.run_number directly so each build automatically increments (1, 2, 3...)
V_CODE="${{ github.run_number }}"
fi

if [ -n "${{ inputs.version_name }}" ]; then
V_NAME="${{ inputs.version_name }}"
else
# Auto-incrementing version name based on version code
V_NAME="1.0.${V_CODE}"
fi

echo "Determined Version Code: $V_CODE"
echo "Determined Version Name: $V_NAME"
echo "v_code=$V_CODE" >> $GITHUB_OUTPUT
echo "v_name=$V_NAME" >> $GITHUB_OUTPUT


- name: Build Release APK, Debug APK and AAB Bundle with Gradle
run: |
./gradlew assembleRelease assembleDebug bundleRelease \
-PversionCode=${{ steps.versioning.outputs.v_code }} \
-PversionName=${{ steps.versioning.outputs.v_name }} \
--no-daemon

- name: Sign Release APK & AAB
env:
KEYSTORE_BASE64: ${{ secrets.RELEASE_KEYSTORE_BASE64 }}
KEYSTORE_PASS: ${{ secrets.KEYSTORE_PASSWORD || 'android123' }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS || '' }}
KEY_PASS: ${{ secrets.KEY_PASSWORD || 'android123' }}
V_NAME: ${{ steps.versioning.outputs.v_name }}
run: |
echo "Locating generated Release APK, Debug APK, and AAB..."
UNSIGNED_APK=$(find app/build/outputs/apk/release/ -name "*.apk" | head -n 1)
DEBUG_APK=$(find app/build/outputs/apk/debug/ -name "*.apk" | head -n 1)
UNSIGNED_AAB=$(find app/build/outputs/bundle/release/ -name "*.aab" | head -n 1)

mkdir -p output_release

# 0. Copy Debug APK directly (already signed with debug keystore)
if [ -n "$DEBUG_APK" ]; then
cp "$DEBUG_APK" output_release/BansifyBrowser-v${V_NAME}-Debug.apk
echo "Successfully included Debug APK: output_release/BansifyBrowser-v${V_NAME}-Debug.apk"
fi

# Store keystore in secure temporary location outside release outputs
KS_PATH="/tmp/bansify_release_key.jks"

if [ -n "$KEYSTORE_BASE64" ]; then
echo "Using Permanent Keystore from GitHub Secrets..."
echo "$KEYSTORE_BASE64" | tr -d '\r\n ' | base64 -d > "$KS_PATH"
if ! keytool -list -keystore "$KS_PATH" -storepass "$KEYSTORE_PASS" > /tmp/kt_diag.log 2>&1; then
echo "⚠️ WARNING: keytool failed to verify keystore with provided password!"
cat /tmp/kt_diag.log
fi
else
echo "⚠️ No GitHub Secret found! Generating temporary keystore..."
DEFAULT_ALIAS="${KEY_ALIAS:-bansify_key}"
keytool -genkey -v \
-keystore "$KS_PATH" \
-keyalg RSA -keysize 2048 -validity 10000 \
-alias "$DEFAULT_ALIAS" \
-dname "CN=Bansify Browser, O=Bansify, C=IN" \
-storepass "$KEYSTORE_PASS" -keypass "$KEY_PASS"
fi

# Dynamically detect exact Alias name from the keystore
DETECTED_ALIAS=$(keytool -list -v -keystore "$KS_PATH" -storepass "$KEYSTORE_PASS" 2>/dev/null | grep -i "Alias name:" | head -n 1 | sed 's/.*Alias name: //I' | tr -d '\r' | xargs)

if [ -n "$KEY_ALIAS" ]; then
ACTUAL_ALIAS="$KEY_ALIAS"
elif [ -n "$DETECTED_ALIAS" ]; then
ACTUAL_ALIAS="$DETECTED_ALIAS"
else
ACTUAL_ALIAS="bansify_key"
fi

echo "Using Keystore Alias: $ACTUAL_ALIAS"

# Find latest zipalign and apksigner dynamically
ZIPALIGN=$(find $ANDROID_HOME/build-tools/ -name "zipalign" | sort -V | tail -n 1)
APKSIGNER=$(find $ANDROID_HOME/build-tools/ -name "apksigner" | sort -V | tail -n 1)

# 1. Sign APK
if [ -n "$UNSIGNED_APK" ]; then
UNALIGNED_TEMP="/tmp/unaligned_temp.apk"
if [ -n "$ZIPALIGN" ]; then
$ZIPALIGN -v -p 4 "$UNSIGNED_APK" "$UNALIGNED_TEMP" || cp "$UNSIGNED_APK" "$UNALIGNED_TEMP"
else
cp "$UNSIGNED_APK" "$UNALIGNED_TEMP"
fi

$APKSIGNER sign \
--ks "$KS_PATH" \
--ks-key-alias "$ACTUAL_ALIAS" \
--ks-pass "pass:$KEYSTORE_PASS" \
--key-pass "pass:$KEY_PASS" \
--out output_release/BansifyBrowser-v${V_NAME}-Release.apk \
"$UNALIGNED_TEMP"

$APKSIGNER verify --verbose output_release/BansifyBrowser-v${V_NAME}-Release.apk
rm -f "$UNALIGNED_TEMP"
fi

# 2. Sign Play Store AAB Bundle using jarsigner
if [ -n "$UNSIGNED_AAB" ]; then
cp "$UNSIGNED_AAB" output_release/BansifyBrowser-v${V_NAME}-PlayStore.aab
jarsigner -verbose -sigalg SHA256withRSA -digestalg SHA-256 \
-keystore "$KS_PATH" \
-storepass "$KEYSTORE_PASS" -keypass "$KEY_PASS" \
output_release/BansifyBrowser-v${V_NAME}-PlayStore.aab \
"$ACTUAL_ALIAS"
echo "Successfully signed Play Store AAB!"
fi

# Securely destroy the temporary keystore file so it is never exposed or uploaded
rm -f "$KS_PATH"
echo "Keystore securely cleaned up."




- name: Upload signed release APK, debug APK and Play Store AAB
uses: actions/upload-artifact@v4
with:
name: Bansify-Browser-v${{ steps.versioning.outputs.v_name }}-Build${{ steps.versioning.outputs.v_code }}
path: output_release/

- name: Create Automatic GitHub Release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.versioning.outputs.v_name }}
name: v${{ steps.versioning.outputs.v_name }}
draft: false
prerelease: false
generate_release_notes: true
files: |
output_release/BansifyBrowser-v${{ steps.versioning.outputs.v_name }}-Release.apk
output_release/BansifyBrowser-v${{ steps.versioning.outputs.v_name }}-Debug.apk
output_release/BansifyBrowser-v${{ steps.versioning.outputs.v_name }}-PlayStore.aab
135 changes: 135 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Quality Gate & Tests

# The release pipeline (build_apk.yml) only runs on main and only builds. This workflow is the
# cheap, always-on half: the mechanical AGENTS.md rules, the JVM unit tests, and a compile so a
# PR can never land something that does not even build.

on:
pull_request:
push:
branches: [ main, master ]
workflow_dispatch:

permissions:
contents: read

concurrency:
group: quality-${{ github.ref }}
cancel-in-progress: true

jobs:
rules:
name: AGENTS.md rules (grep gate)
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

# No JDK, no SDK: this is the feedback loop that should answer in seconds.
- name: Run quality gate
run: |
set -e
fail=0
echo "Package must be com.bansify.browser everywhere."
if grep -rn "com\.example" app/src app/build.gradle.kts 2>/dev/null; then
echo "::error::Found com.example in the tree"
fail=1
fi
grep -q 'namespace = "com.bansify.browser"' app/build.gradle.kts \
|| { echo "::error::namespace must be com.bansify.browser"; fail=1; }
grep -q 'applicationId = "com.bansify.browser"' app/build.gradle.kts \
|| { echo "::error::applicationId must be com.bansify.browser"; fail=1; }
for f in gradlew app/build.gradle.kts settings.gradle.kts \
app/src/main/AndroidManifest.xml app/src/main/res/values/strings.xml; do
[ -f "$f" ] || { echo "::error::missing required file $f"; fail=1; }
done
echo "Quality gate finished with status $fail"
exit $fail

test:
name: Unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Make Gradle Wrapper Executable
run: chmod +x ./gradlew

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: ${{ github.ref != 'refs/heads/main' }}

- name: Unit tests (app + common)
run: |
set -o pipefail
./gradlew :app:testDebugUnitTest --no-daemon --continue --stacktrace 2>&1 | tee gradle.log

# The raw log lives behind an endpoint a sandboxed runner often cannot reach, and a red X
# with no message teaches nobody anything: put the useful lines in the job summary.
- name: Publish the failure in the job summary
if: failure()
run: |
{
echo "### Gradle failure (last 80 lines)"
echo '```'
tail -n 80 gradle.log 2>/dev/null || echo "no gradle.log"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"

build:
name: Compile (debug) + Android lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Make Gradle Wrapper Executable
run: chmod +x ./gradlew

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Set up Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: ${{ github.ref != 'refs/heads/main' }}

# Debug builds use the default ~/.android/debug.keystore that AGP creates on first use,
# so no keystore step is needed here.
- name: Compile debug
run: |
set -o pipefail
./gradlew :app:assembleDebug --no-daemon --continue --stacktrace 2>&1 | tee gradle.log

- name: Publish the failure in the job summary
if: failure()
run: |
{
echo "### Gradle failure (last 80 lines)"
echo '```'
tail -n 80 gradle.log 2>/dev/null || echo "no gradle.log"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"

- name: Android lint
continue-on-error: true
run: ./gradlew :app:lintDebug --no-daemon

- name: Upload lint report
if: always()
uses: actions/upload-artifact@v4
with:
name: lint-report
path: app/build/reports/lint-results-*.html
if-no-files-found: ignore
Loading
Loading