Build Android #319
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Android | |
on: | |
workflow_dispatch: | |
inputs: | |
use-published-plugins: | |
description: 'Boolean indicating whether to use a published plugin for the Breez SDK - Native (Greenlight Implementation). Default = false.' | |
required: false | |
type: boolean | |
default: false | |
greenlight-sdk-plugin-version: | |
description: 'Version for the published Breez SDK - Native (Greenlight Implementation) plugin "v(MAJOR.MINOR.BUILD)". Defaults to latest published version on "breez/breez-sdk-flutter"' | |
required: false | |
type: string | |
default: '' | |
greenlight-sdk-ref: | |
description: 'Breez SDK - Native (Greenlight Implementation) commit/tag/branch reference when not using a published plugin. Default = "main"' | |
required: false | |
type: string | |
default: 'main' | |
jobs: | |
pre-setup: | |
name: Pre-setup | |
runs-on: ubuntu-latest | |
outputs: | |
# These outputs mimic the inputs for the workflow. | |
# Their only purpose is to be able to test this workflow if you make | |
# changes that you won't want to commit to main yet. | |
# You can set these values manually, to test how the CI behaves with | |
# certain inputs. | |
use-published-plugins: ${{ inputs.use-published-plugins }} | |
greenlight-sdk-plugin-version: ${{ inputs.greenlight-sdk-plugin-version }} | |
greenlight-sdk-ref: ${{ inputs.greenlight-sdk-ref }} | |
steps: | |
- name: Checkout repository | |
if: ${{ inputs.use-published-plugins == true && inputs.greenlight-sdk-plugin-version == ''}} | |
uses: actions/checkout@v4 | |
with: | |
repository: 'breez/breez-sdk-flutter' | |
- name: Get the latest tag and set 'greenlight-sdk-plugin-version' | |
if: ${{ inputs.use-published-plugins == true && inputs.greenlight-sdk-plugin-version == ''}} | |
run: | | |
latest_tag=$(git describe --tags `git rev-list --tags --max-count=1`) | |
echo "::set-output name=greenlight-sdk-plugin-version::$latest_tag" | |
- run: echo "set pre-setup output variables" | |
- name: Disk Cleanup | |
run: | | |
echo "::group::Free space before cleanup" | |
df -h --total | |
echo "::endgroup::" | |
echo "::group::Cleaned Files" | |
sudo rm -rf /usr/local/.ghcup | |
sudo rm -rf /opt/hostedtoolcache/CodeQL | |
sudo rm -rf /usr/local/lib/android/sdk/ndk | |
sudo rm -rf /usr/share/dotnet | |
sudo rm -rf /opt/ghc | |
sudo rm -rf /usr/local/share/boost | |
sudo apt-get clean | |
echo "::endgroup::" | |
echo "::group::Free space after cleanup" | |
df -h --total | |
echo "::endgroup::" | |
setup: | |
name: Setup | |
needs: pre-setup | |
runs-on: ubuntu-latest | |
outputs: | |
# Careful, a boolean input is not a boolean output. A boolean input is | |
# actually a boolean, but these outputs are strings. All the boolean | |
# checks in this file have the format `boolean == 'true'`. So feel free | |
# to set these variables here to `true` or `false` | |
# (e.g. bindings-windows: true) if you want to test something. | |
use-published-plugins: ${{ needs.pre-setup.outputs.use-published-plugins }} | |
greenlight-sdk-plugin-version: ${{ needs.pre-setup.outputs.greenlight-sdk-plugin-version }} | |
greenlight-sdk-ref: ${{ needs.pre-setup.outputs.greenlight-sdk-ref }} | |
steps: | |
- run: echo "set setup output variables" | |
build-android: | |
needs: setup | |
name: Build Android | |
runs-on: macOS-latest | |
steps: | |
- name: Disk Cleanup | |
run: | | |
echo "::group::Free space before cleanup" | |
df -hI | |
echo "::endgroup::" | |
echo "::group::Cleaned Files" | |
sudo rm -rf /Applications/Xcode_14.3.1.app | |
sudo rm -rf /Applications/Xcode_15.0.1.app | |
sudo rm -rf /Applications/Xcode_15.1.app | |
sudo rm -rf /Applications/Xcode_15.2.app | |
sudo rm -rf /Applications/Xcode_15.3.app | |
echo "::endgroup::" | |
echo "::group::Free space after cleanup" | |
df -hI | |
echo "::endgroup::" | |
- name: ποΈ Check-out c-breez repository | |
uses: actions/checkout@v4 | |
with: | |
path: 'cbreez' | |
- name: Set Breez SDK - Native (Greenlight Implementation) plugin version | |
if: ${{ needs.setup.outputs.use-published-plugins == 'true' }} | |
working-directory: cbreez | |
run: | | |
mv pubspec_overrides.yaml.workflow pubspec_overrides.yaml | |
sed -i.bak -e 's/ref:.*/ref: ${{ needs.setup.outputs.greenlight-sdk-plugin-version }}/' pubspec_overrides.yaml | |
rm pubspec_overrides.yaml.bak | |
- name: Decode Keystore | |
env: | |
STORE_FILE_BASE64: ${{ secrets.STORE_FILE_BASE64 }} | |
STORE_FILE: ${RUNNER_TEMP}/keystore/cbreez-release.keystore | |
run: | | |
echo "STORE_FILE=${RUNNER_TEMP}/keystore/cbreez-release.keystore" >> $GITHUB_ENV | |
echo "STORE_FILE=${RUNNER_TEMP}/keystore/cbreez-release.keystore" | |
TMP_KEYSTORE_FILE_PATH=${RUNNER_TEMP}/keystore | |
mkdir -p ${TMP_KEYSTORE_FILE_PATH} | |
echo $STORE_FILE_BASE64 | base64 -do ${TMP_KEYSTORE_FILE_PATH}/cbreez-release.keystore | |
echo "${TMP_KEYSTORE_FILE_PATH}/cbreez-release.keystore" | |
- name: Install rust | |
if: ${{ needs.setup.outputs.use-published-plugins == 'false' }} | |
run: | | |
rustup set auto-self-update disable | |
rustup toolchain install stable --profile minimal | |
- name: Install cross compilation tools | |
if: ${{ needs.setup.outputs.use-published-plugins == 'false' }} | |
run: | | |
brew tap messense/macos-cross-toolchains | |
brew install x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu | |
- name: ποΈ Setup Java | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'zulu' | |
java-version: '17' | |
- name: ποΈ Setup Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
channel: 'stable' | |
flutter-version: 3.32.1 | |
cache: true | |
- name: ποΈ Android cache | |
id: android-cache | |
uses: actions/cache@v3 | |
with: | |
path: ~/.android/debug.keystore | |
key: debug.keystore | |
- name: ποΈ Copy Firebase configuration file | |
working-directory: cbreez | |
env: | |
GOOGLE_SERVICES: ${{secrets.GOOGLE_SERVICES}} | |
run: echo "$GOOGLE_SERVICES" > android/app/google-services.json | |
- name: ποΈ Setup breez-sdk-greenlight repository | |
if: ${{ needs.setup.outputs.use-published-plugins == 'false' }} | |
uses: actions/checkout@v4 | |
with: | |
repository: 'breez/breez-sdk-greenlight' | |
ssh-key: ${{secrets.REPO_SSH_KEY}} | |
path: 'breez-sdk-greenlight' | |
ref: ${{ needs.setup.outputs.greenlight-sdk-ref }} | |
- name: ποΈ Rust cache | |
if: ${{ needs.setup.outputs.use-published-plugins == 'false' }} | |
uses: Swatinem/rust-cache@v2 | |
with: | |
workspaces: breez-sdk-greenlight/libs | |
cache-all-crates: true | |
- name: π¦ Install Breez SDK - Native (Greenlight Implementation) dependencies | |
if: ${{ needs.setup.outputs.use-published-plugins == 'false' }} | |
working-directory: breez-sdk-greenlight/libs/ | |
run: | | |
brew install protobuf | |
cd sdk-flutter | |
make init | |
cd ../sdk-bindings | |
make init | |
- name: π Install SSH Key | |
if: ${{ needs.setup.outputs.use-published-plugins == 'false' }} | |
env: | |
SSH_PRIVATE_KEY: ${{secrets.REPO_SSH_KEY}} | |
run: | | |
mkdir -p ~/.ssh | |
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa | |
sudo chmod 600 ~/.ssh/id_rsa | |
ssh-add ~/.ssh/id_rsa | |
- name: π¨ Build Breez SDK - Native (Greenlight Implementation) | |
if: ${{ needs.setup.outputs.use-published-plugins == 'false' }} | |
working-directory: breez-sdk-greenlight/libs/sdk-flutter | |
env: | |
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc | |
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: x86_64-linux-gnu-gcc | |
run: | | |
rm -rf ../target | |
cargo check | |
make android | |
- name: ποΈ Populate Flutter tool's cache of binary artifacts. | |
working-directory: cbreez | |
run: flutter precache | |
- name: π¦ Install Flutter dependencies | |
working-directory: cbreez | |
run: flutter pub get | |
- name: π Perform static analysis | |
working-directory: cbreez | |
run: dart analyze --fatal-infos | |
- name: βοΈ Setup compile-time variables | |
env: | |
CONFIG_FILE: ${{secrets.CONFIG_FILE}} | |
run: echo "$CONFIG_FILE" > ./cbreez/config.json | |
- name: Get Version from pubspec.yaml | |
working-directory: cbreez | |
run: | | |
VERSION=$(awk -F ': ' '/^version:/ {print $2}' pubspec.yaml) | |
VERSION_BASE=${VERSION%%+*} | |
BUILD_NUMBER=$(date -u +%s) | |
echo "VERSION_BASE=$VERSION_BASE" | |
echo "BUILD_NUMBER=$BUILD_NUMBER" | |
echo "VERSION_BASE=$VERSION_BASE" >> $GITHUB_ENV | |
echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITHUB_ENV | |
- name: π Build Release apk | |
env: | |
STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} | |
KEY_ALIAS: ${{ secrets.KEY_ALIAS }} | |
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} | |
working-directory: cbreez | |
run: | | |
flutter build apk \ | |
--build-name="$VERSION_BASE" \ | |
--build-number="$BUILD_NUMBER" \ | |
--release \ | |
--split-debug-info=./obsfucated/debug \ | |
--obfuscate \ | |
--no-pub \ | |
--split-per-abi \ | |
--dart-define-from-file=config.json | |
- name: π Build Release App Bundle | |
env: | |
STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} | |
KEY_ALIAS: ${{ secrets.KEY_ALIAS }} | |
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} | |
working-directory: cbreez | |
run: | | |
flutter build appbundle \ | |
--build-number="$BUILD_NUMBER" \ | |
--release \ | |
--no-pub \ | |
--dart-define-from-file="config.json" | |
- name: ποΈ Compress APK build folder | |
if: github.event_name == 'release' | |
uses: TheDoctor0/zip-release@master | |
with: | |
filename: apk-build.zip | |
directory: cbreez/build/app/outputs/flutter-apk | |
type: zip | |
- name: ποΈ Compress Bundle build folder | |
if: github.event_name == 'release' | |
uses: TheDoctor0/zip-release@master | |
with: | |
filename: bundle-build.zip | |
directory: cbreez/build/app/outputs/bundle/release | |
type: zip | |
- name: π€ Upload APK asset | |
if: github.event_name == 'release' | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
asset_name: Android-APK-${{ github.run_number }}.zip | |
file: cbreez/build/app/outputs/flutter-apk/apk-build.zip | |
overwrite: true | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: π€ Upload Bundle asset | |
if: github.event_name == 'release' | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
asset_name: Android-Bundle-${{ github.run_number }}.zip | |
file: cbreez/build/app/outputs/bundle/release/bundle-build.zip | |
overwrite: true | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: π€ Upload APK artifact | |
if: github.event_name != 'release' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Android-APK-${{ github.run_number }} | |
path: cbreez/build/app/outputs/flutter-apk/app-*.apk | |
- name: π€ Upload Bundle artifact | |
if: github.event_name != 'release' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: Android-Bundle-${{ github.run_number }} | |
path: cbreez/build/app/outputs/bundle/release/app-release.aab |