extension_tests.yml

  1# Generated from xtask::workflows::extension_tests
  2# Rebuild with `cargo xtask workflows`.
  3name: extension_tests
  4env:
  5  CARGO_TERM_COLOR: always
  6  RUST_BACKTRACE: '1'
  7  CARGO_INCREMENTAL: '0'
  8  ZED_EXTENSION_CLI_SHA: 7cfce605704d41ca247e3f84804bf323f6c6caaf
  9on:
 10  workflow_call:
 11    inputs:
 12      run_tests:
 13        description: Whether the workflow should run rust tests
 14        required: true
 15        type: boolean
 16jobs:
 17  orchestrate:
 18    if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions')
 19    runs-on: namespace-profile-2x4-ubuntu-2404
 20    steps:
 21    - name: steps::checkout_repo
 22      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
 23      with:
 24        clean: false
 25        fetch-depth: ${{ github.ref == 'refs/heads/main' && 2 || 350 }}
 26    - id: filter
 27      name: filter
 28      run: |
 29        if [ -z "$GITHUB_BASE_REF" ]; then
 30          echo "Not in a PR context (i.e., push to main/stable/preview)"
 31          COMPARE_REV="$(git rev-parse HEAD~1)"
 32        else
 33          echo "In a PR context comparing to pull_request.base.ref"
 34          git fetch origin "$GITHUB_BASE_REF" --depth=350
 35          COMPARE_REV="$(git merge-base "origin/${GITHUB_BASE_REF}" HEAD)"
 36        fi
 37        CHANGED_FILES="$(git diff --name-only "$COMPARE_REV" ${{ github.sha }})"
 38
 39        check_pattern() {
 40          local output_name="$1"
 41          local pattern="$2"
 42          local grep_arg="$3"
 43
 44          echo "$CHANGED_FILES" | grep "$grep_arg" "$pattern" && \
 45            echo "${output_name}=true" >> "$GITHUB_OUTPUT" || \
 46            echo "${output_name}=false" >> "$GITHUB_OUTPUT"
 47        }
 48
 49        check_pattern "check_rust" '^(Cargo.lock|Cargo.toml|.*\.rs)$' -qP
 50        check_pattern "check_extension" '^.*\.scm$' -qP
 51      shell: bash -euxo pipefail {0}
 52    outputs:
 53      check_rust: ${{ steps.filter.outputs.check_rust }}
 54      check_extension: ${{ steps.filter.outputs.check_extension }}
 55  check_rust:
 56    needs:
 57    - orchestrate
 58    if: needs.orchestrate.outputs.check_rust == 'true'
 59    runs-on: namespace-profile-16x32-ubuntu-2204
 60    steps:
 61    - name: steps::checkout_repo
 62      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
 63      with:
 64        clean: false
 65    - name: steps::cache_rust_dependencies_namespace
 66      uses: namespacelabs/nscloud-cache-action@v1
 67      with:
 68        cache: rust
 69    - name: steps::cargo_fmt
 70      run: cargo fmt --all -- --check
 71      shell: bash -euxo pipefail {0}
 72    - name: extension_tests::run_clippy
 73      run: cargo clippy --release --all-targets --all-features -- --deny warnings
 74      shell: bash -euxo pipefail {0}
 75    - name: steps::cargo_install_nextest
 76      if: inputs.run_tests
 77      uses: taiki-e/install-action@nextest
 78    - name: steps::cargo_nextest
 79      if: inputs.run_tests
 80      run: cargo nextest run --workspace --no-fail-fast
 81      shell: bash -euxo pipefail {0}
 82    timeout-minutes: 3
 83  check_extension:
 84    needs:
 85    - orchestrate
 86    if: needs.orchestrate.outputs.check_extension == 'true'
 87    runs-on: namespace-profile-2x4-ubuntu-2404
 88    steps:
 89    - name: steps::checkout_repo
 90      uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
 91      with:
 92        clean: false
 93    - id: cache-zed-extension-cli
 94      name: extension_tests::cache_zed_extension_cli
 95      uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830
 96      with:
 97        path: zed-extension
 98        key: zed-extension-${{ env.ZED_EXTENSION_CLI_SHA }}
 99    - name: extension_tests::download_zed_extension_cli
100      if: steps.cache-zed-extension-cli.outputs.cache-hit != 'true'
101      run: |
102        wget --quiet "https://zed-extension-cli.nyc3.digitaloceanspaces.com/$ZED_EXTENSION_CLI_SHA/x86_64-unknown-linux-gnu/zed-extension"
103        chmod +x zed-extension
104      shell: bash -euxo pipefail {0}
105    - name: extension_tests::check
106      run: |
107        mkdir -p /tmp/ext-scratch
108        mkdir -p /tmp/ext-output
109        ./zed-extension --source-dir . --scratch-dir /tmp/ext-scratch --output-dir /tmp/ext-output
110      shell: bash -euxo pipefail {0}
111    timeout-minutes: 1
112  tests_pass:
113    needs:
114    - orchestrate
115    - check_rust
116    - check_extension
117    if: (github.repository_owner == 'zed-industries' || github.repository_owner == 'zed-extensions') && always()
118    runs-on: namespace-profile-2x4-ubuntu-2404
119    steps:
120    - name: run_tests::tests_pass
121      run: |
122        set +x
123        EXIT_CODE=0
124
125        check_result() {
126          echo "* $1: $2"
127          if [[ "$2" != "skipped" && "$2" != "success" ]]; then EXIT_CODE=1; fi
128        }
129
130        check_result "orchestrate" "${{ needs.orchestrate.result }}"
131        check_result "check_rust" "${{ needs.check_rust.result }}"
132        check_result "check_extension" "${{ needs.check_extension.result }}"
133
134        exit $EXIT_CODE
135      shell: bash -euxo pipefail {0}
136concurrency:
137  group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.ref_name == 'main' && github.sha || 'anysha' }}
138  cancel-in-progress: true