diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ad9bf00..bb0ab36e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -123,9 +123,11 @@ jobs: runner: windows-2025 build-jobs: "4" - platform: macos - runner: macos-15 + runner: macos-26 + retry-runner: macos-15 build-jobs: "3" - runs-on: ${{ matrix.runner }} + # Try the other Apple Silicon image when the job is rerun. + runs-on: ${{ github.run_attempt > 1 && matrix.retry-runner || matrix.runner }} timeout-minutes: 90 env: CARGO_BUILD_JOBS: ${{ matrix.build-jobs }} @@ -210,8 +212,9 @@ jobs: - platform: windows runner: windows-2025 - platform: macos - runner: macos-15 - runs-on: ${{ matrix.runner }} + runner: macos-26 + retry-runner: macos-15 + runs-on: ${{ github.run_attempt > 1 && matrix.retry-runner || matrix.runner }} timeout-minutes: 60 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -269,9 +272,10 @@ jobs: runner: windows-2025 binary: cargo-llvm-cov.exe - platform: macos - runner: macos-15 + runner: macos-26 + retry-runner: macos-15 binary: cargo-llvm-cov - runs-on: ${{ matrix.runner }} + runs-on: ${{ github.run_attempt > 1 && matrix.retry-runner || matrix.runner }} timeout-minutes: 90 env: NC_LLVM_COV_VERSION: "0.9.1" @@ -296,7 +300,7 @@ jobs: uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5 with: path: ~/.cargo/bin/${{ matrix.binary }} - key: cargo-llvm-cov-${{ matrix.runner }}-${{ runner.arch }}-${{ env.NC_LLVM_COV_VERSION }}-${{ hashFiles('rust-toolchain.toml') }} + key: cargo-llvm-cov-${{ github.run_attempt > 1 && matrix.retry-runner || matrix.runner }}-${{ runner.arch }}-${{ env.NC_LLVM_COV_VERSION }}-${{ hashFiles('rust-toolchain.toml') }} - name: Ensure pinned coverage tool run: | if [[ "$(cargo llvm-cov --version 2>/dev/null || true)" != "cargo-llvm-cov $NC_LLVM_COV_VERSION" ]]; then diff --git a/.github/workflows/coverage-backstop.yml b/.github/workflows/coverage-backstop.yml index 954f9daa..0b8cbf2e 100644 --- a/.github/workflows/coverage-backstop.yml +++ b/.github/workflows/coverage-backstop.yml @@ -29,10 +29,11 @@ jobs: GH_TOKEN: ${{ github.token }} REPO: ${{ github.repository }} RUN_ID: ${{ github.event.workflow_run.id }} + RUN_ATTEMPT: ${{ github.event.workflow_run.run_attempt }} RUN_URL: ${{ github.event.workflow_run.html_url }} SOURCE_SHA: ${{ github.event.workflow_run.head_sha }} steps: - - name: Report unavailable or below-floor coverage + - name: Report missing coverage and close recovered alerts run: | set -euo pipefail # Ignore CI runs already in progress when this workflow first lands. @@ -40,7 +41,16 @@ jobs: if ! grep -Fxq ' coverage-floor:' <<< "$source"; then exit 0 fi + head=$(gh api "repos/$REPO/git/ref/heads/main" --jq .object.sha) + attempt_status=$(gh api "repos/$REPO/actions/runs/$RUN_ID" --jq '[.run_attempt, .status] | @tsv') + if [[ "$head" != "$SOURCE_SHA" || "$attempt_status" != "$RUN_ATTEMPT"$'\t'completed ]]; then + echo "Coverage report superseded by a newer commit or CI attempt." + exit 0 + fi for platform in linux windows macos; do + title="CI coverage needs attention on $platform" + issue=$(gh issue list --repo "$REPO" --state open --label bug --search "$title in:title" --json author,title,number \ + --jq "map(select(.title == \"$title\" and (.author.login == \"app/github-actions\" or .author.login == \"github-actions[bot]\" or .author.login == \"github-actions\"))) | first | .number // empty") dir=$(mktemp -d) report="$dir/coverage-summary.json" if gh run download "$RUN_ID" --repo "$REPO" --name "coverage-$platform" --dir "$dir" && @@ -54,16 +64,17 @@ jobs: ' "$report"); then read -r covered count <<< "$counts" if (( covered * 5 >= count * 4 )); then + if [[ -n "$issue" ]]; then + resolution=$(printf 'Coverage recovered on main: %s of %s source lines covered.\n\n[CI run %s](%s)' "$covered" "$count" "$RUN_ID" "$RUN_URL") + gh issue close "$issue" --repo "$REPO" --reason completed --comment "$resolution" + fi continue fi evidence="Covered $covered of $count source lines, below the 80% floor." else evidence="No valid line coverage report was available." fi - title="CI coverage needs attention on $platform" body=$(printf '%s\n\nSource commit %s.\n\n[CI run %s](%s)\n' "$evidence" "$SOURCE_SHA" "$RUN_ID" "$RUN_URL") - issue=$(gh issue list --repo "$REPO" --state open --label bug --search "$title in:title" --json title,number \ - --jq ".[] | select(.title == \"$title\") | .number" | head -n 1) if [[ -n "$issue" ]]; then if ! gh issue view "$issue" --repo "$REPO" --json body,comments --jq '.body, .comments[].body' | grep -F "[CI run $RUN_ID]($RUN_URL)" > /dev/null; then gh issue comment "$issue" --repo "$REPO" --body "$body" diff --git a/android/ci-setup.sh b/android/ci-setup.sh index e7f52185..9978b270 100755 --- a/android/ci-setup.sh +++ b/android/ci-setup.sh @@ -10,26 +10,58 @@ cd "$ROOT" : "${GITHUB_ENV:?this script is for GitHub Actions runners}" : "${ANDROID_HOME:?the runner has no ANDROID_HOME}" +# Retry downloads three times after the first failure, then preserve the last exit status. +retry_download() { + local delay status + for delay in 5 10 20; do + if "$@"; then + return 0 + else + status=$? + fi + printf 'Download command %s failed (exit %s); retrying in %s seconds.\n' "$1" "$status" "$delay" >&2 + sleep "$delay" + done + "$@" +} + NDK_VERSION="27.2.12479018" export JAVA_HOME="${JAVA_HOME_21_X64:-$JAVA_HOME}" echo "JAVA_HOME=$JAVA_HOME" >> "$GITHUB_ENV" sdkmanager="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" -packages=() -[[ -f "$ANDROID_HOME/platforms/android-35/android.jar" ]] || packages+=("platforms;android-35") -[[ -x "$ANDROID_HOME/build-tools/35.0.0/aapt2" ]] || packages+=("build-tools;35.0.0") -[[ -x "$ANDROID_HOME/ndk/$NDK_VERSION/ndk-build" ]] || packages+=("ndk;$NDK_VERSION") -if (( ${#packages[@]} )); then +find_missing_sdk_packages() { + packages=() + [[ -f "$ANDROID_HOME/platforms/android-35/android.jar" ]] || packages+=("platforms;android-35") + [[ -x "$ANDROID_HOME/build-tools/35.0.0/aapt2" ]] || packages+=("build-tools;35.0.0") + [[ -x "$ANDROID_HOME/ndk/$NDK_VERSION/ndk-build" ]] || packages+=("ndk;$NDK_VERSION") +} + +install_sdk_packages() { + find_missing_sdk_packages + if (( ! ${#packages[@]} )); then + return 0 + fi printf 'Installing Android SDK packages: %s\n' "${packages[*]}" + timeout --kill-after=20s 12m "$sdkmanager" --install "${packages[@]}" || return "$?" + find_missing_sdk_packages + if (( ${#packages[@]} )); then + printf 'Android SDK packages still missing after sdkmanager ran: %s\n' "${packages[*]}" >&2 + return 1 + fi +} + +find_missing_sdk_packages +if (( ${#packages[@]} )); then (yes || true) | timeout --kill-after=20s 5m "$sdkmanager" --licenses > /dev/null - timeout --kill-after=20s 12m "$sdkmanager" --install "${packages[@]}" + retry_download install_sdk_packages else echo "The requested SDK and NDK packages are already installed." fi echo "ANDROID_NDK_HOME=$ANDROID_HOME/ndk/$NDK_VERSION" >> "$GITHUB_ENV" -rustup install -rustup target add aarch64-linux-android +retry_download rustup install +retry_download rustup target add aarch64-linux-android if [[ "$(cargo ndk --version 2>/dev/null || true)" != "cargo-ndk 4.1.2" ]]; then - cargo install cargo-ndk --version 4.1.2 --locked --force + CARGO_NET_RETRY=3 cargo install cargo-ndk --version 4.1.2 --locked --force fi cargo ndk --version