Files
FocusGram-Android/.github/workflows/release-apk.yml
T

153 lines
5.1 KiB
YAML

name: Build APK and Create GitHub Release
on:
workflow_dispatch:
inputs:
version:
description: "Release version without leading v. Example: 2.1.0. Leave empty to read the top CHANGELOG heading."
required: false
type: string
push:
tags:
- "v*.*.*"
permissions:
contents: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Java 21
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "21"
- name: Set up Android SDK
uses: android-actions/setup-android@v4
- name: Install required Android SDK packages
shell: bash
run: |
set -euo pipefail
sdkmanager \
"platform-tools" \
"platforms;android-35" \
"build-tools;35.0.0"
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: wrapper
cache-read-only: false
- name: Grant execute permission for gradlew
shell: bash
run: chmod +x gradlew
- name: Resolve version and tag
id: meta
shell: bash
run: |
set -euo pipefail
if [[ "${GITHUB_REF:-}" == refs/tags/* ]]; then
TAG="${GITHUB_REF#refs/tags/}"
VERSION="${TAG#v}"
elif [[ -n "${{ github.event.inputs.version }}" ]]; then
VERSION="${{ github.event.inputs.version }}"
VERSION="${VERSION#v}"
TAG="v${VERSION}"
else
VERSION="$(python3 .github/scripts/get_version.py)"
TAG="v${VERSION}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
- name: Extract release notes from CHANGELOG.md
shell: bash
env:
VERSION: ${{ steps.meta.outputs.version }}
run: python3 .github/scripts/get_notes.py
- name: Run Unit Tests
run: ./gradlew :app:testDebugUnitTest --no-daemon
- name: Setup Android release signing keystore
shell: bash
env:
KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD || secrets.KEYSTORE_PASSWORD }}
KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD || secrets.KEY_PASSWORD }}
KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS || secrets.KEY_ALIAS }}
run: |
set -euo pipefail
if [ -n "${KEYSTORE_BASE64:-}" ]; then
echo "Decoding Android release keystore from secrets..."
echo "${KEYSTORE_BASE64}" | tr -d '[:space:]' | base64 --decode > upload-keystore.jks
chmod 600 upload-keystore.jks
KS_PASS="$(printf '%s' "${KEYSTORE_PASSWORD:-}" | tr -d '[:space:]')"
K_PASS="$(printf '%s' "${KEY_PASSWORD:-}" | tr -d '[:space:]')"
K_ALIAS="$(printf '%s' "${KEY_ALIAS:-}" | tr -d '[:space:]')"
KEYSTORE_PATH="${GITHUB_WORKSPACE}/upload-keystore.jks"
{
printf 'storePassword=%s\n' "${KS_PASS}"
printf 'keyPassword=%s\n' "${K_PASS}"
printf 'keyAlias=%s\n' "${K_ALIAS}"
printf 'storeFile=%s\n' "${KEYSTORE_PATH}"
} > key.properties
echo "Release keystore configured: $(wc -c < upload-keystore.jks) bytes"
else
echo "::warning::ANDROID_KEYSTORE_BASE64 secret not found. Release build will fall back to debug signing."
fi
- name: Build release APKs (with ABI splits)
run: ./gradlew :app:assembleRelease --no-daemon
- name: Display Generated APKs
shell: bash
run: |
echo "=== Built Release APKs ==="
ls -lh app/build/outputs/apk/release/*.apk
- name: Upload APK artifacts
uses: actions/upload-artifact@v4
with:
name: focusgram-apk-${{ steps.meta.outputs.tag }}
path: app/build/outputs/apk/release/*.apk
if-no-files-found: error
- name: Create Git tag (workflow_dispatch only)
shell: bash
if: github.event_name == 'workflow_dispatch'
env:
TAG: ${{ steps.meta.outputs.tag }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
if ! git ls-remote --exit-code --tags origin "refs/tags/${TAG}" >/dev/null 2>&1; then
git tag -a "${TAG}" -m "Release ${TAG}"
git push origin "${TAG}"
else
echo "Tag ${TAG} already exists on remote."
fi
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.meta.outputs.tag }}
name: FocusGram ${{ steps.meta.outputs.tag }}
body_path: release_notes.md
files: app/build/outputs/apk/release/*.apk
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}