Validate #425
This file contains 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
# This workflow is triggered on push events to the repository | |
# It runs the following jobs: | |
# - build: Ensure the code builds | |
# - unit-test: Run unit tests | |
# - instrumented-test: Run instrumented tests | |
# - assemble-archive: Archive APKs | |
# - distribute: Upload artifact to Firebase App Distribution | |
name: Validate | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
schedule: | |
- cron: "0 2 * * */2" | |
jobs: | |
build: | |
name: Ensure the code builds | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
version: | |
- "OoniStableFullRelease" | |
- "OoniStableFdroidRelease" | |
- "DwStableFullRelease" | |
- "DwStableFdroidRelease" | |
steps: | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: Gradle cache | |
uses: gradle/actions/setup-gradle@v3 | |
- name: Build `StableFullRelease` and `StableFdroidRelease` variants | |
run: ./gradlew build${{ matrix.version }} && ./gradlew clean | |
unit-test: | |
name: Run unit tests | |
runs-on: ubuntu-latest | |
needs: [ build ] | |
steps: | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: Gradle cache | |
uses: gradle/actions/setup-gradle@v3 | |
- name: Run unit tests | |
run: ./gradlew testOoniStableFullRelease | |
- name: Uploads test reports | |
uses: actions/upload-artifact@v4 | |
if: failure() | |
with: | |
name: test-report | |
path: app/build/test-results/testOoniStableFullReleaseUnitTest | |
instrumented-test: | |
name: Run instrumented tests | |
runs-on: ubuntu-latest | |
needs: [ build ] | |
strategy: | |
matrix: | |
api-level: [25, 29] # Bug in API 21-24 | |
target: [default, google_apis] | |
steps: | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: Enable KVM | |
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 | |
- 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-${{ matrix.api-level }}-${{ matrix.target }} | |
- name: create AVD and 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: x86_64 | |
profile: Nexus 6 | |
ram-size: 4096M | |
force-avd-creation: false | |
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none | |
disable-animations: false | |
script: echo "Generated AVD snapshot for caching." | |
- name: Run instrumented tests | |
uses: reactivecircus/android-emulator-runner@v2 | |
with: | |
api-level: ${{ matrix.api-level }} | |
target: ${{ matrix.target }} | |
arch: x86_64 | |
profile: Nexus 6 | |
ram-size: 4096M | |
force-avd-creation: false | |
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none | |
disable-animations: true | |
script: ./gradlew connectedOoniStableFullDebugAndroidTest | |
- name: uploads test reports | |
uses: actions/upload-artifact@v4 | |
if: failure() | |
with: | |
name: emulator-test-reports | |
path: app/build/reports/androidTests/connected/debug/flavors/ooniStableFull/ | |
assemble-archive: | |
name: Archive APKs | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
version: | |
- "OoniStableFullDebug" | |
- "OoniStableFdroidDebug" | |
- "OoniDevFullDebug" | |
- "OoniDevFullDebugAndroidTest" | |
- "DwStableFullDebug" | |
- "DwStableFdroidDebug" | |
- "DwDevFullDebug" | |
needs: [ build ] | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: Get issue number | |
uses: actions/github-script@v7 | |
id: get_issue_number | |
with: | |
script: | | |
if (context.issue.number) { | |
// Return issue number if present | |
return context.issue.number; | |
} else { | |
// Otherwise return issue number from commit | |
return ( | |
await github.rest.repos.listPullRequestsAssociatedWithCommit({ | |
commit_sha: context.sha, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}) | |
).data[0].number; | |
} | |
result-encoding: string | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Gradle cache | |
uses: gradle/actions/setup-gradle@v3 | |
- name: Assemble APKs | |
if: success() && steps.get_issue_number.outputs.result | |
run: ./gradlew assemble${{ matrix.version }} | |
env: | |
PR_NUMBER: ${{ steps.get_issue_number.outputs.result }} | |
- name: uploads dev apk | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.version }}Apk | |
path: | | |
app/build/outputs/apk/ooniStableFull/debug/app-ooni-stable-full-debug.apk | |
app/build/outputs/apk/ooniStableFdroid/debug/app-ooni-stable-fdroid-debug.apk | |
app/build/outputs/apk/ooniDevFull/debug/app-ooni-dev-full-debug.apk | |
app/build/outputs/apk/androidTest/ooniDevFull/debug/app-ooni-dev-full-debug-androidTest.apk | |
app/build/outputs/apk/dwStableFull/debug/app-dw-stable-full-debug.apk | |
app/build/outputs/apk/dwStableFdroid/debug/app-dw-stable-fdroid-debug.apk | |
app/build/outputs/apk/dwDevFull/debug/app-dw-dev-full-debug.apk | |
distribute: | |
name: Upload artifact to Firebase App Distribution | |
runs-on: ubuntu-latest | |
needs: [ assemble-archive ] | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: Download app APK | |
uses: actions/download-artifact@v4 | |
with: | |
name: OoniDevFullDebugApk | |
- name: Upload artifact to Firebase App Distribution | |
id: uploadArtifact | |
env: | |
INPUT_APPID: ${{secrets.FIREBASE_APP_ID}} | |
INPUT_SERVICECREDENTIALSFILECONTENT: ${{ secrets.CREDENTIAL_FILE_CONTENT }} | |
GOOGLE_APPLICATION_CREDENTIALS: service_credentials_content.json | |
INPUT_GROUPS: testers | |
INPUT_FILE: ooniDevFull/debug/app-ooni-dev-full-debug.apk | |
run: | | |
cat <<< "${INPUT_SERVICECREDENTIALSFILECONTENT}" > service_credentials_content.json | |
sudo npm install -g firebase-tools | |
firebase appdistribution:distribute "$INPUT_FILE" --app "$INPUT_APPID" --groups "$INPUT_GROUPS" --testers "$INPUT_TESTERS" --release-notes "$(git log -1 --pretty=short)" |