Skip to content

Build quick (each platform) #1069

Build quick (each platform)

Build quick (each platform) #1069

Workflow file for this run

name: Build quick (each platform)
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
pull_request:
branches:
- "**"
push:
branches:
- main
merge_group:
env:
DEBUG: 1
concurrency:
# if a workflow is run against the same ref, only one at a time...
# ...but allow different triggers to run concurrent (push, manual flake run, scheduled flake run...)
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true
jobs:
# We want to generate our matrix dynamically
# Initial job generates the matrix as a JSON, and following job will use deserialize and use the result
matrix_prep:
# Do not run the scheduled jobs on forks
if: (github.event_name == 'schedule' && github.repository == 'ankidroid/Anki-Android-Backend') || (github.event_name != 'schedule')
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.build-matrix.outputs.result }}
steps:
- id: build-matrix
uses: actions/github-script@v7
with:
script: |
// by default, we will include all 3 platforms we test on
// "latest" would be easy everywhere, but "macos-15" isn't "latest" so we are specific there
let osArray = ["ubuntu-latest", "macos-15", "windows-latest"]
let includeArray = [];
for(const os of osArray) {
// we do this work to define 'name' so we don't need to update branch protection rules
// if the os changes, the name is used in the expanded workflow run name, which is then
// used as a "required check" on branch protection merge rules, this keeps it stable
// even if "macos-15" changes to "macos-latest" in the future so we just change the list here
// but don't have to go into organization settings / protection rules etc etc
includeArray.push({"os": os, "name": os.split('-')[0]});
}
return {
"os": osArray,
"include": includeArray,
}
- name: Debug Output
run: echo "${{ steps.build-matrix.outputs.result }}"
# This uses the matrix generated from the matrix-prep stage
build:
needs: matrix_prep
# Do not run the scheduled jobs on forks
if: (github.event_name == 'schedule' && github.repository == 'ankidroid/Anki-Android-Backend') || (github.event_name != 'schedule')
strategy:
fail-fast: false
matrix: ${{fromJson(needs.matrix_prep.outputs.matrix)}}
runs-on: ${{ matrix.os }}
timeout-minutes: 80
# Stable name so branch protection required checks set is stable regardless of runner version (-latest, -15, etc)
name: build (${{ matrix.name }})
steps:
- name: Liberate disk space (Ubuntu)
uses: jlumbroso/free-disk-space@main
if: contains(matrix.os, 'ubuntu')
with:
tool-cache: false
android: false
dotnet: true
haskell: true
large-packages: false
docker-images: true
swap-storage: false
- uses: actions/checkout@v4
- name: Install windows pre-requisites
# Windows requires git and rsync to build correctly, and specifies them from msys2
# msys2 is already in the windows action runner images, but not in path so add it
# use msys2 to install git and rsync per the README documentation in this repo
#
# note: zstd without absolute path is used in standard github cache restore though,
# and msys2 zstd is 100x slower than default, so remove msys2 zstd
if: contains(matrix.os, 'windows')
run: |
Add-Content $env:GITHUB_PATH "C:\msys64\usr\bin"
c:\msys64\usr\bin\pacman.exe -S --noconfirm git rsync
rm -force c:\msys64\usr\bin\zstd.exe
- name: Ubuntu setup
# We get KVM set up on Ubuntu as we run the emulator there (only platform with nested virt)
# We also install some system software needed for the build on ubuntu
if: contains(matrix.os, 'ubuntu')
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
sudo apt update
sudo apt -y install liblzma-dev
- name: Fetch submodules
run: git submodule update --init
- name: Read configured NDK version
run: |
cargo install toml-cli
ANDROID_NDK_VERSION=$(toml get gradle/libs.versions.toml versions.ndk --raw)
echo "ANDROID_NDK_VERSION=$ANDROID_NDK_VERSION" >> $GITHUB_ENV
shell: bash
- name: Install/Set NDK version (Unix)
if: contains(matrix.os, 'ubuntu') || contains(matrix.os, 'macos')
run: |
export PATH="$PATH:$ANDROID_HOME/cmdline-tools/latest/bin"
./.github/scripts/install_ndk.sh ${ANDROID_NDK_VERSION}
export ANDROID_NDK_LATEST_HOME="${ANDROID_SDK_ROOT}/ndk/${ANDROID_NDK_VERSION}"
echo "ANDROID_NDK_HOME=$ANDROID_NDK_LATEST_HOME" >> $GITHUB_ENV
echo "ANDROID_NDK_ROOT=$ANDROID_NDK_LATEST_HOME" >> $GITHUB_ENV
- name: Install/Set NDK version (Windows)
if: contains(matrix.os, 'windows')
run: |
$env:PATH = "$env:PATH;$env:ANDROID_HOME\cmdline-tools\latest\bin"
./.github/scripts/install_ndk.bat $env:ANDROID_NDK_VERSION
$env:ANDROID_NDK_LATEST_HOME = "$env:ANDROID_SDK_ROOT\ndk\$env:ANDROID_NDK_VERSION"
Add-Content -Path $env:GITHUB_ENV -Value ANDROID_NDK_HOME=$env:ANDROID_NDK_LATEST_HOME
Add-Content -Path $env:GITHUB_ENV -Value ANDROID_NDK_ROOT=$env:ANDROID_NDK_LATEST_HOME
- name: Configure JDK
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "21" # matches Anki-Android
- name: Restore Rust Cache (Windows)
uses: actions/cache/restore@v4
if: contains(matrix.os, 'windows')
with:
path: |
~/.cargo/registry
~/.cargo/git
target
anki/out/rust
anki/out/download
# no node_modules, as it doesn't unpack properly
key: ${{ runner.os }}-rust-debug-${{ hashFiles('Cargo.lock') }}-${{ hashFiles('anki/yarn.lock') }}
restore-keys: |
${{ runner.os }}-rust-debug
- name: Restore Rust Cache (Unix)
uses: actions/cache/restore@v4
if: contains(matrix.os, 'windows') == false
with:
path: |
~/.cargo/registry
~/.cargo/git
target
anki/out/rust
anki/out/download
anki/out/node_modules
key: ${{ runner.os }}-rust-debug-${{ hashFiles('Cargo.lock') }}-${{ hashFiles('anki/yarn.lock') }}
restore-keys: |
${{ runner.os }}-rust-debug
- name: Setup N2
run: bash ./anki/tools/install-n2
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
timeout-minutes: 5
with:
# Only write to the cache for builds on the 'main' branches, stops branches evicting main cache
# Builds on other branches will only read from main branch cache writes
# Comment this and the with: above out for performance testing on a branch
cache-read-only: ${{ github.ref != 'refs/heads/main' }}
- name: Build all (current platform)
run: cargo run -p build_rust
- name: Check Rust (Unix)
if: contains(matrix.os, 'windows') == false
run: ./check-rust.sh
- name: Check Rust (Windows)
if: contains(matrix.os, 'windows')
run: ./check-rust.bat
- name: Run tests (Unit)
run: ./gradlew test rsdroid:lint --daemon
- name: Run tests (Emulator)
uses: reactivecircus/android-emulator-runner@v2
if: contains(matrix.os, 'ubuntu')
timeout-minutes: 30
with:
api-level: 23
target: default
arch: x86_64
profile: Nexus 6
script: |
touch adb-log.txt
$ANDROID_HOME/platform-tools/adb logcat '*:D' >> adb-log.txt &
adb emu screenrecord start --time-limit 1800 video.webm
sleep 5
./gradlew rsdroid-instrumented:connectedCheck
- name: Upload rsdroid AAR as artifact
uses: actions/upload-artifact@v4
if: '!cancelled()'
with:
name: rsdroid-aar-${{ matrix.os }}
if-no-files-found: error
path: rsdroid/build/outputs/aar
- name: Upload rsdroid-robo JAR as artifact
uses: actions/upload-artifact@v4
if: '!cancelled()'
with:
name: rsdroid-robo-${{ matrix.os }}
if-no-files-found: error
path: rsdroid-testing/build/libs
- name: Upload Emulator Log
uses: actions/upload-artifact@v4
if: ('!cancelled()' && contains(matrix.os, 'ubuntu'))
with:
name: ${{ matrix.name }}-adb_logs
path: adb-log.txt
- name: Upload Emulator Screen Record
uses: actions/upload-artifact@v4
if: ('!cancelled()' && contains(matrix.os, 'ubuntu'))
with:
name: ${{ matrix.name }}-adb_video
path: video.webm
- name: Save Rust Cache (Windows)
uses: actions/cache/save@v4
if: contains(matrix.os, 'windows') && github.ref == 'refs/heads/main'
with:
path: |
~/.cargo/registry
~/.cargo/git
target
anki/out/rust
anki/out/download
# no node_modules, as it doesn't unpack properly
key: ${{ runner.os }}-rust-debug-${{ hashFiles('Cargo.lock') }}-${{ hashFiles('anki/yarn.lock') }}
- name: Save Rust Cache (Unix)
uses: actions/cache/save@v4
if: contains(matrix.os, 'windows') == false && github.ref == 'refs/heads/main'
with:
path: |
~/.cargo/registry
~/.cargo/git
target
anki/out/rust
anki/out/download
anki/out/node_modules
key: ${{ runner.os }}-rust-debug-${{ hashFiles('Cargo.lock') }}-${{ hashFiles('anki/yarn.lock') }}