| # Licensed to the Apache Software Foundation (ASF) under one |
| # or more contributor license agreements. See the NOTICE file |
| # distributed with this work for additional information |
| # regarding copyright ownership. The ASF licenses this file |
| # to you under the Apache License, Version 2.0 (the |
| # "License"); you may not use this file except in compliance |
| # with the License. You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, |
| # software distributed under the License is distributed on an |
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| # KIND, either express or implied. See the License for the |
| # specific language governing permissions and limitations |
| # under the License. |
| |
| name: setup-rust-with-cache |
| description: Setup Rust toolchain with Swatinem/rust-cache |
| |
| inputs: |
| read-cache: |
| description: "Whether to read from cache" |
| required: false |
| default: "true" |
| shared-key: |
| description: "Shared cache key across jobs" |
| required: false |
| default: "dev" |
| save-cache: |
| description: "Whether to save cache (true/false)" |
| required: false |
| default: "false" |
| print-cache-status: |
| description: "Whether to print cache status to job summary" |
| required: false |
| default: "false" |
| |
| runs: |
| using: "composite" |
| steps: |
| - name: Install system dependencies (Linux) |
| if: runner.os == 'Linux' |
| run: | |
| sudo apt-get update |
| sudo apt-get install -y libhwloc-dev pkg-config libudev-dev |
| shell: bash |
| |
| - name: Install system dependencies (macOS) |
| if: runner.os == 'macOS' |
| run: | |
| # Pin version of hwloc to 2.12.2_1 |
| # brew extract doesn't have this version, so we fetch the formula directly |
| brew tap-new iggy/local-hwloc |
| curl -fsSL https://raw.githubusercontent.com/Homebrew/homebrew-core/bb1e23f8e5eacf4d31acd489f6079c8a53ebd690/Formula/h/hwloc.rb \ |
| -o "$(brew --repository iggy/local-hwloc)/Formula/hwloc.rb" |
| brew install iggy/local-hwloc/hwloc |
| shell: bash |
| |
| - name: Setup Rust toolchain |
| run: | |
| # macOS runners provision Rust via the Homebrew `rustup` formula, which |
| # installs only `rustup-init` plus brew shims that resolve back to it in |
| # installer mode - so `cargo` errors out and ~/.cargo/bin has no proxies. |
| # Run rustup-init once to generate the real cargo/rustc proxies. |
| if [ "$RUNNER_OS" = "macOS" ]; then |
| rustup-init -y --no-modify-path --default-toolchain none |
| fi |
| rustup show |
| echo "$HOME/.cargo/bin" >> "$GITHUB_PATH" |
| shell: bash |
| |
| - name: Setup Rust cache |
| id: rust-cache |
| if: inputs.read-cache == 'true' |
| uses: Swatinem/rust-cache@v2 |
| with: |
| shared-key: ${{ inputs.shared-key }} |
| save-if: ${{ inputs.save-cache == 'true' }} |
| |
| - name: Cache status |
| if: inputs.read-cache == 'true' && inputs.print-cache-status == 'true' |
| run: | |
| echo "### Rust Cache" >> $GITHUB_STEP_SUMMARY |
| if [ "${{ steps.rust-cache.outputs.cache-hit }}" == "true" ]; then |
| echo "✅ Cache hit" >> $GITHUB_STEP_SUMMARY |
| elif [ -d "target" ]; then |
| echo "🔶 Partial cache hit" >> $GITHUB_STEP_SUMMARY |
| else |
| echo "❌ Cache miss" >> $GITHUB_STEP_SUMMARY |
| fi |
| shell: bash |
| |
| - name: Install cargo-nextest |
| if: runner.os == 'Linux' |
| run: | |
| if command -v cargo-nextest &> /dev/null; then |
| echo "cargo-nextest already installed" |
| cargo nextest --version |
| exit 0 |
| fi |
| |
| ARCH="$(uname -m)" |
| case "$ARCH" in |
| x86_64) NEXTEST_PLATFORM="linux" ;; |
| aarch64) NEXTEST_PLATFORM="linux-arm" ;; |
| *) |
| echo "Unsupported architecture: $ARCH, skipping nextest" |
| exit 0 |
| ;; |
| esac |
| |
| curl -LsSf "https://get.nexte.st/latest/${NEXTEST_PLATFORM}" | tar xzf - -C ${CARGO_HOME:-~/.cargo}/bin |
| cargo nextest --version |
| shell: bash |
| continue-on-error: true |
| |
| - name: Configure Cargo for CI |
| if: inputs.read-cache == 'true' |
| run: | |
| echo "CARGO_INCREMENTAL=0" >> $GITHUB_ENV |
| echo "CARGO_PROFILE_DEV_DEBUG=0" >> $GITHUB_ENV |
| echo "CARGO_PROFILE_TEST_DEBUG=0" >> $GITHUB_ENV |
| echo "CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse" >> $GITHUB_ENV |
| shell: bash |