Skip to content

Commit

Permalink
add firebase upload for Android
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas7morgen committed Sep 16, 2024
1 parent 7d1b2fe commit d539b13
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 0 deletions.
1 change: 1 addition & 0 deletions .flutter
Submodule .flutter added at 266318
84 changes: 84 additions & 0 deletions .github/workflows/sprint_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# This workflow builds the release variants for Android and iOS, uploads them to a new release
# and distributes them via firebase
# It is triggered by the creation of a sprint release tag
# Please note that the KeyStore credentials have to be created as secrets in your project
# For more information about best practices, see:
# https://grandcentrix.atlassian.net/wiki/spaces/TENG/pages/31180230199/GitHub+Actions+Best+Practices

name: Build Sprint Release

on:
push:
tags:
- 'release/sprint*'

jobs:
build_sprint_release_android:
name: Build Sprint Release Android
runs-on: ubuntu-latest
outputs:
version-name: ${{ steps.version.outputs.version-name }}
timeout-minutes: 60
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Enable private dependencies
run: git config --global url."https://${{ github.actor }}:${{ secrets.REPO_READ_TOKEN }}@github.com/".insteadOf "[email protected]:"
- name: Cache dart packages
uses: actions/[email protected]
with:
path: |
/opt/hostedtoolcache/flutter
~/.pub-cache
key: ${{ runner.os }}-flutter-android
- name: Accept Android licenses
run: yes | ${ANDROID_HOME}/tools/bin/sdkmanager --licenses
- name: Run Flutter doctor
run: ./flutterw doctor --verbose
timeout-minutes: 10
- name: Get Dart packages
run: ./flutterw pub get
timeout-minutes: 10
- name: Get version name for release name
id: version
run: |
pubspecVersion=$(cat pubspec.yaml | grep 'version\:\ ' | sed -e "s/^.*[[:blank:]]//" -e "s/^\"//" -e "s/\"$//")
sprintNumber=${GITHUB_REF#refs/*/release/*}
echo "::set-output name=version-name::$pubspecVersion-$sprintNumber"
- name: Build Release
run: ./flutterw build apk --release --build-number=${{ github.run_number }} --build-name=${{ steps.version.outputs.version-name }} --target=lib/main.dart
timeout-minutes: 20
- name: Upload workflow artifact
uses: actions/upload-artifact@v2
with:
name: apk
path: "build/app/outputs/flutter-apk/app-release.apk"

release_n_upload:
name: Release and upload to Firebase
runs-on: ubuntu-latest
timeout-minutes: 10
needs:
- build_sprint_release_android
steps:
- name: Download workflow artifacts
uses: actions/download-artifact@v2
with:
path: artifacts
- name: Create GitHub release
id: github_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
name: Sprint Release ${{needs.build_sprint_release_android.outputs.version-name}}
files: "**/artifacts/**"
prerelease: true
- name: Upload Android app to Firebase
uses: wzieba/[email protected]
with:
appId: ${{secrets.FIREBASE_ANDROID_APP_ID}}
token: ${{secrets.FIREBASE_TOKEN}}
file: artifacts/apk/app-release.apk
groups: gcx
releaseNotes: Sprint Release ${{needs.build_sprint_release_android.outputs.version-name}}
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[submodule ".flutter"]
path = .flutter
url = https://github.com/flutter/flutter.git
branch = stable

[submodule "nrf_mesh_plugin"]
path = nrf_mesh_plugin
url = https://github.com/OZEO-DOOZ/nrf_mesh_plugin
branch = feature/vendor_model_message
9 changes: 9 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ android {
versionName = flutter.versionName
}

signingConfigs {
debug {
storeFile file("../debug.jks")
storePassword "grandcentrix"
keyAlias "grandcentrix"
keyPassword "grandcentrix"
}
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
Expand Down
113 changes: 113 additions & 0 deletions flutterw
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/usr/bin/env sh

##############################################################################
##
## Flutter start up script for UN*X
## Version: v1.3.1
## Date: 2024-09-16 15:37:42
##
## Use this flutter wrapper to bundle Flutter within your project to make
## sure everybody builds with the same version.
##
## Read about the install and uninstall process in the README on GitHub
## https://github.com/passsy/flutter_wrapper
##
## Inspired by gradle-wrapper.
##
##############################################################################

echoerr() { echo "$@" 1>&2; }

# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ]; do
ls=$(ls -ld "$PRG")
link=$(expr "$ls" : '.*-> \(.*\)$')
if expr "$link" : '/.*' >/dev/null; then
PRG="$link"
else
PRG=$(dirname "$PRG")"/$link"
fi
done
SAVED="$(pwd)"
cd "$(dirname "$PRG")/" >/dev/null
APP_HOME="$(pwd -P)"
cd "$SAVED" >/dev/null

FLUTTER_SUBMODULE_NAME='.flutter'
GIT_HOME=$(git -C "${APP_HOME}" rev-parse --show-toplevel)
FLUTTER_DIR="${GIT_HOME}/${FLUTTER_SUBMODULE_NAME}"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

# Fix not initialized flutter submodule
if [ ! -f "${FLUTTER_DIR}/bin/flutter" ]; then
echoerr "$FLUTTER_SUBMODULE_NAME submodule not initialized. Initializing..."
git submodule update --init "${FLUTTER_DIR}"
fi

# Detect detach HEAD and fix it. commands like upgrade expect a valid branch, not a detached HEAD
FLUTTER_SYMBOLIC_REF=$(git -C "${FLUTTER_DIR}" symbolic-ref -q HEAD)
if [ -z "${FLUTTER_SYMBOLIC_REF}" ]; then
FLUTTER_REV=$(git -C "${FLUTTER_DIR}" rev-parse HEAD)
FLUTTER_CHANNEL=$(git -C "${GIT_HOME}" config -f .gitmodules submodule.${FLUTTER_SUBMODULE_NAME}.branch)

if [ -z "${FLUTTER_CHANNEL}" ]; then
echoerr "Warning: Submodule '$FLUTTER_SUBMODULE_NAME' doesn't point to an official Flutter channel \
(one of stable|beta|dev|master). './flutterw upgrade' will fail without a channel."
echoerr "Fix this by adding a specific channel with:"
echoerr " - './flutterw channel <channel>' or"
echoerr " - Add 'branch = <channel>' to '$FLUTTER_SUBMODULE_NAME' submodule in .gitmodules"
else
echoerr "Fixing detached HEAD: '$FLUTTER_SUBMODULE_NAME' submodule points to a specific commit $FLUTTER_REV, not channel '$FLUTTER_CHANNEL' (as defined in .gitmodules)."
# Make sure channel is fetched
# Remove old channel branch because it might be moved to an unrelated commit where fast-forward pull isn't possible
git -C "${FLUTTER_DIR}" branch -q -D "${FLUTTER_CHANNEL}" 2> /dev/null || true
git -C "${FLUTTER_DIR}" fetch -q origin

# bind current HEAD to channel defined in .gitmodules
git -C "${FLUTTER_DIR}" checkout -q -b "${FLUTTER_CHANNEL}" "${FLUTTER_REV}"
git -C "${FLUTTER_DIR}" branch -q -u "origin/${FLUTTER_CHANNEL}" "${FLUTTER_CHANNEL}"
echoerr "Fixed! Migrated to channel '$FLUTTER_CHANNEL' while staying at commit $FLUTTER_REV. './flutterw upgrade' now works without problems!"
git -C "${FLUTTER_DIR}" status -bs
fi
fi

# Wrapper tasks done, call flutter binary with all args
set -e
"$FLUTTER_DIR/bin/flutter" "$@"
set +e

# Post flutterw tasks. exit code from /bin/flutterw will be used as final exit
FLUTTER_EXIT_STATUS=$?
if [ ${FLUTTER_EXIT_STATUS} -eq 0 ]; then

# ./flutterw channel CHANNEL
if echo "$@" | grep -q "channel"; then
if [ -n "$2" ]; then
# make sure .gitmodules is updated as well
CHANNEL=${2} # second arg
git config -f "${GIT_HOME}/.gitmodules" "submodule.${FLUTTER_SUBMODULE_NAME}.branch" "${CHANNEL}"
# makes sure nobody forgets to do commit all changed files
git add "${GIT_HOME}/.gitmodules"
git add "${FLUTTER_DIR}"
fi
fi

# ./flutterw upgrade
if echo "$@" | grep -q "upgrade"; then
# makes sure nobody forgets to do commit the changed submodule
git add "${FLUTTER_DIR}"
# flutter packages get runs automatically. Stage those changes as well
if [ -f pubspec.lock ]; then
git add pubspec.lock
fi
fi
fi

exit ${FLUTTER_EXIT_STATUS}

0 comments on commit d539b13

Please sign in to comment.