summaryrefslogtreecommitdiffhomepage
path: root/.github/workflows/android-app.yml
blob: 14ce2932582aaac6ad59465d570426c06e230feb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Android app CI
on:
    # Build whenever a file that affects Android is changed by a push
    push:
        paths:
            - .github/workflows/android-app.yml
            - android/**
            - mullvad-daemon/**
            - mullvad-jni/**
            - mullvad-paths/**
            - mullvad-problem-report/**
            - mullvad-rpc/**
            - mullvad-types/**
            - talpid-core/**
            - talpid-platform-metadata/**
            - talpid-types/**
            - talpid-types/**
            - wireguard/**
            - Cargo.toml
            - build-apk.sh
            - update-api-metadata.sh
            - update-version-metadata.sh
            - version-metadata.sh
    # Build if requested manually from the Actions tab
    workflow_dispatch:
jobs:
    build:
        runs-on: ubuntu-latest
        steps:
            - name: Checkout repository
              uses: actions/checkout@v2

            - name: Declare commit sha variable
              id: vars
              shell: bash
              run: |
                echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"

            - name: Configure Rust
              uses: ATiltedTree/setup-rust@v1.0.4
              with:
                  rust-version: stable
                  targets: x86_64-linux-android

            - name: Configure Go
              uses: actions/setup-go@v2.1.3
              with:
                  go-version: 1.16

            - name: Configure Android SDK
              uses: maxim-lobanov/setup-android-tools@v1
              with:
                  packages: |
                      platforms;android-30
                      build-tools;30.0.3
                  cache: true

            - name: Configure Android NDK
              id: install-android-ndk
              uses: nttld/setup-ndk@v1
              with:
                  ndk-version: r20b

            - name: Configure cache
              uses: actions/cache@v2
              with:
                path: |
                    ~/.gradle/caches
                    ~/.gradle/wrapper
                    ./android/build
                key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}-${{ steps.vars.outputs.sha_short }}
                restore-keys: |
                    gradle-${{ steps.vars.outputs.sha_short }}

            - name: Bind Cargo with NDK
              run: |
                cat >> $HOME/.cargo/config << EOF
                [target.x86_64-linux-android]
                ar = "${{ steps.install-android-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-ar"
                linker = "${{ steps.install-android-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android21-clang"
                EOF

            - name: Build and run unit tests
              env:
                RUSTFLAGS: --deny warnings
                NDK_TOOLCHAIN_DIR: ${{ steps.install-android-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin
                AR_x86_64_linux_android: ${{ steps.install-android-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-ar
                CC_x86_64_linux_android: ${{ steps.install-android-ndk.outputs.ndk-path }}/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android21-clang
                ARCHITECTURES: aarch64 x86_64
              run: |
                ./wireguard/build-wireguard-go.sh --android --no-docker
                source env.sh x86_64-linux-android
                cargo build --target x86_64-linux-android --verbose --package mullvad-jni
                cd android
                ./gradlew --console plain assembleDebug
                ./gradlew testDebugUnitTest

    instrumented-tests:
        name: Instrumented tests
        runs-on: macos-latest
        timeout-minutes: 30
        needs:
          - build
        strategy:
            fail-fast: false
        steps:
            - name: Checkout repository
              uses: actions/checkout@v2

            - name: Declare commit sha variable
              id: vars
              shell: bash
              run: |
                echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"

            - name: Set up Java
              uses: actions/setup-java@v1
              with:
                java-version: 1.8

            - uses: gradle/wrapper-validation-action@v1

            - name: Configure cache
              uses: actions/cache@v2
              with:
                path: |
                    ~/.gradle/caches
                    ~/.gradle/wrapper
                    ./android/build
                key: gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}-${{ steps.vars.outputs.sha_short }}
                restore-keys: |
                    gradle-${{ steps.vars.outputs.sha_short }}

            - name: Run Android instrumented tests
              uses: reactivecircus/android-emulator-runner@v2
              with:
                api-level: 29
                arch: x86_64
                emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot-load -noaudio -no-boot-anim
                disable-animations: true
                profile: pixel
                script: ./gradlew connectedCheck --stacktrace
                working-directory: ./android
              env:
                API_LEVEL: 29