Skip to content

Commit

Permalink
Merge pull request #1219 from bonomat/main
Browse files Browse the repository at this point in the history
CI Pipeline to publish to Google Play Store
  • Loading branch information
bonomat authored Sep 6, 2023
2 parents cca5aff + 362616a commit fa40ac6
Show file tree
Hide file tree
Showing 23 changed files with 658 additions and 13 deletions.
5 changes: 4 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ COORDINATOR_P2P_ENDPOINT=03507b924dae6595cfb78492489978127c5f1e3877848564de2015c
COORDINATOR_PORT_HTTP=80
NETWORK=regtest

# Fastlane variables
# Fastlane android variables
ANDROID_SERVICE_ACCOUNT_KEY=/path/to/android-service-key.json

# Fastlane ios variables
FASTLANE_DEVELOPER_APP_ID="1234567890"
FASTLANE_DEVELOPER_APP_IDENTIFIER="finance.get10101.app"
FASTLANE_PROVISIONING_PROFILE_SPECIFIER="sample"
Expand Down
187 changes: 187 additions & 0 deletions .github/workflows/android-fastlane.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
name: "Fastlane: Build and release Android App to Google Play"

on:
workflow_call:
inputs:
coordinator_port_http:
required: true
type: string
esplora_endpoint:
required: true
type: string
coordinator_p2p_endpoint:
required: true
type: string
network:
required: true
type: string
description: "The target network for the release, e.g. mainnet/regtest"
tag:
required: true
description: "The branch, tag or SHA to checkout."
type: string
oracle_endpoint:
required: true
type: string
oracle_pubkey:
required: true
description: "The public key of the oracle. Must match with the public key returned at http://${oracle_endpoint}/oracle/publickey"
type: string
workflow_dispatch:
inputs:
coordinator_port_http:
required: true
description: "The coordinator's http port"
type: string
esplora_endpoint:
required: true
description: "Esplora http url"
type: string
coordinator_p2p_endpoint:
required: true
description: "The coordinator's p2p endpoint"
type: string
network:
required: true
type: string
description: "The target network for the release, e.g. mainnet/regtest"
tag:
required: true
description: "The branch, tag or SHA to checkout."
type: string
oracle_endpoint:
required: true
description: 'The oracles http url'
type: string
oracle_pubkey:
required: true
description: "The public key of the oracle. Must match with the public key returned at http://${oracle_endpoint}/oracle/publickey"
type: string

env:
FLUTTER_VERSION: "3.10.5"

jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
with:
# fetch the complete history to correctly calculate build_number
fetch-depth: 0
ref: ${{ inputs.tag }}

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "14.2"

- uses: subosito/flutter-action@v2
with:
flutter-version: ${{ env.FLUTTER_VERSION }}
channel: "stable"
cache: true
cache-key: flutter-${{ env.FLUTTER_VERSION }}
cache-path: ${{ runner.tool_cache }}/flutter

- uses: actions/cache@v3
id: cache-deps
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
./rust/target
key: ${{ runner.os }}-cargo-build-release-android-${{ hashFiles('**/Cargo.lock') }}

- name: Install just
if: steps.cache-deps.outputs.cache-hit != 'true'
run: cargo install just

- uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: "11.x"
cache: "gradle"

- name: Install fastlane
run: |
cd mobile/android/fastlane
gem install bundler
bundle install
bundle info fastlane
- name: Install FFI bindings
if: steps.cache-deps.outputs.cache-hit != 'true'
run: just deps-gen

- name: Add Rust targets
run: rustup target add armv7-linux-androideabi aarch64-linux-android

# #499, https://github.com/actions/virtual-environments/issues/5595
- name: Configure ndk
if: steps.cache-deps.outputs.cache-hit != 'true'
run: |
ANDROID_HOME=$HOME/Library/Android/sdk
SDKMANAGER=$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager
echo y | $SDKMANAGER "ndk;21.4.7075529"
ln -sfn $ANDROID_HOME/ndk/21.4.7075529 $ANDROID_HOME/ndk-bundle
- name: Install cargo ndk
if: steps.cache-deps.outputs.cache-hit != 'true'
run: cargo install cargo-ndk

- name: Generate FFI bindings
run: just gen

- name: Build android Rust lib in release mode
run: just android-release

- name: Parse version from pubspec.yaml
id: version
uses: jbutcher5/[email protected]
with:
file: "mobile/pubspec.yaml"
key-path: '["version"]'

- name: Prepare signingkeys
env:
# secrets
FASTLANE_ANDROID_SERVICE_ACCOUNT_KEY_BASE64: ${{ secrets.FASTLANE_ANDROID_SERVICE_ACCOUNT_KEY_BASE64 }}
FASTLANE_ANDROID_UPLOAD_KEY_BASE64: ${{ secrets.FASTLANE_ANDROID_UPLOAD_KEY_BASE64 }}
FASTLANE_ANDROID_STORE_PASSWORD: ${{ secrets.FASTLANE_ANDROID_STORE_PASSWORD }}
run: |
echo "$FASTLANE_ANDROID_SERVICE_ACCOUNT_KEY_BASE64" | base64 --decode > ${{ runner.temp }}/fastlane_service_account.json
echo "$FASTLANE_ANDROID_UPLOAD_KEY_BASE64" | base64 --decode > ${{ runner.temp }}/upload-keystore.jks
upload_keystore_content="storePassword=$FASTLANE_ANDROID_STORE_PASSWORD
keyPassword=$FASTLANE_ANDROID_STORE_PASSWORD
keyAlias=upload
storeFile=${{ runner.temp }}/upload-keystore.jks"
echo "$upload_keystore_content" > "./mobile/android/key.properties"
- name: Build Android Archive
id: build-android
run: |
NETWORK=$NETWORK just build-android-app-bundle
env:
ESPLORA_ENDPOINT: ${{ inputs.esplora_endpoint }}
COORDINATOR_P2P_ENDPOINT: ${{ inputs.coordinator_p2p_endpoint }}
NETWORK: ${{ inputs.network }}
COORDINATOR_PORT_HTTP: ${{ inputs.coordinator_port_http }}
ORACLE_ENDPOINT: ${{ inputs.oracle_endpoint }}
ORACLE_PUBKEY: ${{ inputs.oracle_pubkey }}

- name: Release to Google Play Store
env:
# secrets
FASTLANE_ANDROID_SERVICE_ACCOUNT_KEY_BASE64: ${{ secrets.FASTLANE_ANDROID_SERVICE_ACCOUNT_KEY_BASE64 }}
FASTLANE_ANDROID_UPLOAD_KEY_BASE64: ${{ secrets.FASTLANE_ANDROID_UPLOAD_KEY_BASE64 }}
FASTLANE_ANDROID_STORE_PASSWORD: ${{ secrets.FASTLANE_ANDROID_STORE_PASSWORD }}
NETWORK: ${{ inputs.network }}
run: |
NETWORK=$NETWORK ANDROID_SERVICE_ACCOUNT_KEY=${{ runner.temp }}/fastlane_service_account.json just upload-app-bundle
rm ${{ runner.temp }}/fastlane_service_account.json
17 changes: 17 additions & 0 deletions .github/workflows/deliverables-push-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,20 @@ jobs:
fastlane_developer_app_identifier: finance.get10101.app.test
fastlane_provisioning_profile_specifier: match AppStore finance.get10101.app.test
app_scheme: test

build_and_release_regtest_android_app_for_latest_main:
needs: changes
if: needs.changes.outputs.ios-app == 'true'
permissions:
packages: write
contents: read
uses: ./.github/workflows/android-fastlane.yml
secrets: inherit
with:
tag: main
esplora_endpoint: http://35.189.57.114:3000
coordinator_p2p_endpoint: 03507b924dae6595cfb78492489978127c5f1e3877848564de2015cd6d41375802@35.189.57.114:9045
coordinator_port_http: 80
network: regtest
oracle_endpoint: http://api.test.10101.finance:8081
oracle_pubkey: 5d12d79f575b8d99523797c46441c0549eb0defb6195fe8a080000cbe3ab3859
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,19 @@ The app currently works only on `regtest`, which means that the wallet needs to
2. Block explorer - http://localhost:8080/
3. Lightning & Bitcoin faucet - http://localhost:8080/faucet/
4. Manually open a lightning channel - http://localhost:8080/channel/

## Deploy for android beta

1. Create a `./mobile/android/key.properties` with the content from the key generation step from here https://docs.flutter.dev/deployment/android#signing-the-app
2. `just clean` never hurts but might not be necessary ;)
3. `just gen`
4. `just android-release`
5. `NETWORK=regtest just build-android-app-bundle`
6. `NETWORK=regtest just upload-app-bundle`

TL;DR;
a shortcut for this is available but it is recommended to execute each step separately:

```bash
just release-app-bundle-regtest
```
92 changes: 88 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ android args="":
# Note that this does not include x86_64 unlike the above, as android x86_64 is only a development
# target and not a deployment target
android-release:
cd mobile/native && cargo ndk -t armeabi-v7a -t arm64-v8a -o ../android/app/src/main/jniLibs build --release
cd mobile/native && cargo ndk -t armeabi-v7a -t arm64-v8a -o ../android/app/src/main/jniLibs build --release --verbose

# Build Rust library for iOS (debug mode)
ios:
Expand Down Expand Up @@ -401,12 +401,96 @@ build-apk-regtest:
BUILD_NUMBER=$(git rev-list HEAD --count)
echo "build name: ${BUILD_NAME}"
echo "build number: ${BUILD_NUMBER}"
cd mobile && flutter build apk --build-name=${BUILD_NAME} --build-number=${BUILD_NUMBER} --release --dart-define="COMMIT=$(git rev-parse HEAD)" --dart-define="BRANCH=$(git rev-parse --abbrev-ref HEAD)" \
--dart-define="ESPLORA_ENDPOINT={{public_regtest_esplora}}" --dart-define="COORDINATOR_P2P_ENDPOINT={{public_regtest_coordinator}}" \
--dart-define="COORDINATOR_PORT_HTTP={{public_coordinator_http_port}}" --flavor demo
cd mobile && flutter build apk \
--build-name=${BUILD_NAME} \
--build-number=${BUILD_NUMBER} \
--release \
--dart-define="COMMIT=$(git rev-parse HEAD)" \
--dart-define="BRANCH=$(git rev-parse --abbrev-ref HEAD)" \
--dart-define="ESPLORA_ENDPOINT={{public_regtest_esplora}}" \
--dart-define="COORDINATOR_P2P_ENDPOINT={{public_regtest_coordinator}}" \
--dart-define="COORDINATOR_PORT_HTTP={{public_coordinator_http_port}}" --flavor demo
release-apk-regtest: gen android-release build-apk-regtest

build-app-bundle-regtest:
#!/usr/bin/env bash
BUILD_NAME=$(yq -r .version {{pubspec}})
BUILD_NUMBER=$(git rev-list HEAD --count)
echo "build name: ${BUILD_NAME}"
echo "build number: ${BUILD_NUMBER}"
cd mobile && flutter build appbundle \
--build-name=${BUILD_NAME} \
--build-number=${BUILD_NUMBER} \
--release \
--dart-define="COMMIT=$(git rev-parse HEAD)" \
--dart-define="BRANCH=$(git rev-parse --abbrev-ref HEAD)" \
--dart-define="ESPLORA_ENDPOINT={{public_regtest_esplora}}" \
--dart-define="COORDINATOR_P2P_ENDPOINT={{public_regtest_coordinator}}" \
--dart-define="COORDINATOR_PORT_HTTP={{public_coordinator_http_port}}" \
--flavor demo

build-android-app-bundle:
#!/usr/bin/env bash
BUILD_NAME=$(yq -r .version {{pubspec}})
BUILD_NUMBER=$(git rev-list HEAD --count)
echo "build name: ${BUILD_NAME}"
echo "build number: ${BUILD_NUMBER}"
regtest_args=()
ANDROID_PACKAGE_NAME='finance.get10101.app';
if [ "$NETWORK" = "regtest" ]; then
regtest_args+=(--flavor demo)
ANDROID_PACKAGE_NAME='finance.get10101.app.demo';
else
regtest_args+=(--flavor full)
fi

# Replacing package id using the env variable.
os={{os()}}
echo "building on '$os' for '$NETWORK' and package id '$ANDROID_PACKAGE_NAME'"
if [ "$os" = "linux" ]; then
sed -i "s/\"finance\.get10101\.app\"/\"${ANDROID_PACKAGE_NAME}\"/g" mobile/android/app/google-services.json
elif [ "$os" = "macos" ]; then
sed -i '' "s/\"finance\.get10101\.app\"/\"$ANDROID_PACKAGE_NAME\"/g" mobile/android/app/google-services.json
else
echo "Only Linux and macOS are supported."
exit 1
fi
cat mobile/android/app/google-services.json | jq 'recurse | select(type == "object" and (.bundle_id or .package_name))'

cd mobile && flutter build appbundle \
--build-name=${BUILD_NAME} \
--build-number=${BUILD_NUMBER} \
--release \
--dart-define="ESPLORA_ENDPOINT=${ESPLORA_ENDPOINT}" \
--dart-define="COORDINATOR_P2P_ENDPOINT=${COORDINATOR_P2P_ENDPOINT}" \
--dart-define="NETWORK=${NETWORK}" \
--dart-define="COMMIT=$(git rev-parse HEAD)" \
--dart-define="BRANCH=$(git rev-parse --abbrev-ref HEAD)" \
--dart-define="COORDINATOR_PORT_HTTP=${COORDINATOR_PORT_HTTP}" \
--dart-define="ORACLE_ENDPOINT=${ORACLE_ENDPOINT}" \
--dart-define="ORACLE_PUBKEY=${ORACLE_PUBKEY}" \
"${regtest_args[@]}"

upload-app-bundle:
#!/usr/bin/env bash
cd mobile/android/fastlane

ANDROID_PACKAGE_NAME='finance.get10101.app';
FASTLANE_ANDROID_APP_SCHEME='full'
if [ "$NETWORK" = "regtest" ]; then
ANDROID_PACKAGE_NAME='finance.get10101.app.demo';
FASTLANE_ANDROID_APP_SCHEME='demo';
fi
echo $NETWORK
echo $ANDROID_PACKAGE_NAME
FASTLANE_ANDROID_APP_SCHEME=${FASTLANE_ANDROID_APP_SCHEME} ANDROID_PACKAGE_NAME=${ANDROID_PACKAGE_NAME} bundle exec fastlane alpha

release-app-bundle-regtest: gen android-release build-app-bundle-regtest upload-app-bundle

# Run prometheus for local debugging (needs it installed, e.g. `brew install prometheus`)
prometheus:
#!/usr/bin/env bash
Expand Down
6 changes: 6 additions & 0 deletions mobile/android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ GeneratedPluginRegistrant.java
key.properties
**/*.keystore
**/*.jks

# Fastlane keys
fastlane/key.json
## autogenerated stuff
fastlane/report.xml
fastlane/README.md
3 changes: 3 additions & 0 deletions mobile/android/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gem "fastlane"
Loading

0 comments on commit fa40ac6

Please sign in to comment.