name: "Build: Android"
run-name: "Build: Android (${{ github.ref_name }})"

on:
  push:
    branches:
      - main
    paths:
      - ".forgejo/workflows/build-android.yml"
      - "Android/**"
      - "BUILD.bazel"
      - "MODULE.bazel"
      - "MODULE.bazel.lock"
      - "bazel/android/**"
      - "Cargo.lock"
      - "Cargo.toml"
      - "crates/burrow-core/**"
      - "crates/burrow-mobile-ffi/**"
      - "rust-toolchain.toml"
      - "Scripts/ci/nscloud-cache.sh"
  pull_request:
    paths:
      - ".forgejo/workflows/build-android.yml"
      - "Android/**"
      - "BUILD.bazel"
      - "MODULE.bazel"
      - "MODULE.bazel.lock"
      - "bazel/android/**"
      - "Cargo.lock"
      - "Cargo.toml"
      - "crates/burrow-core/**"
      - "crates/burrow-mobile-ffi/**"
      - "rust-toolchain.toml"
      - "Scripts/ci/nscloud-cache.sh"
  workflow_dispatch:

permissions:
  contents: read

concurrency:
  group: burrow-build-android-${{ github.ref }}
  cancel-in-progress: true

env:
  BURROW_NIX_CACHE_URL: ${{ vars.BURROW_NIX_CACHE_URL || 'https://nix.burrow.net/burrow' }}
  BURROW_NIX_CACHE_PUBLIC_KEY: ${{ vars.BURROW_NIX_CACHE_PUBLIC_KEY }}

jobs:
  stub:
    name: Android Rust Core Stub
    runs-on: namespace-profile-linux-medium
    steps:
      - name: Checkout
        uses: https://code.forgejo.org/actions/checkout@v4
        with:
          token: ${{ github.token }}
          fetch-depth: 0

      - name: Configure Cache
        shell: bash
        run: |
          set -euo pipefail
          bash Scripts/ci/ensure-nix.sh
          nix develop .#ci -c Scripts/ci/nscloud-cache.sh bazel

      - name: Build Android Stub Check
        shell: bash
        run: |
          set -euo pipefail
          if [[ -n "${BURROW_BAZEL_NSCCACHE_BAZELRC:-}" ]]; then
            bazel --bazelrc="$BURROW_BAZEL_NSCCACHE_BAZELRC" build //bazel/android:check_stub_stamp
          else
            bazel build //bazel/android:check_stub_stamp
          fi
