| 1 |
name: Android |
| 2 |
|
| 3 |
# spell-checker:ignore (people) reactivecircus juliangruber |
| 4 |
# spell-checker:ignore (shell/tools) TERMUX nextest udevadm pkill |
| 5 |
# spell-checker:ignore (misc) swiftshader playstore DATALOSS noaudio |
| 6 |
|
| 7 |
on: |
| 8 |
pull_request: |
| 9 |
push: |
| 10 |
branches: |
| 11 |
- '*' |
| 12 |
|
| 13 |
|
| 14 |
permissions: |
| 15 |
contents: read # to fetch code (actions/checkout) |
| 16 |
|
| 17 |
# End the current execution if there is a new changeset in the PR. |
| 18 |
concurrency: |
| 19 |
group: ${{ github.workflow }}-${{ github.ref }} |
| 20 |
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} |
| 21 |
|
| 22 |
env: |
| 23 |
TERMUX: v0.118.0 |
| 24 |
KEY_POSTFIX: nextest+rustc-hash+adb+sshd+upgrade+XGB+inc18 |
| 25 |
COMMON_EMULATOR_OPTIONS: -no-metrics -no-window -noaudio -no-boot-anim -camera-back none -gpu off |
| 26 |
EMULATOR_DISK_SIZE: 12GB |
| 27 |
EMULATOR_HEAP_SIZE: 2048M |
| 28 |
EMULATOR_BOOT_TIMEOUT: 1200 # 20min |
| 29 |
|
| 30 |
jobs: |
| 31 |
test_android: |
| 32 |
name: Test builds |
| 33 |
timeout-minutes: 90 |
| 34 |
strategy: |
| 35 |
fail-fast: false |
| 36 |
matrix: |
| 37 |
os: [ubuntu-latest] # , macos-latest |
| 38 |
cores: [4] # , 6 |
| 39 |
ram: [4096] |
| 40 |
api-level: [28] |
| 41 |
target: [google_apis_playstore] |
| 42 |
arch: [x86_64] # ,x86 ,arm64-v8a |
| 43 |
runs-on: ${{ matrix.os }} |
| 44 |
env: |
| 45 |
EMULATOR_RAM_SIZE: ${{ matrix.ram }} |
| 46 |
EMULATOR_CORES: ${{ matrix.cores }} |
| 47 |
RUNNER_OS: ${{ matrix.os }} |
| 48 |
AVD_CACHE_KEY: "set later due to limitations of github actions not able to concatenate env variables" |
| 49 |
steps: |
| 50 |
- name: Concatenate values to environment file |
| 51 |
run: | |
| 52 |
echo "AVD_CACHE_KEY=${{ matrix.os }}-${{ matrix.cores }}-${{ matrix.ram }}-${{ matrix.api-level }}-${{ matrix.target }}-${{ matrix.arch }}+termux-${{ env.TERMUX }}+${{ env.KEY_POSTFIX }}" >> $GITHUB_ENV |
| 53 |
- name: Collect information about runner |
| 54 |
if: always() |
| 55 |
continue-on-error: true |
| 56 |
run: | |
| 57 |
hostname |
| 58 |
uname -a |
| 59 |
free -mh |
| 60 |
df -Th |
| 61 |
cat /proc/cpuinfo |
| 62 |
- name: (Linux) create links from home to data partition |
| 63 |
if: ${{ runner.os == 'Linux' }} |
| 64 |
continue-on-error: true |
| 65 |
run: | |
| 66 |
ls -lah /mnt/ |
| 67 |
cat /mnt/DATALOSS_WARNING_README.txt |
| 68 |
sudo mkdir /mnt/data |
| 69 |
sudo chmod a+rwx /mnt/data |
| 70 |
mkdir /mnt/data/.android && ln -s /mnt/data/.android ~/.android |
| 71 |
mkdir /mnt/data/work && ln -s /mnt/data/work ~/work |
| 72 |
- name: Enable KVM group perms (linux hardware acceleration) |
| 73 |
if: ${{ runner.os == 'Linux' }} |
| 74 |
run: | |
| 75 |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules |
| 76 |
sudo udevadm control --reload-rules |
| 77 |
sudo udevadm trigger --name-match=kvm |
| 78 |
- uses: actions/[email protected] |
| 79 |
with: |
| 80 |
persist-credentials: false |
| 81 |
- name: Collect information about runner |
| 82 |
if: always() |
| 83 |
continue-on-error: true |
| 84 |
run: | |
| 85 |
free -mh |
| 86 |
df -Th |
| 87 |
- name: Restore AVD cache |
| 88 |
uses: actions/cache/restore@v6 |
| 89 |
id: avd-cache |
| 90 |
continue-on-error: true |
| 91 |
with: |
| 92 |
path: | |
| 93 |
~/.android/avd/* |
| 94 |
~/.android/avd/*/snapshots/* |
| 95 |
~/.android/adb* |
| 96 |
~/__rustc_hash__ |
| 97 |
key: avd-${{ env.AVD_CACHE_KEY }} |
| 98 |
- name: Collect information about runner after AVD cache |
| 99 |
if: always() |
| 100 |
continue-on-error: true |
| 101 |
run: | |
| 102 |
free -mh |
| 103 |
df -Th |
| 104 |
ls -lah /mnt/data |
| 105 |
du -sch /mnt/data |
| 106 |
- name: Delete AVD Lockfile when run from cache |
| 107 |
if: steps.avd-cache.outputs.cache-hit == 'true' |
| 108 |
run: | |
| 109 |
rm -f \ |
| 110 |
~/.android/avd/*.avd/*.lock \ |
| 111 |
~/.android/avd/*/*.lock |
| 112 |
- name: Create and cache emulator image |
| 113 |
if: steps.avd-cache.outputs.cache-hit != 'true' |
| 114 |
uses: reactivecircus/[email protected] |
| 115 |
with: |
| 116 |
api-level: ${{ matrix.api-level }} |
| 117 |
target: ${{ matrix.target }} |
| 118 |
arch: ${{ matrix.arch }} |
| 119 |
ram-size: ${{ env.EMULATOR_RAM_SIZE }} |
| 120 |
heap-size: ${{ env.EMULATOR_HEAP_SIZE }} |
| 121 |
disk-size: ${{ env.EMULATOR_DISK_SIZE }} |
| 122 |
cores: ${{ env.EMULATOR_CORES }} |
| 123 |
force-avd-creation: true |
| 124 |
emulator-options: ${{ env.COMMON_EMULATOR_OPTIONS }} -no-snapshot-load |
| 125 |
emulator-boot-timeout: ${{ env.EMULATOR_BOOT_TIMEOUT }} |
| 126 |
script: | |
| 127 |
util/android-commands.sh init "${{ matrix.arch }}" "${{ matrix.api-level }}" "${{ env.TERMUX }}" |
| 128 |
- name: Save AVD cache |
| 129 |
if: steps.avd-cache.outputs.cache-hit != 'true' |
| 130 |
uses: actions/cache/save@v6 |
| 131 |
with: |
| 132 |
path: | |
| 133 |
~/.android/avd/* |
| 134 |
~/.android/avd/*/snapshots/* |
| 135 |
~/.android/adb* |
| 136 |
~/__rustc_hash__ |
| 137 |
key: avd-${{ env.AVD_CACHE_KEY }} |
| 138 |
- uses: juliangruber/read-file-action@v1 |
| 139 |
id: read_rustc_hash |
| 140 |
with: |
| 141 |
# ~ expansion didn't work |
| 142 |
path: ${{ runner.os == 'Linux' && '/home/runner/__rustc_hash__' || '/Users/runner/__rustc_hash__' }} |
| 143 |
trim: true |
| 144 |
- name: Restore rust cache |
| 145 |
id: rust-cache |
| 146 |
uses: actions/cache/restore@v6 |
| 147 |
with: |
| 148 |
path: ~/__rust_cache__ |
| 149 |
# The version vX at the end of the key is just a development version to avoid conflicts in |
| 150 |
# the github cache during the development of this workflow |
| 151 |
key: ${{ matrix.arch }}_${{ matrix.target}}_${{ steps.read_rustc_hash.outputs.content }}_${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}_v3 |
| 152 |
- name: Collect information about runner resources |
| 153 |
if: always() |
| 154 |
continue-on-error: true |
| 155 |
run: | |
| 156 |
free -mh |
| 157 |
df -Th |
| 158 |
- name: Build and Test |
| 159 |
uses: reactivecircus/[email protected] |
| 160 |
with: |
| 161 |
api-level: ${{ matrix.api-level }} |
| 162 |
target: ${{ matrix.target }} |
| 163 |
arch: ${{ matrix.arch }} |
| 164 |
ram-size: ${{ env.EMULATOR_RAM_SIZE }} |
| 165 |
heap-size: ${{ env.EMULATOR_HEAP_SIZE }} |
| 166 |
disk-size: ${{ env.EMULATOR_DISK_SIZE }} |
| 167 |
cores: ${{ env.EMULATOR_CORES }} |
| 168 |
force-avd-creation: false |
| 169 |
emulator-options: ${{ env.COMMON_EMULATOR_OPTIONS }} -no-snapshot-save -snapshot ${{ env.AVD_CACHE_KEY }} |
| 170 |
emulator-boot-timeout: ${{ env.EMULATOR_BOOT_TIMEOUT }} |
| 171 |
# This is not a usual script. Every line is executed in a separate shell with `sh -c`. If |
| 172 |
# one of the lines returns with error the whole script is failed (like running a script with |
| 173 |
# set -e) and in consequences the other lines (shells) are not executed. |
| 174 |
script: | |
| 175 |
util/android-commands.sh sync_host |
| 176 |
util/android-commands.sh build |
| 177 |
util/android-commands.sh tests |
| 178 |
if [ "${{ steps.rust-cache.outputs.cache-hit }}" != 'true' ]; then util/android-commands.sh sync_image; fi; exit 0 |
| 179 |
- name: Collect information about runner resources |
| 180 |
if: always() |
| 181 |
continue-on-error: true |
| 182 |
run: | |
| 183 |
free -mh |
| 184 |
df -Th |
| 185 |
- name: Save rust cache |
| 186 |
if: steps.rust-cache.outputs.cache-hit != 'true' |
| 187 |
uses: actions/cache/save@v6 |
| 188 |
with: |
| 189 |
path: ~/__rust_cache__ |
| 190 |
key: ${{ matrix.arch }}_${{ matrix.target}}_${{ steps.read_rustc_hash.outputs.content }}_${{ hashFiles('**/Cargo.toml', '**/Cargo.lock') }}_v3 |
| 191 |
- name: archive any output (error screenshots) |
| 192 |
if: always() |
| 193 |
uses: actions/upload-artifact@v7 |
| 194 |
with: |
| 195 |
name: test_output_${{ env.AVD_CACHE_KEY }} |
| 196 |
path: output |
| 197 |
- name: Collect information about runner resources |
| 198 |
if: always() |
| 199 |
continue-on-error: true |
| 200 |
run: | |
| 201 |
free -mh |
| 202 |
df -Th |