Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 64 additions & 32 deletions .github/workflows/build-quick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,30 @@ concurrency:
cancel-in-progress: true

jobs:
# We may have a self-hosted runner available for macOS. Use it if so.
determine-macos-runner:
runs-on: ubuntu-latest
outputs:
runner: ${{ steps.determine-macos-runner.outputs.use-runner }}
steps:
- name: Use self-hosted runner if online, otherwise public runner
id: determine-macos-runner
uses: mikehardy/runner-fallback-action@feat/orgsandents
with:
organization: "ankidroid"
# 1- Choices are single labels, emitted array element 0 is used directly below
# 2- self-hosted runner label is configured in Tartelet app on runner host
# It is in format 'macos-*' to work with our label splitter below
primary-runner: "macos-selfhosted"
fallback-runner: "macos-15"
github-token: ${{ secrets.MIKE_HARDY_ORG_ADMIN_KEY }}

# 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:
needs: determine-macos-runner
env:
MACOS_RUNNER: ${{ needs.determine-macos-runner.outputs.runner }}
# 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
Expand All @@ -34,9 +55,13 @@ jobs:
uses: actions/github-script@v8
with:
script: |
// The determine-macos-runner step emits a JSON array of labels, but we need a single label
// We configured it above to emit a single label, for either runner choice, parse it out
const macosRunner = JSON.parse(process.env.MACOS_RUNNER)[0]

// 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 osArray = ["ubuntu-latest", "windows-latest", macosRunner]

let includeArray = [];
for(const os of osArray) {
Expand Down Expand Up @@ -94,6 +119,13 @@ jobs:
c:\msys64\usr\bin\pacman.exe -S --noconfirm git rsync
rm -force c:\msys64\usr\bin\zstd.exe

- name: Install macos self-hosted pre-requisites
# All platforms require cargo to build correctly, but our self-hosted tartelet
# image doesn't have cargo (or rustup) installed by default. Easily fixed
if: contains(matrix.os, 'macos-tartelet')
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none

- 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
Expand All @@ -108,37 +140,6 @@ jobs:
- 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@v5
with:
distribution: "temurin"
java-version: "21" # matches Anki-Android

- name: Restore Rust Cache (Windows)
id: rust-cache-windows
uses: actions/cache/restore@v4
Expand Down Expand Up @@ -175,6 +176,37 @@ jobs:
${{ runner.os }}-rust-debug
${{ runner.os }}-rust

- 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@v5
with:
distribution: "temurin"
java-version: "21" # matches Anki-Android

- name: Setup N2
run: bash ./anki/tools/install-n2

Expand Down
63 changes: 44 additions & 19 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,55 @@ concurrency:
cancel-in-progress: true

jobs:
# We may have a self-hosted runner available for macOS. Use it if so.
determine-macos-runner:
runs-on: ubuntu-latest
outputs:
runner: ${{ steps.determine-macos-runner.outputs.use-runner }}
steps:
- name: Use self-hosted runner if online, otherwise public runner
id: determine-macos-runner
uses: mikehardy/runner-fallback-action@feat/orgsandents
with:
organization: "ankidroid"
# self-hosted runner label is configured in Tartelet app on runner host
primary-runner: "macos-selfhosted"
fallback-runner: "macos-15"
github-token: ${{ secrets.MIKE_HARDY_ORG_ADMIN_KEY }}

build:
runs-on: macos-15
needs: determine-macos-runner
runs-on: ${{ fromJson(needs.determine-macos-runner.outputs.runner) }}
timeout-minutes: 180
steps:
- uses: actions/checkout@v5

- name: Fetch submodules
run: git submodule update --init

- name: Install macos self-hosted pre-requisites
# All platforms require cargo to build correctly, but our self-hosted tartelet
# image doesn't have cargo (or rustup) installed by default. Easily fixed
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none

- name: Restore Rust Cache
id: rust-cache
uses: actions/cache/restore@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
anki/out/rust
anki/out/download
anki/out/extracted
anki/out/node_modules
key: ${{ runner.os }}-rust-release-${{ hashFiles('Cargo.lock', 'anki/Cargo.lock', 'anki/yarn.lock') }}
restore-keys: |
${{ runner.os }}-rust-release
${{ runner.os }}-rust

- name: Read configured NDK version
run: |
cargo install toml-cli
Expand All @@ -63,30 +103,15 @@ jobs:
java-version: "21" # matches Anki-Android

- name: Install Windows cross compiler
run: brew install mingw-w64 && x86_64-w64-mingw32-gcc -v
run: |
brew install mingw-w64
x86_64-w64-mingw32-gcc -v

- name: Install Linux cross compiler
run: |
brew install MaterializeInc/crosstools/x86_64-unknown-linux-gnu
x86_64-unknown-linux-gnu-gcc -v

- name: Restore Rust Cache
id: rust-cache
uses: actions/cache/restore@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
anki/out/rust
anki/out/download
anki/out/extracted
anki/out/node_modules
key: ${{ runner.os }}-rust-release-${{ hashFiles('Cargo.lock', 'anki/Cargo.lock', 'anki/yarn.lock') }}
restore-keys: |
${{ runner.os }}-rust-release
${{ runner.os }}-rust

- name: Setup N2
run: ./anki/tools/install-n2

Expand Down
2 changes: 0 additions & 2 deletions tools/doctor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

set -e # Error out if there were any problems

ANDROID_NDK_VERSION="27.0.12077973"

red=31
green=32
yellow=33
Expand Down
55 changes: 55 additions & 0 deletions tools/install-prerequisites-tartelet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# This script expects to be run from the tools directory in
# a local checkout of Anki-Android-Backend, e.g.
# git clone https://github.com/ankidroid/Anki-Android-Backend
# cd Anki-Android-Backend/tools

# Update the actions runner if needed?
# latest release and instructions here:
# https://github.com/actions/runner/releases

# Install rustup, but empty
#curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none

# Make sure our submodules are up to date

# Install the Rust toolchains we need
for RUST_TC in `find .. |grep rust-toolchain.toml`; do rustup toolchain install `grep channel $RUST_TC | cut -f2 -d'"'`; done

# we need protobuf
brew install protobuf
export PROTOC=`which protoc`

# install the JDK we need
brew install temurin@21

# install the NDK we need
cargo install toml-cli
export ANDROID_NDK_VERSION=$(toml get ../gradle/libs.versions.toml versions.ndk --raw)
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}"
export ANDROID_NDK_HOME=$ANDROID_NDK_LATEST_HOME

# install our cross compilers
# TODO - for BREWCMD in `grep "brew install" ../.github/workflows/build-release.yml`; do $BREWCMD; done
brew install mingw-w64
brew install MaterializeInc/crosstools/x86_64-unknown-linux-gnu

# install anki-specific build tool N2
../anki/tools/install-n2

# Warm up local caches with a run of workflow build commands
cd ..

# from build-quick.yml
cargo run -p build_rust
./check-rust.sh
./gradlew test rsdroid:lint

# from build-release.yml
export ALL_ARCHS=1
export RELEASE=1
export CARGO_PROFILE_RELEASE_LTO=fat
./build.sh
Loading