Test and Deploy #28
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
## 1 | |
name: Test and Deploy | |
## Actions that will be executed when you push code currently none | |
on: | |
workflow_dispatch: | |
inputs: | |
semver: | |
description: 'Release Semantic Versioning (e.g. 4.15.2)' | |
required: true | |
track: | |
description: 'Track' | |
required: true | |
default: internal | |
type: choice | |
options: | |
- internal | |
- alpha | |
- beta | |
- production | |
## 2 | |
jobs: | |
## 3 | |
unit_tests: | |
name: Unit tests | |
runs-on: [ubuntu-latest] | |
timeout-minutes: 20 | |
env: | |
TERM: dumb | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Setup JDK | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'adopt' | |
java-version: 17.0.6 | |
- name: Copy CI gradle.properties | |
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties | |
- name: Validate gradle wrapper | |
uses: gradle/wrapper-validation-action@v1 | |
- name: Build | |
uses: gradle/gradle-build-action@v2 | |
with: | |
arguments: assembleDebug -PsaveBuildLogToFile=true | |
- name: Unit tests | |
uses: gradle/gradle-build-action@v2 | |
with: | |
arguments: testDebugUnitTest | |
## 4 | |
instrumentation_tests: | |
name: Instrumentation tests | |
# Android emulators require hardware acceleration (HAXM on Mac & Windows, QEMU on Linux) from the host to run fast. | |
# The macOS VM provided by GitHub Actions is the only one that currently supports it. | |
runs-on: macos-13 | |
timeout-minutes: 45 | |
env: | |
JAVA_TOOL_OPTIONS: -Xmx4g | |
TERM: dumb | |
strategy: | |
# Allow tests to continue on other devices if they fail on one device. | |
fail-fast: false | |
matrix: | |
api-level: [29, 33] | |
target: [google_apis] | |
arch: [arm64-v8a] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Setup JDK | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'adopt' | |
java-version: 17.0.6 | |
- name: Copy CI gradle.properties | |
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties | |
- name: Validate gradle wrapper | |
uses: gradle/wrapper-validation-action@v1 | |
- name: AVD cache | |
uses: actions/cache@v2 | |
id: avd-cache | |
with: | |
path: | | |
~/.android/avd/* | |
~/.android/adb* | |
~/.android/debug.keystore | |
key: avd-${{ matrix.api-level }}-${{ matrix.arch }}-${{ matrix.target }} | |
- name: Assemble Android tests | |
uses: gradle/gradle-build-action@v2 | |
with: | |
arguments: assembleAndroidTest | |
- name: Run emulator to generate snapshot for caching | |
if: steps.avd-cache.outputs.cache-hit != 'true' | |
uses: reactivecircus/android-emulator-runner@v2 | |
with: | |
api-level: ${{ matrix.api-level }} | |
target: ${{ matrix.target }} | |
arch: ${{ matrix.arch }} | |
profile: Galaxy Nexus | |
cores: 2 | |
sdcard-path-or-size: 100M | |
avd-name: api${{ matrix.api-level }}-${{ matrix.arch }}-${{ matrix.target }} | |
force-avd-creation: false | |
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none | |
disable-animations: false | |
channel: stable | |
script: echo "Generated AVD snapshot for caching." | |
## Actual task | |
- name: Run Android tests on API ${{ matrix.api-level }} / ${{ matrix.arch }} / ${{ matrix.target }} | |
uses: reactivecircus/android-emulator-runner@v2 | |
with: | |
api-level: ${{ matrix.api-level }} | |
target: ${{ matrix.target }} | |
arch: ${{ matrix.arch }} | |
profile: Galaxy Nexus | |
cores: 2 | |
ram-size: 2048M | |
sdcard-path-or-size: 100M | |
avd-name: api${{ matrix.api-level }}-${{ matrix.arch }}-${{ matrix.target }} | |
force-avd-creation: false | |
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none | |
disable-animations: true | |
channel: stable | |
script: | | |
echo $GITHUB_REPOSITORY | |
adb devices | |
./gradlew connectedCheck | |
build: | |
needs: [unit_tests, instrumentation_tests] | |
runs-on: ubuntu-latest | |
steps: | |
# 1 | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Create release tag | |
uses: actions/github-script@v5 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: "refs/tags/${{ github.event.inputs.semver }}", | |
sha: context.sha | |
}) | |
- name: Workaround to fetch the tag # Is there a better way to do it? | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
# 2 | |
- name: Generate Release APK | |
run: ./gradlew assembleRelease | |
# 3 | |
- name: Sign APK | |
uses: r0adkll/sign-android-release@v1 | |
# ID used to access action output | |
id: sign_app | |
with: | |
releaseDirectory: app/build/outputs/apk/release | |
signingKeyBase64: ${{ secrets.SIGNING_STORE_PASSWORD }} | |
alias: ${{ secrets.SIGNING_KEY_ALIAS }} | |
keyStorePassword: ${{ secrets.SIGNING_KEY_PASSWORD }} | |
keyPassword: ${{ secrets.SIGNING_KEY_PASSWORD }} | |
# 4 | |
- name: Upload | |
uses: actions/upload-artifact@v2 | |
with: | |
name: Build Artifacts | |
path: app/build/outputs/ |