Skip to content

Commit

Permalink
Merge pull request #64 from CrisisCleanup/feat/improved-workflow-test
Browse files Browse the repository at this point in the history
feat: Setup github workflows, lint + format repo, fix unit tests
  • Loading branch information
hueachilles authored Aug 21, 2023
2 parents 47d0a05 + d9e0de7 commit 1950f06
Show file tree
Hide file tree
Showing 483 changed files with 2,612 additions and 1,844 deletions.
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# style(format): run spotlessApply cmd on codebase to fix lint + format issues
cc43a9f0e1550a50d6025abb2bba2d143e799709
# style(format): run `./gradlew --init-script gradle/init.gradle.kts spotlessApply` to format + lint all files
1fb424562e796ea572d9f9d6d8d88c3bc9f3bb0c
28 changes: 28 additions & 0 deletions .github/ci-gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright 2020 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

org.gradle.daemon=false
org.gradle.parallel=true
org.gradle.workers.max=2

kotlin.incremental=false
kotlin.compiler.execution.strategy=in-process

# Controls KotlinOptions.allWarningsAsErrors.
# This value used in CI and is currently set to false.
# If you want to treat warnings as errors locally, set this property to true
# in your ~/.gradle/gradle.properties file.
warningsAsErrors=false
225 changes: 225 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
name: Main

on:
push:
branches:
- main
pull_request:

concurrency:
group: build-${{ github.job }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build 🏗️
runs-on: ubuntu-latest
timeout-minutes: 120

steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Validate Gradle Wrapper 📝
uses: gradle/wrapper-validation-action@v1

- name: Copy CI gradle.properties 📋
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Set up JDK 17 ⚙️
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

- name: Setup Gradle ⚙️
uses: gradle/gradle-build-action@v2

- name: Build all build type and flavor permutations 🏗️
run: ./gradlew assembleDemoDebug

- name: 📊 Upload build outputs (APKs)
uses: actions/upload-artifact@v3
with:
name: APKs
path: '**/build/outputs/apk/**/*.apk'

spotless-check:
name: Spotless Check 📝
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Validate Gradle Wrapper 📝
uses: gradle/wrapper-validation-action@v1

- name: Copy CI gradle.properties 📋
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Set up JDK 17 ⚙️
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

- name: Setup Gradle ⚙️
uses: gradle/gradle-build-action@v2

- name: Check spotless 📝
run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache

lint:
name: Lint Check 💅
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Validate Gradle Wrapper 📝
uses: gradle/wrapper-validation-action@v1

- name: Copy CI gradle.properties 📋
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Set up JDK 17 ⚙️
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

- name: Setup Gradle ⚙️
uses: gradle/gradle-build-action@v2

- name: Check lint 💅
run: ./gradlew lintDemoDebug

- name: 📊 Upload lint reports (HTML)
if: always()
uses: actions/upload-artifact@v3
with:
name: lint-reports
path: '**/build/reports/lint-results-*.html'

unit-test:
name: Unit Test 🧪
runs-on: ubuntu-latest
timeout-minutes: 120

steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Validate Gradle Wrapper 📝
uses: gradle/wrapper-validation-action@v1

- name: Copy CI gradle.properties 📋
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Set up JDK 17 ⚙️
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

- name: Setup Gradle ⚙️
uses: gradle/gradle-build-action@v2

- name: Run local tests 🧪
run: ./gradlew testDemoDebug testProdDebug

- name: 📊 Upload test results (XML)
if: always()
uses: actions/upload-artifact@v3
with:
name: test-results
path: '**/build/test-results/test*UnitTest/**.xml'

androidTest:
if: false # disabled bc packageDemoDebugAndroidTest is failing
name: Android Test 🧪
needs: build
runs-on: macos-latest # enables hardware acceleration in the virtual machine
timeout-minutes: 90
strategy:
matrix:
api-level: [26, 30]

steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Copy CI gradle.properties 📋
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Set up JDK 17 ⚙️
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

- name: Setup Gradle ⚙️
uses: gradle/gradle-build-action@v2

- name: Build AndroidTest apps 🏗️
run: ./gradlew packageDemoDebug packageDemoDebugAndroidTest --daemon

- name: Run instrumentation tests 🧪
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
arch: x86_64
disable-animations: true
disk-size: 6000M
heap-size: 600M
script: ./gradlew connectedDemoDebugAndroidTest --daemon

- name: 📊 Upload test reports
if: always()
uses: actions/upload-artifact@v3
with:
name: test-reports-${{ matrix.api-level }}
path: '**/build/reports/androidTests'

androidTest-GMD:
if: false # disabled bc packageDemoDebugAndroidTest is failing
name: Android Test GMD 🧪
needs: build
runs-on: macos-latest # enables hardware acceleration in the virtual machine
timeout-minutes: 90

steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Copy CI gradle.properties 📋
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Set up JDK 17 ⚙️
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

- name: Setup Gradle ⚙️
uses: gradle/gradle-build-action@v2

- name: Accept Android licenses ✔️
run: yes | "$ANDROID_HOME"/cmdline-tools/latest/bin/sdkmanager --licenses || true

- name: Build AndroidTest apps 🏗️
run: ./gradlew packageDemoDebug packageDemoDebugAndroidTest

- name: Run instrumented tests with GMD 🧪
run: ./gradlew cleanManagedDevices --unused-only &&
./gradlew ciDemoDebugAndroidTest -Dorg.gradle.workers.max=1
-Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect" -Pandroid.experimental.testOptions.managedDevices.emulator.showKernelLogging=true

- name: 📊 Upload test reports
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: test-reports
path: '**/build/reports/androidTests'
52 changes: 52 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: GitHub Release with APKs

on:
push:
tags:
- 'v*'

jobs:
build:
name: Build and Release 🏷️
runs-on: ubuntu-latest
timeout-minutes: 45

steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Validate Gradle Wrapper 📝
uses: gradle/wrapper-validation-action@v1

- name: Copy CI gradle.properties 📋
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Set up JDK 17 ⚙️
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17

- name: Build app 🏗️
run: ./gradlew :app:assembleDemoRelease

- name: Create Release 🚀
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: true
prerelease: false

- name: Upload app 📤
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: app/build/outputs/apk/demo/release/app-demo-release.apk
asset_name: app-demo-release.apk
asset_content_type: application/vnd.android.package-archive
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
java adoptopenjdk-17.0.8+7
java zulu-17.44.17
direnv 2.32.3
maestro 1.31.0
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class ExampleInstrumentedTest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
Assert.assertEquals("com.crisiscleanup.demo.debug", appContext.packageName)
}
}
}
Loading

0 comments on commit 1950f06

Please sign in to comment.