Skip to content

Commit

Permalink
Add Github Actions to run end-to-end tests, and also hermetically (#2487
Browse files Browse the repository at this point in the history
)

* Setup github actions

* Add GH_TOKEN env variable

* Add checkout to github actions

* Update to checkout@v4

* Add write-all permissions

* Set permissions actions to write

* Use e2e test from ground-platform

* Use `uses` instead `gh run`

* Fix uses

* Setup secrets and workflow_call

* Remove GITHUB_TOKEN

* Set up actions

* Reconfigure action subdirectory

* Add shell property

* Checkout code

* Return missing steps

* Fix repo checkout

* Fix with statement

* Increase timeout

* Fix missing shell parameters

* Switch to local repo

* Skip delete space to sace time

* Pull from data-test

* List data folder

* Set up download actions

* Hardcode api-level

* Fix data/test emulator import path

* Set project

* With stack trace

* Build ground-platform

* Fix formatting

* Use cached firebase emulator

* Update to Java 21

* Try JVM 16

* Set JVM to 16

* Don't change gradle properties

* Set compiler to target jvm 16

* Try JDK 17

* Increase timeouts

* Run  node modules cache before build

* Change Firebase data key

* Set java version to 21, use local build config

* With info

* Update TTL

* Skip create test

* Add GOOGLE_MAPS_KEY secret

* Set environment variable with secret

* Pass in secret as input

* Don't skip create test

* Fix sed for ubunti

* Upload screenshots

* Don't force quit

* Wait for initializing to go away

* Be able to run tests one off

* Fix broken action

* Add one off test

* Add checkout

* add ground-platform/data/test-create

* Increase timeouts

* Fix params in e2e test

* Set to warning

* Removing --warning

* Run JVM 17

* Upload logcat

* Run ADP within emulator script

* Output to logcart afterwards

* Add logcat warning messages

* Show logcat for both warnings and errors

* Use space instead of comma

* Target google_apis_playstore

* Filter logcat to only errors

* Reset build stuff

* Replace fork repo with google repo

* Change LICENSE header

* Consolidate screenshot name into helper function

* Format

* Localize screenshotName

---------

Co-authored-by: Sufyan Abbasi <sufy@google.com>
  • Loading branch information
sufyanAbbasi and sufyanAbbasi authored Jun 10, 2024
1 parent b6650f1 commit 9e2dfff
Showing 6 changed files with 340 additions and 8 deletions.
179 changes: 179 additions & 0 deletions .github/actions/submit-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# Copyright 2024 Google LLC
#
# 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
#
# https://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.
name: Submit to survey

inputs:
android-repository:
description: 'ground-android repository under test'
default: google/ground-android

platform-repository:
description: 'ground-platform repository under test (if applicable)'
default: google/ground-platform

use-repo-data:
description: 'Whether to use the local repository emulator data or not'
default: 'true'

upload-artifacts:
description: 'Whether to upload the final emulator data artifacts'
default: 'false'

google-maps-key:
description: 'A Google Maps API key'

runs:
using: composite
steps:
- name: Enable KVM group perms
shell: bash
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
ls /dev/kvm
- name: Gradle cache
uses: gradle/actions/setup-gradle@v3

- name: AVD cache
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-24

- name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ inputs.android-repository }}

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

- name: Setup Gradle
uses: gradle/gradle-build-action@v3

- name: Set up Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18

- name: Checkout ground-platform
uses: actions/checkout@v4
with:
repository: ${{ inputs.platform-repository }}
path: ground-platform

- name: Cache node modules
id: cache-npm
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Build ground functions
shell: bash
run: |
cd ground-platform
npm run build:local
cd ../
- name: Install firebase-tools
shell: bash
run: |
npm install -g firebase-tools
- name: Cache Firebase emulator
uses: actions/cache@v4
with:
path: ~/.cache/firebase/emulators
key: ${{ runner.os }}-firebase-emulators-${{ github.sha }}
restore-keys: |
${{ runner.os }}-firebase-emulators-
- name: Copy Firebase emulator data
uses: actions/download-artifact@v4
if: inputs.use-repo-data != 'true'
with:
name: data-create
path: data/

- name: Copy the local repo data
if: inputs.use-repo-data == 'true'
shell: bash
run: cp -r ground-platform/data/test-create ground-platform/data/test

- name: Replace Google Maps API key
shell: bash
env:
GOOGLE_MAPS_KEY: ${{ inputs.google-maps-key }}
run: |
sed -E -i 's/("current_key": ")[[:alnum:]_-]+(")/\1'"$GOOGLE_MAPS_KEY"'\2/' ground/src/debug/local/google-services.json
- name: Move the local google-services.json
shell: bash
run: |
cp -r ground/src/debug/local/google-services.json ground/src/debug/
- name: Build projects and run instrumentation tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 24
target: google_apis_playstore
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back emulated -logcat '*:e'
disable-animations: true
script: |
firebase emulators:exec './gradlew :e2eTest:connectedLocalDebugAndroidTest --stacktrace' --config ground-platform/firebase.local.json --project ground-local-dev --import data/test --export-on-exit data/test
- name: Upload test reports
if: always()
uses: actions/upload-artifact@v4
with:
name: test-reports
path: '**/build/reports/androidTests'

- name: Upload screenshots
if: always()
uses: actions/upload-artifact@v4
with:
name: test-screenshots
path: '**/build/outputs/connected_android_test_additional_output'

- name: Move Firebase emulator data (avoids .gitignore)
shell: bash
run: mv data/test/ ./test

- name: Copy Firebase emulator data
if: inputs.upload-artifacts == 'true'
uses: actions/upload-artifact@v4
with:
name: data-submit
path: '**/test'
retention-days: 7
overwrite: true
if-no-files-found: error
66 changes: 66 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2024 The Ground Authors.
#
# 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
#
# https://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.
name: End to End Test

on:
issue_comment:
types: [created]

jobs:
e2eTest:
runs-on: ubuntu-latest
timeout-minutes: 15
if: github.event.issue.pull_request && contains(github.event.comment.body, '/e2eTest')
steps:
- name: Start test
run: |
echo "Begin end to end test"
createTest:
needs: e2eTest
name: Create a new survey
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Run create-test
uses: google/ground-platform/.github/actions/create-test@master
with:
upload-artifacts: true

submitTest:
needs: createTest
name: Submit to survey
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Run submit-test
uses: ./.github/actions/submit-test
with:
android-repository: ${{ github.repository }}
google-maps-key: ${{ secrets.GOOGLE_MAPS_KEY }}
use-repo-data: false
upload-artifacts: true


verifyTest:
needs: submitTest
name: Verify survey submissions
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Run verify-test
uses: google/ground-platform/.github/actions/verify-test@master
with:
use-repo-data: false
35 changes: 35 additions & 0 deletions .github/workflows/test-submit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2024 The Ground Authors.
#
# 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
#
# https://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.
name: Submission Test

on:
issue_comment:
types: [created]

jobs:
submitTest:
if: github.event.issue.pull_request && contains(github.event.comment.body, '/submitTest')
name: Submit to survey
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run submit-test
uses: ./.github/actions/submit-test
with:
android-repository: ${{ github.repository }}
google-maps-key: ${{ secrets.GOOGLE_MAPS_KEY }}
use-repo-data: true
upload-artifacts: false
9 changes: 8 additions & 1 deletion e2eTest/build.gradle
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ android {
compileSdk rootProject.androidCompileSdk

defaultConfig {
applicationId "com.google.android.ground.e2etest"
minSdkVersion rootProject.androidMinSdk
targetSdkVersion rootProject.androidTargetSdk
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -35,6 +34,10 @@ android {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}

buildFeatures {
buildConfig = true
}

buildTypes {
staging {
}
@@ -43,15 +46,19 @@ android {
productFlavors {
local {
dimension "backend"
buildConfigField "boolean", "USE_EMULATORS", "true"
}
dev {
dimension "backend"
buildConfigField "boolean", "USE_EMULATORS", "false"
}
sig {
dimension "backend"
buildConfigField "boolean", "USE_EMULATORS", "false"
}
ecam {
dimension "backend"
buildConfigField "boolean", "USE_EMULATORS", "false"
}
}
}
Loading

0 comments on commit 9e2dfff

Please sign in to comment.