Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
opt(ci): rust check/test ci performance improvements (#2989)
teo211f89d7fa3c
diff --git a/.github/actions/setup-rust/action.yml b/.github/actions/setup-rust/action.ymlindex e4dc85ab05..721163c82d 100644--- a/.github/actions/setup-rust/action.yml+++ b/.github/actions/setup-rust/action.yml@@ -1,16 +1,50 @@name: Setup Rust-description: Installs rust++description: Installs Rust and configures cargo/sccache caching.++inputs:+ sccache:+ description: Configure sccache as RUSTC_WRAPPER+ required: false+ default: 'true'+ rust-cache:+ description: Restore Swatinem/rust-cache Cargo target cache+ required: false+ default: 'false'runs:using: compositesteps:- - uses: actions-rs/toolchain@v1- with:- toolchain: stable- - name: setup rust version+ - name: setup rust toolchainshell: bash- run: rustup update stable && rustup default stable+ run: |+ set -euo pipefail++ if [[ -f rust/rust-toolchain.toml ]]; then+ toolchain="$(grep -E '^[[:space:]]*channel[[:space:]]*=' rust/rust-toolchain.toml | sed -E 's/.*"([^"]+)".*/\1/')"+ else+ toolchain="stable"+ fi++ if ! rustup run "$toolchain" rustc --version >/dev/null 2>&1; then+ rustup toolchain install "$toolchain" --profile minimal --component clippy --component rustfmt+ else+ echo "Rust toolchain $toolchain already installed: $(rustup run "$toolchain" rustc --version)"+ installed_components="$(rustup component list --toolchain "$toolchain" --installed)"+ if ! grep -q '^clippy-' <<<"$installed_components"; then+ rustup component add --toolchain "$toolchain" clippy+ fi+ if ! grep -q '^rustfmt-' <<<"$installed_components"; then+ rustup component add --toolchain "$toolchain" rustfmt+ fi+ fi++ rustup default "$toolchain"+ - name: setup sccache+ if: ${{ inputs.sccache == 'true' }}+ uses: ./.github/actions/setup-sccache- name: setup rust caching+ if: ${{ inputs.rust-cache == 'true' }}uses: Swatinem/rust-cache@v2with:shared-key: cloud-storagediff --git a/.github/actions/setup-sccache/action.yml b/.github/actions/setup-sccache/action.ymlnew file mode 100644index 0000000000..b9e7f4d332--- /dev/null+++ b/.github/actions/setup-sccache/action.yml@@ -0,0 +1,120 @@+name: Setup sccache++description: Install sccache and configure it as RUSTC_WRAPPER.++inputs:+ version:+ description: sccache release version to install+ required: false+ default: v0.15.0+ cache-key-prefix:+ description: Prefix for the local GitHub Actions cache key+ required: false+ default: sccache++runs:+ using: composite+ steps:+ - name: Install sccache+ shell: bash+ env:+ SCCACHE_VERSION: ${{ inputs.version }}+ run: |+ set -euo pipefail++ install_dir="$HOME/.local/bin"+ mkdir -p "$install_dir"++ sccache_bin="$install_dir/sccache"+ echo "$install_dir" >> "$GITHUB_PATH"++ existing_sccache="$(command -v sccache || true)"+ if [[ -n "$existing_sccache" ]] && "$existing_sccache" --version >/dev/null 2>&1; then+ installed_version="$($existing_sccache --version | awk '{print "v" $2}')"+ if [[ "$installed_version" == "$SCCACHE_VERSION" ]]; then+ if [[ "$existing_sccache" != "$sccache_bin" ]]; then+ ln -sf "$existing_sccache" "$sccache_bin"+ fi+ echo "sccache already available: $($sccache_bin --version)"+ exit 0+ fi+ fi++ if [[ -x "$sccache_bin" ]] && "$sccache_bin" --version >/dev/null 2>&1; then+ installed_version="$($sccache_bin --version | awk '{print "v" $2}')"+ if [[ "$installed_version" == "$SCCACHE_VERSION" ]]; then+ echo "sccache already installed: $($sccache_bin --version)"+ exit 0+ fi++ echo "Replacing $($sccache_bin --version) with sccache ${SCCACHE_VERSION}"+ rm -f "$sccache_bin"+ fi++ os="$(uname -s)"+ arch="$(uname -m)"+ case "${os}-${arch}" in+ Linux-x86_64)+ archive="sccache-${SCCACHE_VERSION}-x86_64-unknown-linux-musl.tar.gz"+ ;;+ Linux-aarch64|Linux-arm64)+ archive="sccache-${SCCACHE_VERSION}-aarch64-unknown-linux-musl.tar.gz"+ ;;+ Darwin-arm64)+ archive="sccache-${SCCACHE_VERSION}-aarch64-apple-darwin.tar.gz"+ ;;+ Darwin-x86_64)+ archive="sccache-${SCCACHE_VERSION}-x86_64-apple-darwin.tar.gz"+ ;;+ *)+ echo "Unsupported platform for sccache: ${os}-${arch}" >&2+ exit 1+ ;;+ esac++ tmp_dir="$(mktemp -d)"+ trap 'rm -rf "$tmp_dir"' EXIT++ basename="${archive%.tar.gz}"+ release_url="https://github.com/mozilla/sccache/releases/download/${SCCACHE_VERSION}"+ curl -fsSL "$release_url/$archive" -o "$tmp_dir/$archive"+ curl -fsSL "$release_url/$archive.sha256" -o "$tmp_dir/$archive.sha256"+ (cd "$tmp_dir" && sha256sum --check "$archive.sha256")+ tar -xzf "$tmp_dir/$archive" -C "$tmp_dir"+ rm -f "$sccache_bin"+ mv "$tmp_dir/$basename/sccache" "$sccache_bin"+ chmod +x "$sccache_bin"++ echo "Installed sccache: $($sccache_bin --version)"++ - name: Configure sccache+ shell: bash+ run: |+ set -euo pipefail++ sccache_bin="$HOME/.local/bin/sccache"+ cache_dir="$HOME/.cache/sccache"+ mkdir -p "$cache_dir"++ {+ echo "RUSTC_WRAPPER=$sccache_bin"+ echo "SCCACHE_DIR=$cache_dir"+ echo "SCCACHE_CACHE_SIZE=${SCCACHE_CACHE_SIZE:-5G}"+ echo "SCCACHE_BASEDIR=${GITHUB_WORKSPACE:-$PWD}"+ } >> "$GITHUB_ENV"++ # Configure an S3 backend when SCCACHE_BUCKET is provided. AWS credentials+ # are intentionally not persisted here; scope them to the cargo steps that+ # actually compile code so third-party setup actions don't receive them.+ if [[ -n "${SCCACHE_BUCKET:-}" ]]; then+ {+ echo "SCCACHE_BUCKET=${SCCACHE_BUCKET}"+ echo "SCCACHE_REGION=${SCCACHE_REGION:-us-east-1}"+ echo "SCCACHE_S3_KEY_PREFIX=${SCCACHE_S3_KEY_PREFIX:-sccache/}"+ } >> "$GITHUB_ENV"+ echo "Configured sccache for S3 bucket ${SCCACHE_BUCKET}"+ else+ echo "No remote sccache bucket configured; using local cached sccache directory."+ fi++ "$sccache_bin" --versiondiff --git a/.github/workflows/code-check-cloud-storage.yml b/.github/workflows/code-check-cloud-storage.ymlindex 5d96d3f8eb..96a225508e 100644--- a/.github/workflows/code-check-cloud-storage.yml+++ b/.github/workflows/code-check-cloud-storage.yml@@ -4,6 +4,14 @@ on:branches: [ 'main' ]types: [opened, synchronize, reopened, ready_for_review]+env:+ CARGO_INCREMENTAL: '0'+ CARGO_TERM_COLOR: always+ CARGO_PROFILE_DEV_DEBUG: limited+ CARGO_PROFILE_TEST_DEBUG: limited+ RUST_BACKTRACE: '1'+ RUSTFLAGS: "-C link-arg=-fuse-ld=lld"+concurrency:group: code-check-cloud-storage-${{ github.ref }}cancel-in-progress: true@@ -13,41 +21,189 @@ jobs:runs-on: ubuntu-latestoutputs:should_run: ${{ steps.filter.outputs.should_run }}+ nextest_filter: ${{ steps.package-filter.outputs.nextest_filter }}steps:- uses: actions/checkout@v6+ with:+ clean: false+ fetch-depth: 0- uses: dorny/paths-filter@v3id: filterwith:filters: |should_run:- 'rust/cloud-storage/**'+ - 'rust/rust-toolchain.toml'+ - '.github/actions/setup-rust/**'+ - '.github/actions/setup-sccache/**'- .github/workflows/code-check-cloud-storage.yml+ - name: compute nextest package filter+ id: package-filter+ if: steps.filter.outputs.should_run == 'true'+ shell: bash+ run: |+ set -euo pipefail++ if [ -z "${GITHUB_BASE_REF:-}" ]; then+ compare_rev="$(git rev-parse HEAD~1)"+ else+ git fetch origin "$GITHUB_BASE_REF:refs/remotes/origin/$GITHUB_BASE_REF"+ if ! compare_rev="$(git merge-base "origin/${GITHUB_BASE_REF}" HEAD)"; then+ echo "Unable to find merge-base for origin/${GITHUB_BASE_REF}; falling back to full test suite" >&2+ echo "nextest_filter=" >> "$GITHUB_OUTPUT"+ exit 0+ fi+ fi++ changed_files="$(git diff --name-only "$compare_rev" "$GITHUB_SHA")"+ printf '%s\n' "$changed_files" > /tmp/changed-files++ # Root cargo/toolchain/CI changes can affect the whole workspace, so run all tests.+ if printf '%s\n' "$changed_files" | grep -qE '^(rust/rust-toolchain\.toml|rust/cloud-storage/Cargo\.(toml|lock)|rust/cloud-storage/\.cargo/.*|\.github/actions/(setup-rust|setup-sccache)/.*|\.github/workflows/code-check-cloud-storage\.yml)$'; then+ echo "Workspace-level change detected; running all tests"+ echo "nextest_filter=" >> "$GITHUB_OUTPUT"+ exit 0+ fi++ filterset="$(+ python3 <<'PY'+ import glob+ import re+ from pathlib import Path++ repo = Path.cwd().resolve()+ workspace = repo / 'rust' / 'cloud-storage'+ changed_files = [line for line in Path('/tmp/changed-files').read_text().splitlines() if line]++ def workspace_members(manifest: Path) -> list[str]:+ members = []+ in_workspace = False+ in_members = False++ for raw_line in manifest.read_text().splitlines():+ line = raw_line.split('#', 1)[0].strip()+ if not line:+ continue+ if line.startswith('['):+ in_workspace = line == '[workspace]'+ continue+ if not in_workspace:+ continue+ if line.startswith('members') and '[' in line:+ in_members = True+ if in_members:+ members.extend(re.findall(r'"([^"\\]*(?:\\.[^"\\]*)*)"', line))+ if ']' in line:+ in_members = False+ return members++ def package_name(manifest: Path) -> str | None:+ in_package = False+ for raw_line in manifest.read_text().splitlines():+ line = raw_line.split('#', 1)[0].strip()+ if not line:+ continue+ if line.startswith('['):+ in_package = line == '[package]'+ continue+ if in_package:+ match = re.match(r'name\s*=\s*"([^"]+)"', line)+ if match:+ return match.group(1)+ return None++ packages = []+ for member in workspace_members(workspace / 'Cargo.toml'):+ for member_dir in glob.glob(str(workspace / member)):+ manifest = Path(member_dir) / 'Cargo.toml'+ if not manifest.exists():+ continue+ name = package_name(manifest)+ if name:+ packages.append((manifest.parent.resolve(), name))++ changed_packages = set()+ for changed_file in changed_files:+ path = (repo / changed_file).resolve()+ if path != workspace and workspace not in path.parents:+ continue++ matching_packages = [+ (manifest_dir, name)+ for manifest_dir, name in packages+ if path == manifest_dir or manifest_dir in path.parents+ ]+ if matching_packages:+ _, name = max(matching_packages, key=lambda item: len(item[0].parts))+ changed_packages.add(name)++ def escape_nextest_name(name: str) -> str:+ return (+ name+ .replace('\\', '\\\\')+ .replace(')', '\\)')+ .replace(',', '\\,')+ )++ if changed_packages:+ print('|'.join(f'rdeps(={escape_nextest_name(name)})' for name in sorted(changed_packages)))+ PY+ )"++ if [ -z "$filterset" ]; then+ echo "No package-specific Rust changes detected; running all tests"+ else+ echo "nextest filter: $filterset"+ fi+ echo "nextest_filter=$filterset" >> "$GITHUB_OUTPUT"check:needs: path-checkif: needs.path-check.outputs.should_run == 'true' && github.event.pull_request.draft == false- runs-on: linux-latest-middy+ runs-on: linux-extra-beefyenv:- CARGO_TERM_COLOR: always- RUSTFLAGS: "-Dwarnings"+ RUSTFLAGS: "-Dwarnings -C link-arg=-fuse-ld=lld"RUSTDOCFLAGS: "-Dwarnings"SQLX_OFFLINE: truesteps:- uses: actions/checkout@v6+ with:+ clean: false- uses: ./.github/actions/setup-rust+ env:+ SCCACHE_BUCKET: ${{ vars.SCCACHE_BUCKET || secrets.SCCACHE_BUCKET }}+ - name: setup lld+ run: |+ if ! command -v ld.lld >/dev/null 2>&1; then+ sudo apt-get update+ sudo apt-get install -y lld+ fi+ ld.lld --version- name: fmtrun: |cd rust/cloud-storagecargo fmt --check- name: clippy+ env:+ AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID || secrets.AWS_ACCESS_KEY }}+ AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}run: |cd rust/cloud-storagecargo clippy --all-features+ - name: show sccache stats+ if: always()+ env:+ AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID || secrets.AWS_ACCESS_KEY }}+ AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}+ run: sccache --show-stats || truetest:needs: path-checkif: needs.path-check.outputs.should_run == 'true' && github.event.pull_request.draft == false- runs-on: linux-latest-beefy+ runs-on: linux-extra-beefy+ env:+ NEXTEST_FILTER: ${{ needs.path-check.outputs.nextest_filter }}+ NEXTEST_TEST_THREADS: '32'services:postgres:image: postgres:16@@ -66,30 +222,83 @@ jobs:options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5steps:- uses: actions/checkout@v6+ with:+ clean: false- uses: ./.github/actions/setup-rust+ env:+ SCCACHE_BUCKET: ${{ vars.SCCACHE_BUCKET || secrets.SCCACHE_BUCKET }}+ - name: setup lld+ run: |+ if ! command -v ld.lld >/dev/null 2>&1; then+ sudo apt-get update+ sudo apt-get install -y lld+ fi+ ld.lld --version- uses: actions/cache@v4with:path: |- ~/.cargo/bin/~/.cargo/registry/index/~/.cargo/registry/cache/~/.cargo/git/db/key: ${{ runner.os }}-cargo-${{ hashFiles('rust/cloud-storage/Cargo.lock') }}restore-keys: |${{ runner.os }}-cargo-+ - name: check cargo-nextest+ id: check-cargo-nextest+ run: |+ if command -v cargo-nextest >/dev/null 2>&1; then+ echo "installed=true" >> "$GITHUB_OUTPUT"+ cargo nextest --version+ else+ echo "installed=false" >> "$GITHUB_OUTPUT"+ fi+ - name: install cargo-nextest+ if: steps.check-cargo-nextest.outputs.installed != 'true'+ uses: taiki-e/install-action@e32179aa3c2a47939bd07439bd80ddf13f99979f- name: install dependencies+ env:+ AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID || secrets.AWS_ACCESS_KEY }}+ AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}run: |command -v just || cargo install just --lockedcommand -v sqlx || cargo install sqlx-cli --locked- command -v cargo-nextest || cargo install cargo-nextest --locked+ - name: configure postgres for concurrent tests+ run: |+ postgres_container="$(docker ps --format '{{.ID}} {{.Image}}' | awk '$2 == "postgres:16" { print $1; exit }')"+ if [ -z "$postgres_container" ]; then+ echo "postgres:16 service container not found" >&2+ docker ps+ exit 1+ fi++ docker exec "$postgres_container" psql -U user -d macrodb -c "ALTER SYSTEM SET max_locks_per_transaction = 256;"+ docker restart "$postgres_container"+ until docker exec "$postgres_container" pg_isready -U user -d macrodb; do+ sleep 1+ done- name: prepare testsrun: |just rust/cloud-storage/setup_test_envsjust rust/cloud-storage/initialize_dbs- name: run tests+ env:+ AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID || secrets.AWS_ACCESS_KEY }}+ AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}run: |cd rust/cloud-storage- cargo nextest run --all-features++ args=(--all-features --lib --bins --tests --test-threads "$NEXTEST_TEST_THREADS")+ if [ -n "$NEXTEST_FILTER" ]; then+ args+=(-E "$NEXTEST_FILTER")+ fi++ cargo nextest run "${args[@]}"+ - name: show sccache stats+ if: always()+ env:+ AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID || secrets.AWS_ACCESS_KEY }}+ AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}+ run: sccache --show-stats || truediff-check:needs: path-check