Skip to content

Commit

Permalink
CI: upload to firebase app distribution + run unittests on each commit (
Browse files Browse the repository at this point in the history
#68)

ADD CI firebase upload
ADD CI unittests
  • Loading branch information
Frank1234 authored Aug 8, 2024
1 parent 4ae5f7c commit 13975eb
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 48 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/_prepare-all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Prepare All

on:
workflow_call:

jobs:
prepare-all:
runs-on: macos-latest # use [ self-hosted, macOS ] to host on our own mac mini, which is twice as fast and cheaper than hosting on a github runner. See README for more info.
steps:
- uses: actions/checkout@v3

- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: "corretto"
java-version: "21" # keep the same as your Android Studio version
cache: "gradle"

- name: Setup Android SDK
uses: android-actions/[email protected]
16 changes: 16 additions & 0 deletions .github/workflows/_prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Prepare Release

on:
workflow_call:

jobs:
prepareRelease:
runs-on: macos-latest # use [ self-hosted, macOS ] to host on our own mac mini, which is twice as fast and cheaper than hosting on a github runner. See README for more info.
steps:
- uses: actions/checkout@v3

- name: Update Version Code # we increase the version code with each build
uses: chkfung/[email protected]
with:
gradlePath: app/build.gradle
versionCode: ${{ github.run_number }}
12 changes: 6 additions & 6 deletions .github/workflows/debug.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
name: Debug Builds

on:
workflow_dispatch:
push:
branches: [ '*' ] # run on all pushes on any branch
on: [ push ] # run on all pushes on any branch

jobs:
prepare-all:
uses: ./.github/workflows/_prepare-all.yml
build:
runs-on: macos-latest # use [ self-hosted, macOS ] to host on our own mac mini, which is twice as fast and cheaper than hosting on a github runner. See README for more info.
steps:
- uses: actions/checkout@v3
- name: Prepare build
uses: ./.github/workflows/scripts/prepare

- name: Build Debug APK
run: ./gradlew assembleDevDebug --stacktrace

- name: Run unit tests
run: ./gradlew test --stacktrace

- name: Upload Dev Debug APK to Artifacts
uses: actions/upload-artifact@v3
with:
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Release Builds

on:
workflow_dispatch:
pull_request:
branches: [ 'develop' ]

jobs:
prepare-all:
uses: ./.github/workflows/_prepare-all.yml
prepare-release:
uses: ./.github/workflows/_prepare-release.yml
build:
runs-on: macos-latest # use [ self-hosted, macOS ] to host on our own mac mini, which is twice as fast and cheaper than hosting on a github runner. See README for more info.
steps:
- uses: actions/checkout@v3

# This will decode the keystore from base 64 text representation that we have stored in secrets
# and generates and keystore file and gets stored in /android-app path
- name: Decode Keystore
env:
ENCODED_STRING: ${{ secrets.KEYSTORE_BASE_64 }}
shell: bash
run: |
echo $ENCODED_STRING > keystore-b64.txt
base64 -d <keystore-b64.txt >upload-keystore.jks
- name: Build Prod Release APK
env:
RELEASE_KEYSTORE_PASSWORD: ${{ secrets.RELEASE_KEYSTORE_PASSWORD }}
RELEASE_KEYSTORE_ALIAS: ${{ secrets.RELEASE_KEYSTORE_ALIAS }}
RELEASE_KEY_PASSWORD: ${{ secrets.RELEASE_KEY_PASSWORD }}
run: ./gradlew assembleProdRelease --stacktrace

- name: Upload Release APK to Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}-${{ github.run_number }}-prod-release-apk
path: |
${{ github.workspace }}/app/build/outputs/apk/prod/release/app-prod-release.apk
- name: Upload Prod Release APK to Firebase App Distribution
uses: nickwph/firebase-app-distribution-action@v1
with:
file: ${{ github.workspace }}/app/build/outputs/apk/prod/release/app-prod-release.apk
app: ${{ secrets.FIREBASE_PROD_APP_ID }}
credentials: ${{ secrets.FIREBASE_CREDENTIALS }}

- name: Build Prod Release Bundle
env:
RELEASE_KEYSTORE_PASSWORD: ${{ secrets.RELEASE_KEYSTORE_PASSWORD }}
RELEASE_KEYSTORE_ALIAS: ${{ secrets.RELEASE_KEYSTORE_ALIAS }}
RELEASE_KEY_PASSWORD: ${{ secrets.RELEASE_KEY_PASSWORD }}
run: ./gradlew bundleProdRelease --stacktrace

- name: Upload Release Bundle to Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}-${{ github.run_number }}-prod-release-bundle
path: |
${{ github.workspace }}/app/build/outputs/bundle/prodRelease/app-prod-release.aab
31 changes: 5 additions & 26 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,21 @@ on:
branches: [ '*' ] # run on all pull requests

jobs:
prepare-all:
uses: ./.github/workflows/_prepare-all.yml
prepare-release:
uses: ./.github/workflows/_prepare-release.yml
build:
runs-on: macos-latest # use [ self-hosted, macOS ] to host on our own mac mini, which is twice as fast and cheaper than hosting on a github runner. See README for more info.
steps:
- uses: actions/checkout@v3
- name: Prepare build
uses: ./.github/workflows/scripts/prepare

- name: Update Version Code # we increase the version code with each build
uses: chkfung/[email protected]
with:
gradlePath: app/build.gradle
versionCode: ${{ github.run_number }}

# This will decode the keystore from base 64 text representation that we have stored in secrets
# and generates and keystore file and gets stored in /android-app path
- name: Decode Keystore
env:
ENCODED_STRING: ${{ secrets.KEYSTORE_BASE_64 }}
RELEASE_KEYSTORE_PASSWORD: ${{ secrets.RELEASE_KEYSTORE_PASSWORD }}
RELEASE_KEYSTORE_ALIAS: ${{ secrets.RELEASE_KEYSTORE_ALIAS }}
RELEASE_KEY_PASSWORD: ${{ secrets.RELEASE_KEY_PASSWORD }}

shell: bash
run: |
echo $ENCODED_STRING > keystore-b64.txt
base64 -d <keystore-b64.txt >upload-keystore.jks
Expand All @@ -45,17 +38,3 @@ jobs:
name: ${{ github.event.repository.name }}-${{ github.run_number }}-prod-release-apk
path: |
${{ github.workspace }}/app/build/outputs/apk/prod/release/app-prod-release.apk
- name: Build Prod Release Bundle
env:
RELEASE_KEYSTORE_PASSWORD: ${{ secrets.RELEASE_KEYSTORE_PASSWORD }}
RELEASE_KEYSTORE_ALIAS: ${{ secrets.RELEASE_KEYSTORE_ALIAS }}
RELEASE_KEY_PASSWORD: ${{ secrets.RELEASE_KEY_PASSWORD }}
run: ./gradlew bundleProdRelease --stacktrace

- name: Upload Release Bundle to Artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ github.event.repository.name }}-${{ github.run_number }}-prod-release-bundle
path: |
${{ github.workspace }}/app/build/outputs/bundle/prodRelease/app-prod-release.aab
14 changes: 0 additions & 14 deletions .github/workflows/scripts/prepare/action.yml

This file was deleted.

15 changes: 13 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ A template for creating Android projects at Q42.
in [CI / Automated Builds](#ci--automated-builds)
1. You probably want to enable the self-hosted runner, as described
in [self hosted runner](#self-hosted-runner), when using Github Actions.
1. Setup/adjust uploads to [Firebase app distribution](#firebase-app-distribution).

## Contributing

Expand All @@ -35,8 +36,6 @@ note on changes:
template by removing the data and domain modules and calling them 'data/main' and 'domain/main',
in that way more modules can easily be added, but are not added by default.
- Research android screen transition standards + update our animations
- Github: upload to Firebase Distribution on merges to develop
- Github: run unittests on all commits
- Switch build files to KTS, also build some custom plugins.
- Use lifecycle events from Google (we use our own now)
- Use preview light dark from google (we use our own now)
Expand Down Expand Up @@ -102,6 +101,18 @@ your projects 1Password vault as well:
- RELEASE_KEYSTORE_ALIAS ('template' for this template)
- RELEASE_KEY_PASSWORD ('secondpass' for this template)

#### Firebase app distribution

We use a [firebase app github action](https://github.com/nickwph/firebase-app-distribution-action) (
in our github actions setup) to automatically upload release builds to firebase.

To change this to your own firebase project, you need to set two secrets:

- `FIREBASE_PROD_APP_ID` from your firebase project settings. It's in your firebase project
settings (for the app you want to publish), it looks something like `1:xxxxxxxxx:android:yyyyyyyy`
- `FIREBASE_CREDENTIALS` from your firebase project. More info how to obtain it can be found
in [creating a service account](https://github.com/nickwph/firebase-app-distribution-action?tab=readme-ov-file#download-credentials-from-firebase).

#### Self-hosted runner

You can run the worlkflows on our self-hosted runner (a mac mini). This is:
Expand Down

0 comments on commit 13975eb

Please sign in to comment.