Android - Build and test #15468
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
--- | |
name: Android - Build and test | |
on: | |
workflow_dispatch: | |
push: | |
jobs: | |
generate-debug-keystore: | |
name: Generate debug keystore (migrate to secret) | |
runs-on: ubuntu-latest | |
steps: | |
- name: Generate keystore | |
run: >- | |
keytool -genkey | |
-keystore debug.keystore | |
-storepass android | |
-alias androiddebugkey | |
-keypass android | |
-keyalg RSA | |
-keysize 2048 | |
-validity 10000 | |
-dname "CN=Android Debug,O=Android,C=US" | |
- name: Upload keystore | |
uses: actions/upload-artifact@v4 | |
with: | |
name: debug-keystore | |
path: debug.keystore | |
if-no-files-found: error | |
retention-days: 7 | |
generate-relay-list: | |
name: Generate relay list (migrate to secret) | |
runs-on: se-got-github-runner-006 | |
steps: | |
- name: Get date | |
id: get-date | |
shell: bash | |
run: echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT | |
- name: Cache | |
uses: actions/cache@v4 | |
id: cache-relay-list | |
with: | |
path: android/app/build/extraAssets/relays.json | |
key: relay-list-${{ steps.get-date.outputs.date }} | |
- name: Checkout repository | |
if: steps.cache-relay-list.outputs.cache-hit != 'true' | |
uses: actions/checkout@v4 | |
- name: Create dummy dir | |
if: steps.cache-relay-list.outputs.cache-hit != 'true' | |
run: mkdir .android | |
- name: Generate | |
if: steps.cache-relay-list.outputs.cache-hit != 'true' | |
env: | |
ANDROID_HOME: .android | |
CARGO_TARGET_VOLUME_NAME: cargo-target-${{ runner.name }} | |
CARGO_REGISTRY_VOLUME_NAME: cargo-cache-${{ runner.name }} | |
GRADLE_CACHE_VOLUME_NAME: gradle-cache-${{ runner.name }} | |
run: | | |
mkdir -p android/app/build/extraAssets | |
./building/container-run.sh android cargo run --bin relay_list > android/app/build/extraAssets/relays.json | |
- name: Upload | |
uses: actions/upload-artifact@v4 | |
with: | |
name: relay-list | |
path: android/app/build/extraAssets/relays.json | |
if-no-files-found: error | |
retention-days: 7 | |
build-native: | |
name: Build native | |
runs-on: se-got-github-runner-006 | |
strategy: | |
matrix: | |
include: | |
# - arch: "x86_64" | |
# abi: "x86_64" | |
# target: "x86_64-linux-android" | |
# - arch: "i686" | |
# abi: "x86" | |
# target: "i686-linux-android" | |
- arch: "aarch64" | |
abi: "arm64-v8a" | |
target: "aarch64-linux-android" | |
# - arch: "armv7" | |
# abi: "armeabi-v7a" | |
# target: "armv7-linux-androideabi" | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Checkout wireguard-go-rs recursively | |
run: | | |
git config --global --add safe.directory '*' | |
git submodule update --init --recursive --depth=1 wireguard-go-rs | |
- name: Create dummy dir | |
run: mkdir .android | |
- name: Build native | |
env: | |
ANDROID_HOME: .android | |
CARGO_TARGET_VOLUME_NAME: cargo-target-${{ runner.name }} | |
CARGO_REGISTRY_VOLUME_NAME: cargo-cache-${{ runner.name }} | |
GRADLE_CACHE_VOLUME_NAME: gradle-cache-${{ runner.name }} | |
run: ./building/container-run.sh android ARCHITECTURES=${{ matrix.arch }} ./build-apk.sh --dev-build --skip-apk | |
- name: Upload native libs | |
uses: actions/upload-artifact@v3 | |
with: | |
name: native-libs-${{ matrix.arch }} | |
path: android/app/build/extraJni | |
if-no-files-found: error | |
retention-days: 7 | |
build-app: | |
name: Build app | |
runs-on: se-got-github-runner-006 | |
needs: [generate-debug-keystore] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: debug-keystore | |
path: .android | |
- name: Compile debug app | |
env: | |
ANDROID_HOME: .android | |
CARGO_TARGET_VOLUME_NAME: cargo-target-${{ runner.name }} | |
CARGO_REGISTRY_VOLUME_NAME: cargo-cache-${{ runner.name }} | |
GRADLE_CACHE_VOLUME_NAME: gradle-cache-${{ runner.name }} | |
run: ./building/container-run.sh android android/gradlew -p android compileOssProdDebugKotlin | |
- name: Wait for other jobs (native, relay list) | |
uses: kachick/wait-other-jobs@v2.0.3 | |
with: | |
wait-seconds-before-first-polling: '1' | |
wait-list: | | |
[ | |
{ | |
"workflowFile": "android-app.yml", | |
"jobName": "build-native" | |
}, | |
{ | |
"workflowFile": "android-app.yml", | |
"jobName": "generate-relay-list" | |
} | |
] | |
- uses: actions/download-artifact@v4 | |
with: | |
name: relay-list | |
path: android/app/build/extraAssets | |
- uses: actions/download-artifact@v3 | |
with: | |
name: native-libs-aarch64 | |
path: android/app/build/extraJni | |
#merge-multiple: true | |
- name: Temp maybenot fix | |
run: touch android/app/build/extraAssets/maybenot_machines_v2 | |
- name: Assemble debug app | |
env: | |
ANDROID_HOME: .android | |
CARGO_TARGET_VOLUME_NAME: cargo-target-${{ runner.name }} | |
CARGO_REGISTRY_VOLUME_NAME: cargo-cache-${{ runner.name }} | |
GRADLE_CACHE_VOLUME_NAME: gradle-cache-${{ runner.name }} | |
run: ./building/container-run.sh android android/gradlew -p android assembleOssProdDebug | |
- name: Upload apks | |
uses: actions/upload-artifact@v3 | |
with: | |
name: apks | |
path: android/app/build/outputs/apk | |
if-no-files-found: error | |
retention-days: 7 | |
build-test-apps: | |
name: Build test apps | |
runs-on: se-got-github-runner-006 | |
needs: generate-debug-keystore | |
strategy: | |
matrix: | |
include: | |
- test-type: app | |
assemble-command: assembleOssProdAndroidTest | |
artifact-path: android/app/build/outputs/apk | |
- test-type: mockapi | |
assemble-command: :test:mockapi:assemble | |
artifact-path: android/test/mockapi/build/outputs/apk | |
# - test-type: e2e | |
# assemble-command: :test:e2e:assemble | |
# artifact-path: android/test/e2e/build/outputs/apk | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: debug-keystore | |
path: .android | |
- name: Build test apps | |
env: | |
ANDROID_HOME: .android | |
CARGO_TARGET_VOLUME_NAME: cargo-target-${{ runner.name }} | |
CARGO_REGISTRY_VOLUME_NAME: cargo-cache-${{ runner.name }} | |
GRADLE_CACHE_VOLUME_NAME: gradle-cache-${{ runner.name }} | |
run: ./building/container-run.sh android android/gradlew -p android ${{ matrix.assemble-command }} | |
- name: Upload apks | |
# Using v3 due to v4 being very slow for this artifact. | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ matrix.test-type }}-instrumentation-apks | |
path: ${{ matrix.artifact-path }} | |
if-no-files-found: error | |
retention-days: 7 | |
instrumented-tests: | |
name: Run instrumented tests | |
runs-on: [self-hosted, android-device] | |
needs: [build-app, build-test-apps] | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- test-type: app | |
path: android/app/build/outputs/apk | |
test-repeat: 1 | |
- test-type: mockapi | |
path: android/test/mockapi/build/outputs/apk | |
test-repeat: ${{ github.event_name == 'schedule' && 10 || github.event.inputs.mockapi_test_repeat || 1 }} | |
steps: | |
- name: Prepare report dir | |
if: ${{ matrix.test-repeat != 0 }} | |
id: prepare-report-dir | |
env: | |
INNER_REPORT_DIR: /tmp/${{ matrix.test-type }}-${{ github.run_id }}-${{ github.run_attempt }} | |
run: | | |
mkdir -p $INNER_REPORT_DIR | |
echo "report_dir=$INNER_REPORT_DIR" >> $GITHUB_OUTPUT | |
- name: Checkout repository | |
if: ${{ matrix.test-repeat != 0 }} | |
uses: actions/checkout@v4 | |
# Using v3 due to v4 being very slow for this artifact. | |
- uses: actions/download-artifact@v3 | |
if: ${{ matrix.test-repeat != 0 }} | |
with: | |
name: apks | |
path: android/app/build/outputs/apk | |
# Using v3 due to v4 being very slow for this artifact. | |
- uses: actions/download-artifact@v3 | |
if: ${{ matrix.test-repeat != 0 }} | |
with: | |
name: ${{ matrix.test-type }}-instrumentation-apks | |
path: ${{ matrix.path }} | |
- name: Calculate timeout | |
id: calculate-timeout | |
run: echo "timeout=$(( ${{ matrix.test-repeat }} * 10 ))" >> $GITHUB_OUTPUT | |
shell: bash | |
- name: Run instrumented test script | |
if: ${{ matrix.test-repeat != 0 }} | |
timeout-minutes: ${{ fromJSON(steps.calculate-timeout.outputs.timeout) }} | |
shell: bash -ieo pipefail {0} | |
env: | |
AUTO_FETCH_TEST_HELPER_APKS: true | |
TEST_TYPE: ${{ matrix.test-type }} | |
BILLING_FLAVOR: oss | |
INFRA_FLAVOR: prod | |
REPORT_DIR: ${{ steps.prepare-report-dir.outputs.report_dir }} | |
run: ./android/scripts/run-instrumented-tests-repeat.sh ${{ matrix.test-repeat }} | |
- name: Upload instrumentation report (${{ matrix.test-type }}) | |
uses: actions/upload-artifact@v4 | |
if: ${{ matrix.test-repeat != 0 }} | |
with: | |
name: ${{ matrix.test-type }}-instrumentation-report | |
path: ${{ steps.prepare-report-dir.outputs.report_dir }} | |
if-no-files-found: ignore | |
retention-days: 7 | |
# run-lint-and-tests: | |
# name: Run lint and test tasks | |
# needs: generate-debug-keystore | |
# runs-on: se-got-github-runner-006 | |
# strategy: | |
# fail-fast: false | |
# max-parallel: 1 | |
# matrix: | |
# include: | |
# - gradle-task: testDebugUnitTest -x :test:arch:testDebugUnitTest :app:testOssProdDebugUnitTest :service:testOssProdDebugUnitTest :lib:billing:testDebugUnitTest :lib:daemon-grpc:testDebugUnitTest :lib:shared:testDebugUnitTest | |
# - gradle-task: :test:arch:test --rerun-tasks | |
# - gradle-task: detekt | |
# - gradle-task: lint | |
# steps: | |
# - name: Checkout repository | |
# uses: actions/checkout@v4 | |
# - uses: actions/download-artifact@v4 | |
# with: | |
# name: debug-keystore | |
# path: .android | |
# - name: Run gradle test task | |
# env: | |
# CARGO_TARGET_VOLUME_NAME: cargo-target-${{ runner.name }} | |
# CARGO_REGISTRY_VOLUME_NAME: cargo-cache-${{ runner.name }} | |
# GRADLE_CACHE_VOLUME_NAME: gradle-cache-${{ runner.name }} | |
# run: ./building/container-run.sh android android/gradlew -p android ${{ matrix.gradle-task }} |