Build release (from macOS) #1918
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build release (from macOS) | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| mavenPublish: | |
| description: "Publish artifacts to Maven Central? non-empty to publish, empty to skip publish" | |
| required: false | |
| type: string | |
| schedule: | |
| - cron: "0 0 * * *" | |
| pull_request: | |
| branches: | |
| - "**" | |
| push: | |
| branches: | |
| - main | |
| merge_group: | |
| env: | |
| # NOTE: ALL_ARCHS and RELEASE variables are the *main* difference between generating | |
| # regular / single-arch builds and release builds. If you are on an Apple Silicon | |
| # mac and you want to build test for release mode, something like | |
| # 'ALL_ARCHS=1 RELEASE=1 cargo run -p build_rust' | |
| # is how you do it, once you install the cross-compilers like in the sections below | |
| ALL_ARCHS: 1 | |
| RELEASE: 1 | |
| CARGO_PROFILE_RELEASE_LTO: fat | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}-${{ github.event.inputs.mavenPublish }}-release | |
| 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 | |
| concurrency: | |
| group: runner-determination | |
| cancel-in-progress: false | |
| outputs: | |
| runner: ${{ steps.determine-macos-runner.outputs.use-runner }} | |
| steps: | |
| - name: Wait for possible parallel workflow run job startup lag | |
| # After runner choice, the job that will use it has unavoidable job startup lag | |
| # Wait for that job start / runner state change before we choose the runner for this run | |
| run: sleep 15 | |
| - name: Use self-hosted runner if online and not busy, otherwise public runner | |
| id: determine-macos-runner | |
| uses: mikehardy/runner-fallback-action@v1 | |
| with: | |
| organization: "ankidroid" | |
| # self-hosted runner label is configured in Tartelet app on runner host | |
| primary-runner: "macos-selfhosted" | |
| fallback-runner: "macos-26" | |
| primaries-required: 1 | |
| fallback-on-error: true | |
| # Actions secrets and Dependabot secrets are separate, and this is at org level:: | |
| # https://github.com/organizations/ankidroid/settings/secrets/dependabot | |
| # https://github.com/organizations/ankidroid/settings/secrets/actions | |
| github-token: ${{ secrets.MIKE_HARDY_ORG_ADMIN_KEY }} | |
| build: | |
| needs: determine-macos-runner | |
| runs-on: ${{ fromJson(needs.determine-macos-runner.outputs.runner) }} | |
| timeout-minutes: 180 | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - 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 | |
| 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 | |
| run: | | |
| export PATH="$PATH:$ANDROID_HOME/cmdline-tools/latest/bin" | |
| ./.github/scripts/install_ndk.sh ${ANDROID_NDK_VERSION} | |
| ./.github/scripts/purge_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: Configure JDK | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: "temurin" | |
| java-version: "21" # matches Anki-Android | |
| - name: Install Windows cross compiler | |
| run: | | |
| brew install --quiet mingw-w64 | |
| x86_64-w64-mingw32-gcc -v | |
| - name: Install Linux cross compiler | |
| run: | | |
| brew install --quiet MaterializeInc/crosstools/x86_64-unknown-linux-gnu | |
| x86_64-unknown-linux-gnu-gcc -v | |
| - name: Setup N2 | |
| run: ./anki/tools/install-n2 | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v5 | |
| 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 | |
| # We use retries as the build fetches network resources and those may flake | |
| uses: nick-fields/retry@v3 | |
| with: | |
| timeout_minutes: 90 | |
| max_attempts: 3 | |
| retry_wait_seconds: 0 | |
| retry_on: error | |
| command: ./build.sh | |
| - name: Upload rsdroid AAR as artifact | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: rsdroid-aar | |
| if-no-files-found: error | |
| path: rsdroid/build/outputs/aar | |
| - name: Upload rsdroid-robo JAR as artifact | |
| uses: actions/upload-artifact@v5 | |
| with: | |
| name: rsdroid-robo | |
| if-no-files-found: error | |
| path: rsdroid-testing/build/libs | |
| # following steps only run on workflow dispatch | |
| - name: Publish AAR to Maven | |
| if: "${{ github.event.inputs.mavenPublish != '' && github.event_name == 'workflow_dispatch'}}" | |
| env: | |
| ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_PRIVATE_KEY }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} | |
| ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} | |
| ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} | |
| run: | | |
| ./gradlew rsdroid:publishAllPublicationsToMavenCentral -DtestBuildType=release -Dorg.gradle.daemon=false -Dorg.gradle.console=plain | |
| - name: Publish JAR to Maven | |
| if: "${{ github.event.inputs.mavenPublish != '' && github.event_name == 'workflow_dispatch'}}" | |
| env: | |
| ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_PRIVATE_KEY }} | |
| ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }} | |
| ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }} | |
| ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} | |
| run: | | |
| export ANKIDROID_LINUX_CC=x86_64-unknown-linux-gnu-gcc | |
| export ANKIDROID_MACOS_CC=cc | |
| export RUST_DEBUG=1 | |
| export RUST_BACKTRACE=1 | |
| export RUST_LOG=trace | |
| export NO_CROSS=true | |
| ./gradlew rsdroid-testing:publishAllPublicationsToMavenCentral -Dorg.gradle.project.macCC=$ANKIDROID_MACOS_CC -DtestBuildType=debug -Dorg.gradle.daemon=false -Dorg.gradle.console=plain | |
| - name: Save Rust Cache | |
| uses: actions/cache/save@v4 | |
| if: github.ref == 'refs/heads/main' | |
| with: | |
| path: | | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| target | |
| anki/out/rust | |
| anki/out/download | |
| anki/out/extracted | |
| anki/out/node_modules | |
| key: ${{ steps.rust-cache.outputs.cache-primary-key }} |