# Generated from xtask::workflows::run_tests
# Rebuild with `cargo xtask workflows`.
name: run_tests
env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: '1'
  CARGO_INCREMENTAL: '0'
on:
  pull_request:
    branches:
    - '**'
  push:
    branches:
    - main
    - v[0-9]+.[0-9]+.x
jobs:
  orchestrate:
    if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions')
    runs-on: namespace-profile-2x4-ubuntu-2404
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
        fetch-depth: ${{ github.ref == 'refs/heads/main' && 2 || 350 }}
    - id: filter
      name: filter
      run: |
        set -euo pipefail
        if [ -z "$GITHUB_BASE_REF" ]; then
          echo "Not in a PR context (i.e., push to main/stable/preview)"
          COMPARE_REV="$(git rev-parse HEAD~1)"
        else
          echo "In a PR context comparing to pull_request.base.ref"
          git fetch origin "$GITHUB_BASE_REF" --depth=350
          COMPARE_REV="$(git merge-base "origin/${GITHUB_BASE_REF}" HEAD)"
        fi
        CHANGED_FILES="$(git diff --name-only "$COMPARE_REV" "$GITHUB_SHA")"

        check_pattern() {
          local output_name="$1"
          local pattern="$2"
          local grep_arg="$3"

          echo "$CHANGED_FILES" | grep "$grep_arg" "$pattern" && \
            echo "${output_name}=true" >> "$GITHUB_OUTPUT" || \
            echo "${output_name}=false" >> "$GITHUB_OUTPUT"
        }

        # Check for changes that require full rebuild (no filter)
        # Direct pushes to main/stable/preview always run full suite
        if [ -z "$GITHUB_BASE_REF" ]; then
          echo "Not a PR, running full test suite"
          echo "changed_packages=" >> "$GITHUB_OUTPUT"
        elif echo "$CHANGED_FILES" | grep -qP '^(rust-toolchain\.toml|\.cargo/|\.github/|Cargo\.(toml|lock)$)'; then
          echo "Toolchain, cargo config, or root Cargo files changed, will run all tests"
          echo "changed_packages=" >> "$GITHUB_OUTPUT"
        else
          # Extract changed directories from file paths
          CHANGED_DIRS=$(echo "$CHANGED_FILES" | \
            grep -oP '^(crates|tooling)/\K[^/]+' | \
            sort -u || true)

          # Build directory-to-package mapping using cargo metadata
          DIR_TO_PKG=$(cargo metadata --format-version=1 --no-deps 2>/dev/null | \
            jq -r '.packages[] | select(.manifest_path | test("crates/|tooling/")) | "\(.manifest_path | capture("(crates|tooling)/(?<dir>[^/]+)") | .dir)=\(.name)"')

          # Map directory names to package names
          FILE_CHANGED_PKGS=""
          for dir in $CHANGED_DIRS; do
            pkg=$(echo "$DIR_TO_PKG" | grep "^${dir}=" | cut -d= -f2 | head -1)
            if [ -n "$pkg" ]; then
              FILE_CHANGED_PKGS=$(printf '%s\n%s' "$FILE_CHANGED_PKGS" "$pkg")
            else
              # Fall back to directory name if no mapping found
              FILE_CHANGED_PKGS=$(printf '%s\n%s' "$FILE_CHANGED_PKGS" "$dir")
            fi
          done
          FILE_CHANGED_PKGS=$(echo "$FILE_CHANGED_PKGS" | grep -v '^$' | sort -u || true)

          # If assets/ changed, add crates that depend on those assets
          if echo "$CHANGED_FILES" | grep -qP '^assets/'; then
            FILE_CHANGED_PKGS=$(printf '%s\n%s\n%s' "$FILE_CHANGED_PKGS" "settings" "assets" | sort -u)
          fi

          # Combine all changed packages
          ALL_CHANGED_PKGS=$(echo "$FILE_CHANGED_PKGS" | grep -v '^$' || true)

          if [ -z "$ALL_CHANGED_PKGS" ]; then
            echo "No package changes detected, will run all tests"
            echo "changed_packages=" >> "$GITHUB_OUTPUT"
          else
            # Build nextest filterset with rdeps for each package
            FILTERSET=$(echo "$ALL_CHANGED_PKGS" | \
              sed 's/.*/rdeps(&)/' | \
              tr '\n' '|' | \
              sed 's/|$//')
            echo "Changed packages filterset: $FILTERSET"
            echo "changed_packages=$FILTERSET" >> "$GITHUB_OUTPUT"
          fi
        fi

        check_pattern "run_action_checks" '^\.github/(workflows/|actions/|actionlint.yml)|tooling/xtask|script/' -qP
        check_pattern "run_docs" '^(docs/|crates/.*\.rs)' -qP
        check_pattern "run_licenses" '^(Cargo.lock|script/.*licenses)' -qP
        check_pattern "run_tests" '^(docs/|script/update_top_ranking_issues/|\.github/(ISSUE_TEMPLATE|workflows/(?!run_tests))|extensions/)' -qvP
        # Detect changed extension directories (excluding extensions/workflows)
        CHANGED_EXTENSIONS=$(echo "$CHANGED_FILES" | grep -oP '^extensions/[^/]+(?=/)' | sort -u | grep -v '^extensions/workflows$' || true)
        # Filter out deleted extensions
        EXISTING_EXTENSIONS=""
        for ext in $CHANGED_EXTENSIONS; do
            if [ -f "$ext/extension.toml" ]; then
                EXISTING_EXTENSIONS=$(printf '%s\n%s' "$EXISTING_EXTENSIONS" "$ext")
            fi
        done
        CHANGED_EXTENSIONS=$(echo "$EXISTING_EXTENSIONS" | sed '/^$/d')
        if [ -n "$CHANGED_EXTENSIONS" ]; then
            EXTENSIONS_JSON=$(echo "$CHANGED_EXTENSIONS" | jq -R -s -c 'split("\n") | map(select(length > 0))')
        else
            EXTENSIONS_JSON="[]"
        fi
        echo "changed_extensions=$EXTENSIONS_JSON" >> "$GITHUB_OUTPUT"
    outputs:
      changed_packages: ${{ steps.filter.outputs.changed_packages }}
      run_action_checks: ${{ steps.filter.outputs.run_action_checks }}
      run_docs: ${{ steps.filter.outputs.run_docs }}
      run_licenses: ${{ steps.filter.outputs.run_licenses }}
      run_tests: ${{ steps.filter.outputs.run_tests }}
      changed_extensions: ${{ steps.filter.outputs.changed_extensions }}
  check_style:
    if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions')
    runs-on: namespace-profile-4x8-ubuntu-2204
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
    - name: steps::cache_rust_dependencies_namespace
      uses: namespacelabs/nscloud-cache-action@a90bb5d4b27522ce881c6e98eebd7d7e6d1653f9
      with:
        cache: rust
        path: ~/.rustup
    - name: steps::setup_pnpm
      uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2
      with:
        version: '9'
    - name: steps::prettier
      run: ./script/prettier
    - name: steps::cargo_fmt
      run: cargo fmt --all -- --check
    - name: ./script/check-todos
      run: ./script/check-todos
    - name: ./script/check-keymaps
      run: ./script/check-keymaps
    - name: run_tests::check_style::check_for_typos
      uses: crate-ci/typos@2d0ce569feab1f8752f1dde43cc2f2aa53236e06
      with:
        config: ./typos.toml
    - name: run_tests::fetch_ts_query_ls
      uses: dsaltares/fetch-gh-release-asset@aa37ae5c44d3c9820bc12fe675e8670ecd93bd1c
      with:
        repo: ribru17/ts_query_ls
        version: tags/v3.15.1
        file: ts_query_ls-x86_64-unknown-linux-gnu.tar.gz
    - name: run_tests::run_ts_query_ls
      run: |-
        tar -xf "$GITHUB_WORKSPACE/ts_query_ls-x86_64-unknown-linux-gnu.tar.gz" -C "$GITHUB_WORKSPACE"
        "$GITHUB_WORKSPACE/ts_query_ls" format --check . || {
            echo "Found unformatted queries, please format them with ts_query_ls."
            echo "For easy use, install the Tree-sitter query extension:"
            echo "zed://extension/tree-sitter-query"
            false
        }
    timeout-minutes: 60
  clippy_windows:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.run_tests == 'true'
    runs-on: self-32vcpu-windows-2022
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
    - name: steps::setup_cargo_config
      run: |
        New-Item -ItemType Directory -Path "./../.cargo" -Force
        Copy-Item -Path "./.cargo/ci-config.toml" -Destination "./../.cargo/config.toml"
      shell: pwsh
    - name: steps::setup_sccache
      run: ./script/setup-sccache.ps1
      shell: pwsh
      env:
        R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
        R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
        R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
        SCCACHE_BUCKET: sccache-zed
    - name: steps::clippy
      run: ./script/clippy.ps1
      shell: pwsh
    - name: steps::show_sccache_stats
      run: if ($env:RUSTC_WRAPPER) { & $env:RUSTC_WRAPPER --show-stats }; exit 0
      shell: pwsh
    timeout-minutes: 60
  clippy_linux:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.run_tests == 'true'
    runs-on: namespace-profile-16x32-ubuntu-2204
    env:
      CC: clang
      CXX: clang++
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
    - name: steps::setup_cargo_config
      run: |
        mkdir -p ./../.cargo
        cp ./.cargo/ci-config.toml ./../.cargo/config.toml
    - name: steps::cache_rust_dependencies_namespace
      uses: namespacelabs/nscloud-cache-action@a90bb5d4b27522ce881c6e98eebd7d7e6d1653f9
      with:
        cache: rust
        path: ~/.rustup
    - name: steps::setup_linux
      run: ./script/linux
    - name: steps::download_wasi_sdk
      run: ./script/download-wasi-sdk
    - name: steps::setup_sccache
      run: ./script/setup-sccache
      env:
        R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
        R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
        R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
        SCCACHE_BUCKET: sccache-zed
    - name: steps::clippy
      run: ./script/clippy
    - name: steps::show_sccache_stats
      run: sccache --show-stats || true
    timeout-minutes: 60
  clippy_mac:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.run_tests == 'true'
    runs-on: namespace-profile-mac-large
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
    - name: steps::setup_cargo_config
      run: |
        mkdir -p ./../.cargo
        cp ./.cargo/ci-config.toml ./../.cargo/config.toml
    - name: steps::cache_rust_dependencies_namespace
      uses: namespacelabs/nscloud-cache-action@a90bb5d4b27522ce881c6e98eebd7d7e6d1653f9
      with:
        cache: rust
        path: ~/.rustup
    - name: steps::setup_sccache
      run: ./script/setup-sccache
      env:
        R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
        R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
        R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
        SCCACHE_BUCKET: sccache-zed
    - name: steps::clippy
      run: ./script/clippy
    - name: steps::show_sccache_stats
      run: sccache --show-stats || true
    timeout-minutes: 60
  clippy_mac_x86_64:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.run_tests == 'true'
    runs-on: namespace-profile-mac-large
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
    - name: steps::setup_cargo_config
      run: |
        mkdir -p ./../.cargo
        cp ./.cargo/ci-config.toml ./../.cargo/config.toml
    - name: steps::cache_rust_dependencies_namespace
      uses: namespacelabs/nscloud-cache-action@a90bb5d4b27522ce881c6e98eebd7d7e6d1653f9
      with:
        cache: rust
        path: ~/.rustup
    - name: steps::install_rustup_target
      run: rustup target add x86_64-apple-darwin
    - name: steps::setup_sccache
      run: ./script/setup-sccache
      env:
        R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
        R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
        R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
        SCCACHE_BUCKET: sccache-zed
    - name: steps::clippy
      run: ./script/clippy --target x86_64-apple-darwin
    - name: steps::show_sccache_stats
      run: sccache --show-stats || true
    timeout-minutes: 60
  run_tests_windows:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.run_tests == 'true'
    runs-on: self-32vcpu-windows-2022
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
    - name: steps::setup_cargo_config
      run: |
        New-Item -ItemType Directory -Path "./../.cargo" -Force
        Copy-Item -Path "./.cargo/ci-config.toml" -Destination "./../.cargo/config.toml"
      shell: pwsh
    - name: steps::setup_node
      uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
      with:
        node-version: '20'
    - name: steps::clear_target_dir_if_large
      run: ./script/clear-target-dir-if-larger-than.ps1 250
      shell: pwsh
    - name: steps::setup_sccache
      run: ./script/setup-sccache.ps1
      shell: pwsh
      env:
        R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
        R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
        R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
        SCCACHE_BUCKET: sccache-zed
    - name: steps::cargo_nextest
      run: cargo nextest run --workspace --no-fail-fast --no-tests=warn${{ needs.orchestrate.outputs.changed_packages && format(' -E "{0}"', needs.orchestrate.outputs.changed_packages) || '' }}
      shell: pwsh
    - name: steps::show_sccache_stats
      run: if ($env:RUSTC_WRAPPER) { & $env:RUSTC_WRAPPER --show-stats }; exit 0
      shell: pwsh
    - name: steps::cleanup_cargo_config
      if: always()
      run: |
        Remove-Item -Recurse -Path "./../.cargo" -Force -ErrorAction SilentlyContinue
      shell: pwsh
    timeout-minutes: 60
  run_tests_linux:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.run_tests == 'true'
    runs-on: namespace-profile-16x32-ubuntu-2204
    env:
      CC: clang
      CXX: clang++
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
    - name: steps::setup_cargo_config
      run: |
        mkdir -p ./../.cargo
        cp ./.cargo/ci-config.toml ./../.cargo/config.toml
    - name: steps::cache_rust_dependencies_namespace
      uses: namespacelabs/nscloud-cache-action@a90bb5d4b27522ce881c6e98eebd7d7e6d1653f9
      with:
        cache: rust
        path: ~/.rustup
    - name: steps::setup_linux
      run: ./script/linux
    - name: steps::download_wasi_sdk
      run: ./script/download-wasi-sdk
    - name: steps::setup_node
      uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
      with:
        node-version: '20'
    - name: steps::cargo_install_nextest
      uses: taiki-e/install-action@921e2c9f7148d7ba14cd819f417db338f63e733c
    - name: steps::clear_target_dir_if_large
      run: ./script/clear-target-dir-if-larger-than 250
    - name: steps::setup_sccache
      run: ./script/setup-sccache
      env:
        R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
        R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
        R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
        SCCACHE_BUCKET: sccache-zed
    - name: steps::cargo_nextest
      run: cargo nextest run --workspace --no-fail-fast --no-tests=warn${{ needs.orchestrate.outputs.changed_packages && format(' -E "{0}"', needs.orchestrate.outputs.changed_packages) || '' }}
    - name: steps::show_sccache_stats
      run: sccache --show-stats || true
    - name: steps::cleanup_cargo_config
      if: always()
      run: |
        rm -rf ./../.cargo
    timeout-minutes: 60
    services:
      postgres:
        image: postgres:15
        env:
          POSTGRES_HOST_AUTH_METHOD: trust
        ports:
        - 5432:5432
        options: --health-cmd pg_isready --health-interval 500ms --health-timeout 5s --health-retries 10
  run_tests_mac:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.run_tests == 'true'
    runs-on: namespace-profile-mac-large
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
    - name: steps::setup_cargo_config
      run: |
        mkdir -p ./../.cargo
        cp ./.cargo/ci-config.toml ./../.cargo/config.toml
    - name: steps::cache_rust_dependencies_namespace
      uses: namespacelabs/nscloud-cache-action@a90bb5d4b27522ce881c6e98eebd7d7e6d1653f9
      with:
        cache: rust
        path: ~/.rustup
    - name: steps::setup_node
      uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020
      with:
        node-version: '20'
    - name: steps::cargo_install_nextest
      uses: taiki-e/install-action@921e2c9f7148d7ba14cd819f417db338f63e733c
    - name: steps::clear_target_dir_if_large
      run: ./script/clear-target-dir-if-larger-than 300
    - name: steps::setup_sccache
      run: ./script/setup-sccache
      env:
        R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
        R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
        R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
        SCCACHE_BUCKET: sccache-zed
    - name: steps::cargo_nextest
      run: cargo nextest run --workspace --no-fail-fast --no-tests=warn${{ needs.orchestrate.outputs.changed_packages && format(' -E "{0}"', needs.orchestrate.outputs.changed_packages) || '' }}
    - name: steps::show_sccache_stats
      run: sccache --show-stats || true
    - name: steps::cleanup_cargo_config
      if: always()
      run: |
        rm -rf ./../.cargo
    timeout-minutes: 60
  doctests:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.run_tests == 'true'
    runs-on: namespace-profile-16x32-ubuntu-2204
    env:
      CC: clang
      CXX: clang++
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
    - name: steps::cache_rust_dependencies_namespace
      uses: namespacelabs/nscloud-cache-action@a90bb5d4b27522ce881c6e98eebd7d7e6d1653f9
      with:
        cache: rust
        path: ~/.rustup
    - name: steps::setup_linux
      run: ./script/linux
    - name: steps::download_wasi_sdk
      run: ./script/download-wasi-sdk
    - name: steps::setup_cargo_config
      run: |
        mkdir -p ./../.cargo
        cp ./.cargo/ci-config.toml ./../.cargo/config.toml
    - name: steps::setup_sccache
      run: ./script/setup-sccache
      env:
        R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
        R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
        R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
        SCCACHE_BUCKET: sccache-zed
    - id: run_doctests
      name: run_tests::doctests::run_doctests
      run: |
        cargo test --workspace --doc --no-fail-fast
    - name: steps::show_sccache_stats
      run: sccache --show-stats || true
    - name: steps::cleanup_cargo_config
      if: always()
      run: |
        rm -rf ./../.cargo
    timeout-minutes: 60
  check_workspace_binaries:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.run_tests == 'true'
    runs-on: namespace-profile-8x16-ubuntu-2204
    env:
      CC: clang
      CXX: clang++
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
    - name: steps::setup_cargo_config
      run: |
        mkdir -p ./../.cargo
        cp ./.cargo/ci-config.toml ./../.cargo/config.toml
    - name: steps::cache_rust_dependencies_namespace
      uses: namespacelabs/nscloud-cache-action@a90bb5d4b27522ce881c6e98eebd7d7e6d1653f9
      with:
        cache: rust
        path: ~/.rustup
    - name: steps::setup_linux
      run: ./script/linux
    - name: steps::download_wasi_sdk
      run: ./script/download-wasi-sdk
    - name: steps::setup_sccache
      run: ./script/setup-sccache
      env:
        R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
        R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
        R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
        SCCACHE_BUCKET: sccache-zed
    - name: cargo build -p collab
      run: cargo build -p collab
    - name: cargo build --workspace --bins --examples
      run: cargo build --workspace --bins --examples
    - name: steps::show_sccache_stats
      run: sccache --show-stats || true
    - name: steps::cleanup_cargo_config
      if: always()
      run: |
        rm -rf ./../.cargo
    timeout-minutes: 60
  check_wasm:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.run_tests == 'true'
    runs-on: namespace-profile-8x16-ubuntu-2204
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
    - name: steps::setup_cargo_config
      run: |
        mkdir -p ./../.cargo
        cp ./.cargo/ci-config.toml ./../.cargo/config.toml
    - name: steps::cache_rust_dependencies_namespace
      uses: namespacelabs/nscloud-cache-action@a90bb5d4b27522ce881c6e98eebd7d7e6d1653f9
      with:
        cache: rust
        path: ~/.rustup
    - name: run_tests::check_wasm::install_nightly_wasm_toolchain
      run: rustup toolchain install nightly --component rust-src --target wasm32-unknown-unknown
    - name: steps::setup_sccache
      run: ./script/setup-sccache
      env:
        R2_ACCOUNT_ID: ${{ secrets.R2_ACCOUNT_ID }}
        R2_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
        R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
        SCCACHE_BUCKET: sccache-zed
    - name: run_tests::check_wasm::cargo_check_wasm
      run: cargo +nightly -Zbuild-std=std,panic_abort check --target wasm32-unknown-unknown -p gpui_platform
      env:
        CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUSTFLAGS: -C target-feature=+atomics,+bulk-memory,+mutable-globals
    - name: steps::show_sccache_stats
      run: sccache --show-stats || true
    - name: steps::cleanup_cargo_config
      if: always()
      run: |
        rm -rf ./../.cargo
    timeout-minutes: 60
  check_dependencies:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.run_tests == 'true'
    runs-on: namespace-profile-2x4-ubuntu-2404
    env:
      CC: clang
      CXX: clang++
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
    - name: steps::cache_rust_dependencies_namespace
      uses: namespacelabs/nscloud-cache-action@a90bb5d4b27522ce881c6e98eebd7d7e6d1653f9
      with:
        cache: rust
        path: ~/.rustup
    - name: run_tests::check_dependencies::install_cargo_machete
      uses: clechasseur/rs-cargo@8435b10f6e71c2e3d4d3b7573003a8ce4bfc6386
      with:
        command: install
        args: cargo-machete@0.7.0
    - name: run_tests::check_dependencies::run_cargo_machete
      uses: clechasseur/rs-cargo@8435b10f6e71c2e3d4d3b7573003a8ce4bfc6386
      with:
        command: machete
    - name: run_tests::check_dependencies::check_cargo_lock
      run: cargo update --locked --workspace
    - name: run_tests::check_dependencies::check_vulnerable_dependencies
      if: github.event_name == 'pull_request'
      uses: actions/dependency-review-action@67d4f4bd7a9b17a0db54d2a7519187c65e339de8
      with:
        license-check: false
    timeout-minutes: 60
  check_docs:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.run_docs == 'true'
    runs-on: namespace-profile-8x16-ubuntu-2204
    env:
      CC: clang
      CXX: clang++
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
    - name: steps::setup_cargo_config
      run: |
        mkdir -p ./../.cargo
        cp ./.cargo/ci-config.toml ./../.cargo/config.toml
    - name: steps::cache_rust_dependencies_namespace
      uses: namespacelabs/nscloud-cache-action@a90bb5d4b27522ce881c6e98eebd7d7e6d1653f9
      with:
        cache: rust
        path: ~/.rustup
    - name: run_tests::check_docs::lychee_link_check
      uses: lycheeverse/lychee-action@82202e5e9c2f4ef1a55a3d02563e1cb6041e5332
      with:
        args: --no-progress --exclude '^http' './docs/src/**/*'
        fail: true
        jobSummary: false
    - name: steps::setup_linux
      run: ./script/linux
    - name: steps::download_wasi_sdk
      run: ./script/download-wasi-sdk
    - name: ./script/generate-action-metadata
      run: ./script/generate-action-metadata
    - name: run_tests::check_docs::install_mdbook
      uses: peaceiris/actions-mdbook@ee69d230fe19748b7abf22df32acaa93833fad08
      with:
        mdbook-version: 0.4.37
    - name: run_tests::check_docs::build_docs
      run: |
        mkdir -p target/deploy
        mdbook build ./docs --dest-dir=../target/deploy/docs/
    - name: run_tests::check_docs::lychee_link_check
      uses: lycheeverse/lychee-action@82202e5e9c2f4ef1a55a3d02563e1cb6041e5332
      with:
        args: --no-progress --exclude '^http' 'target/deploy/docs'
        fail: true
        jobSummary: false
    timeout-minutes: 60
  check_licenses:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.run_licenses == 'true'
    runs-on: namespace-profile-2x4-ubuntu-2404
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
    - name: steps::cache_rust_dependencies_namespace
      uses: namespacelabs/nscloud-cache-action@a90bb5d4b27522ce881c6e98eebd7d7e6d1653f9
      with:
        cache: rust
        path: ~/.rustup
    - name: ./script/check-licenses
      run: ./script/check-licenses
    - name: ./script/generate-licenses
      run: ./script/generate-licenses
  check_scripts:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.run_action_checks == 'true'
    runs-on: namespace-profile-2x4-ubuntu-2404
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
    - name: run_tests::check_scripts::run_shellcheck
      run: ./script/shellcheck-scripts error
    - id: get_actionlint
      name: run_tests::check_scripts::download_actionlint
      run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
    - name: run_tests::check_scripts::run_actionlint
      run: '"$ACTIONLINT_BIN" -color'
      env:
        ACTIONLINT_BIN: ${{ steps.get_actionlint.outputs.executable }}
    - name: steps::cache_rust_dependencies_namespace
      uses: namespacelabs/nscloud-cache-action@a90bb5d4b27522ce881c6e98eebd7d7e6d1653f9
      with:
        cache: rust
        path: ~/.rustup
    - name: run_tests::check_scripts::check_xtask_workflows
      run: |
        cargo xtask workflows
        if ! git diff --exit-code .github; then
          echo "Error: .github directory has uncommitted changes after running 'cargo xtask workflows'"
          echo "Please run 'cargo xtask workflows' locally and commit the changes"
          exit 1
        fi
    timeout-minutes: 60
  check_postgres_and_protobuf_migrations:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.run_tests == 'true'
    runs-on: namespace-profile-16x32-ubuntu-2204
    env:
      GIT_AUTHOR_NAME: Protobuf Action
      GIT_AUTHOR_EMAIL: ci@zed.dev
      GIT_COMMITTER_NAME: Protobuf Action
      GIT_COMMITTER_EMAIL: ci@zed.dev
    steps:
    - name: steps::checkout_repo
      uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd
      with:
        clean: false
        fetch-depth: 0
    - name: run_tests::check_postgres_and_protobuf_migrations::ensure_fresh_merge
      run: |
        if [ -z "$GITHUB_BASE_REF" ];
        then
          echo "BUF_BASE_BRANCH=$(git merge-base origin/main HEAD)" >> "$GITHUB_ENV"
        else
          git checkout -B temp
          git merge -q "origin/$GITHUB_BASE_REF" -m "merge main into temp"
          echo "BUF_BASE_BRANCH=$GITHUB_BASE_REF" >> "$GITHUB_ENV"
        fi
    - name: run_tests::check_postgres_and_protobuf_migrations::bufbuild_setup_action
      uses: bufbuild/buf-setup-action@v1
      with:
        version: v1.29.0
        github_token: ${{ secrets.GITHUB_TOKEN }}
    - name: run_tests::check_postgres_and_protobuf_migrations::bufbuild_breaking_action
      uses: bufbuild/buf-breaking-action@v1
      with:
        input: crates/proto/proto/
        against: https://github.com/${GITHUB_REPOSITORY}.git#branch=${BUF_BASE_BRANCH},subdir=crates/proto/proto/
    - name: run_tests::check_postgres_and_protobuf_migrations::buf_lint
      run: buf lint crates/proto/proto
    - name: run_tests::check_postgres_and_protobuf_migrations::check_protobuf_formatting
      run: buf format --diff --exit-code crates/proto/proto
    timeout-minutes: 60
  extension_tests:
    needs:
    - orchestrate
    if: needs.orchestrate.outputs.changed_extensions != '[]'
    permissions:
      contents: read
    strategy:
      matrix:
        extension: ${{ fromJson(needs.orchestrate.outputs.changed_extensions) }}
      fail-fast: false
      max-parallel: 1
    uses: ./.github/workflows/extension_tests.yml
    with:
      working-directory: ${{ matrix.extension }}
  tests_pass:
    needs:
    - orchestrate
    - check_style
    - clippy_windows
    - clippy_linux
    - clippy_mac
    - clippy_mac_x86_64
    - run_tests_windows
    - run_tests_linux
    - run_tests_mac
    - doctests
    - check_workspace_binaries
    - check_wasm
    - check_dependencies
    - check_docs
    - check_licenses
    - check_scripts
    - extension_tests
    if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions') && always()
    runs-on: namespace-profile-2x4-ubuntu-2404
    steps:
    - name: run_tests::tests_pass
      run: |
        set +x
        EXIT_CODE=0

        check_result() {
          echo "* $1: $2"
          if [[ "$2" != "skipped" && "$2" != "success" ]]; then EXIT_CODE=1; fi
        }

        check_result "orchestrate" "$RESULT_ORCHESTRATE"
        check_result "check_style" "$RESULT_CHECK_STYLE"
        check_result "clippy_windows" "$RESULT_CLIPPY_WINDOWS"
        check_result "clippy_linux" "$RESULT_CLIPPY_LINUX"
        check_result "clippy_mac" "$RESULT_CLIPPY_MAC"
        check_result "clippy_mac_x86_64" "$RESULT_CLIPPY_MAC_X86_64"
        check_result "run_tests_windows" "$RESULT_RUN_TESTS_WINDOWS"
        check_result "run_tests_linux" "$RESULT_RUN_TESTS_LINUX"
        check_result "run_tests_mac" "$RESULT_RUN_TESTS_MAC"
        check_result "doctests" "$RESULT_DOCTESTS"
        check_result "check_workspace_binaries" "$RESULT_CHECK_WORKSPACE_BINARIES"
        check_result "check_wasm" "$RESULT_CHECK_WASM"
        check_result "check_dependencies" "$RESULT_CHECK_DEPENDENCIES"
        check_result "check_docs" "$RESULT_CHECK_DOCS"
        check_result "check_licenses" "$RESULT_CHECK_LICENSES"
        check_result "check_scripts" "$RESULT_CHECK_SCRIPTS"
        check_result "extension_tests" "$RESULT_EXTENSION_TESTS"

        exit $EXIT_CODE
      env:
        RESULT_ORCHESTRATE: ${{ needs.orchestrate.result }}
        RESULT_CHECK_STYLE: ${{ needs.check_style.result }}
        RESULT_CLIPPY_WINDOWS: ${{ needs.clippy_windows.result }}
        RESULT_CLIPPY_LINUX: ${{ needs.clippy_linux.result }}
        RESULT_CLIPPY_MAC: ${{ needs.clippy_mac.result }}
        RESULT_CLIPPY_MAC_X86_64: ${{ needs.clippy_mac_x86_64.result }}
        RESULT_RUN_TESTS_WINDOWS: ${{ needs.run_tests_windows.result }}
        RESULT_RUN_TESTS_LINUX: ${{ needs.run_tests_linux.result }}
        RESULT_RUN_TESTS_MAC: ${{ needs.run_tests_mac.result }}
        RESULT_DOCTESTS: ${{ needs.doctests.result }}
        RESULT_CHECK_WORKSPACE_BINARIES: ${{ needs.check_workspace_binaries.result }}
        RESULT_CHECK_WASM: ${{ needs.check_wasm.result }}
        RESULT_CHECK_DEPENDENCIES: ${{ needs.check_dependencies.result }}
        RESULT_CHECK_DOCS: ${{ needs.check_docs.result }}
        RESULT_CHECK_LICENSES: ${{ needs.check_licenses.result }}
        RESULT_CHECK_SCRIPTS: ${{ needs.check_scripts.result }}
        RESULT_EXTENSION_TESTS: ${{ needs.extension_tests.result }}
concurrency:
  group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.ref_name == 'main' && github.sha || 'anysha' }}
  cancel-in-progress: true
defaults:
  run:
    shell: bash -euxo pipefail {0}
