Skip to content

Build and Release APKs #15

Build and Release APKs

Build and Release APKs #15

Workflow file for this run

name: Build and Release APKs
on:
release:
types: [created]
jobs:
build-and-release:
name: Build and Release Android APKs
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: 'stable'
cache: true
cache-key: 'flutter-:os:-:channel:-:version:-:arch:-:hash:'
cache-path: '${{ runner.tool_cache }}/flutter/:channel:-:version:-:arch:'
- name: Decode and install Keystore
# This step now runs always, but the script inside is conditional.
# We pass the secrets to environment variables.
env:
KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }}
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
run: |
# Use a shell 'if' to check if the secret env var is populated.
if [ -n "$KEYSTORE_BASE64" ]; then
echo "Keystore secret found, creating keystore and properties files."
# Decode the base64 secret and create the keystore file
echo "$KEYSTORE_BASE64" | base64 --decode > ${{ github.workspace }}/android/app/upload-keystore.jks
# Create the key.properties file with the other secrets
echo "storeFile=${{ github.workspace }}/android/app/upload-keystore.jks" > ${{ github.workspace }}/android/key.properties
echo "keyAlias=$KEY_ALIAS" >> ${{ github.workspace }}/android/key.properties
echo "storePassword=$STORE_PASSWORD" >> ${{ github.workspace }}/android/key.properties
echo "keyPassword=$KEY_PASSWORD" >> ${{ github.workspace }}/android/key.properties
else
echo "Keystore secret not found. Skipping app signing."
fi
- name: Get Flutter dependencies
run: flutter pub get
- name: Run Flutter analyze
run: |
echo "Running Flutter analyze to catch compilation errors early..."
flutter analyze --fatal-infos
echo "Analysis completed successfully!"
- name: Run tests
run: |
echo "Running Flutter tests..."
flutter test
echo "Tests completed successfully!"
- name: Update pubspec version
run: |
# Extract version from tag (e.g., v1.2.3 -> 1.2.3, also handles 1.2.3)
TAG_VERSION=$(echo "$GITHUB_REF_NAME" | sed 's/^v//')
# Fix: If version is format 1.2, append .0 to make it 1.2.0
if [[ "$TAG_VERSION" =~ ^[0-9]+\.[0-9]+$ ]]; then
TAG_VERSION="${TAG_VERSION}.0"
echo "Formatted version to semantic version: $TAG_VERSION"
fi
# Validate version format
if [[ ! "$TAG_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Invalid version format: $TAG_VERSION"
echo "Expected semantic version format (e.g., 1.2.3)"
exit 1
fi
# Use run_number as build number
BUILD_NUMBER=${{ github.run_number }}
# Update version in pubspec.yaml
sed -i "s/^version: .*/version: ${TAG_VERSION}+${BUILD_NUMBER}/" pubspec.yaml
echo "Updated version to: $TAG_VERSION+$BUILD_NUMBER"
grep "^version:" pubspec.yaml
- name: Build all APKs
run: |
flutter build apk --release
flutter build apk --split-per-abi --release
- name: Prepare Release Artifacts
run: |
mkdir release-artifacts
mv build/app/outputs/flutter-apk/app-release.apk release-artifacts/openlib-extended-universal-release.apk
mv build/app/outputs/flutter-apk/app-arm64-v8a-release.apk release-artifacts/openlib-extended-arm64-v8a-release.apk
mv build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk release-artifacts/openlib-extended-armeabi-v7a-release.apk
- name: Upload Release Assets
uses: softprops/action-gh-release@v1
with:
files: release-artifacts/*.apk
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}