diff --git a/.azure-pipelines/scripts/compare-typescript-pr-dt.sh b/.azure-pipelines/scripts/compare-typescript-pr-dt.sh new file mode 100644 index 0000000000..c3a01e46ad --- /dev/null +++ b/.azure-pipelines/scripts/compare-typescript-pr-dt.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -euo pipefail + +: "${PIPELINE_WORKSPACE:?}" + +pr_errors="$PIPELINE_WORKSPACE/pr/errors.txt" +main_errors="$PIPELINE_WORKSPACE/main/errors.txt" + +echo +echo "=== Errors only in main ===" +diff --changed-group-format='%<' --unchanged-group-format='' "$main_errors" "$pr_errors" | grep -Ev '^(===|[12]>)' || true + +echo +echo "=== Errors only in branch ===" +diff --changed-group-format='%>' --unchanged-group-format='' "$main_errors" "$pr_errors" | grep -Ev '^(===|[12]>)' || true diff --git a/.azure-pipelines/scripts/run-typescript-pr-dt.sh b/.azure-pipelines/scripts/run-typescript-pr-dt.sh index 09f3a7c623..e17955a561 100644 --- a/.azure-pipelines/scripts/run-typescript-pr-dt.sh +++ b/.azure-pipelines/scripts/run-typescript-pr-dt.sh @@ -2,95 +2,45 @@ set -euo pipefail -: "${EXPECTED_BASE_SHA:?}" -: "${EXPECTED_HEAD_SHA:?}" -: "${EXPECTED_MERGE_SHA:?}" : "${PIPELINE_WORKSPACE:?}" : "${SHARD_COUNT:?}" : "${SHARD_ID:?}" -typescript_path="$PIPELINE_WORKSPACE/s/TypeScript" -actual_merge_sha=$(git -C "$typescript_path" rev-parse HEAD) -actual_base_sha=$(git -C "$typescript_path" rev-parse HEAD^1) -actual_head_sha=$(git -C "$typescript_path" rev-parse HEAD^2) - -verify_sha() { - local label=$1 - local actual=$2 - local expected=$3 - if [[ "$actual" != "$expected" ]]; then - echo "$label SHA mismatch: expected $expected, got $actual" >&2 +label=${1:?Usage: $0 PR|main} +case "$label" in + PR) + root="$PIPELINE_WORKSPACE/pr" + failures="$root/prFailures${SHARD_ID}.json" + ;; + main) + root="$PIPELINE_WORKSPACE/main" + failures="$root/mainFailures${SHARD_ID}.json" + ;; + *) + echo "Unknown run label: $label" >&2 exit 1 - fi -} - -verify_sha merge "$actual_merge_sha" "$EXPECTED_MERGE_SHA" -verify_sha base "$actual_base_sha" "$EXPECTED_BASE_SHA" -verify_sha head "$actual_head_sha" "$EXPECTED_HEAD_SHA" - -build_typescript() { - npm ci - npm run build - npx hereby build:api -} - -run_dtslint() { - local label=$1 - local root=$2 - local failures=$3 - local errors="$root/errors.txt" + ;; +esac - mkdir -p "$root" - echo "$label run: Shard $SHARD_ID of $SHARD_COUNT" - - pushd "$dt_path" >/dev/null - set +o pipefail - pnpm dtslint-runner \ - --path . \ - --localTypeScriptPath "$local_typescript_path" \ - --selection all \ - --expectOnly \ - --shardId "$SHARD_ID" \ - --shardCount "$SHARD_COUNT" \ - --writeFailures "$failures" 3>&1 1>&2 2>&3 | tee -a "$errors" - set -o pipefail - popd >/dev/null -} - -pushd "$typescript_path" >/dev/null -build_typescript -popd >/dev/null +tools_path="$PIPELINE_WORKSPACE/s/DefinitelyTyped-tools" +typescript_path="$PIPELINE_WORKSPACE/s/TypeScript" local_typescript_path="$typescript_path/packages/typescript" - dt_path="$PIPELINE_WORKSPACE/s/DefinitelyTyped" -pushd "$dt_path" >/dev/null -npm install --global "$(jq -r '.packageManager' package.json)" -pnpm install -popd >/dev/null +errors="$root/errors.txt" -run_dtslint \ - PR \ - "$PIPELINE_WORKSPACE/pr" \ - "$PIPELINE_WORKSPACE/pr/prFailures${SHARD_ID}.json" +mkdir -p "$root" +echo "$label run: Shard $SHARD_ID of $SHARD_COUNT" +echo "dtslint runner: $tools_path/packages/dtslint-runner/dist/index.js" -git -C "$typescript_path" clean -xdf -git -C "$typescript_path" switch --detach "$EXPECTED_BASE_SHA" -pushd "$typescript_path" >/dev/null -build_typescript +pushd "$dt_path" >/dev/null +set +o pipefail +node "$tools_path/packages/dtslint-runner/dist/index.js" \ + --path . \ + --localTypeScriptPath "$local_typescript_path" \ + --selection all \ + --expectOnly \ + --shardId "$SHARD_ID" \ + --shardCount "$SHARD_COUNT" \ + --writeFailures "$failures" 3>&1 1>&2 2>&3 | tee -a "$errors" +set -o pipefail popd >/dev/null - -run_dtslint \ - main \ - "$PIPELINE_WORKSPACE/main" \ - "$PIPELINE_WORKSPACE/main/mainFailures${SHARD_ID}.json" - -pr_errors="$PIPELINE_WORKSPACE/pr/errors.txt" -main_errors="$PIPELINE_WORKSPACE/main/errors.txt" - -echo -echo "=== Errors only in main ===" -diff --changed-group-format='%<' --unchanged-group-format='' "$main_errors" "$pr_errors" | grep -Ev '^(===|[12]>)' || true - -echo -echo "=== Errors only in branch ===" -diff --changed-group-format='%>' --unchanged-group-format='' "$main_errors" "$pr_errors" | grep -Ev '^(===|[12]>)' || true diff --git a/.azure-pipelines/typescript-pr-dt.yml b/.azure-pipelines/typescript-pr-dt.yml index 016c20cdb4..0d9a21d14d 100644 --- a/.azure-pipelines/typescript-pr-dt.yml +++ b/.azure-pipelines/typescript-pr-dt.yml @@ -88,16 +88,94 @@ jobs: version: "1.27" goDownloadUrl: https://aka.ms/golang/release/latest - - bash: bash .azure-pipelines/scripts/run-typescript-pr-dt.sh - displayName: Run TypeScript PR DT comparison - workingDirectory: $(Pipeline.Workspace)/s/DefinitelyTyped-tools + - bash: | + set -euo pipefail + verify_sha() { + local label=$1 + local actual=$2 + local expected=$3 + if [[ "$actual" != "$expected" ]]; then + echo "$label SHA mismatch: expected $expected, got $actual" >&2 + exit 1 + fi + } + verify_sha merge "$(git rev-parse HEAD)" "$EXPECTED_MERGE_SHA" + verify_sha base "$(git rev-parse HEAD^1)" "$EXPECTED_BASE_SHA" + verify_sha head "$(git rev-parse HEAD^2)" "$EXPECTED_HEAD_SHA" + displayName: Verify TypeScript checkout + workingDirectory: $(Pipeline.Workspace)/s/TypeScript env: EXPECTED_BASE_SHA: ${{ parameters.expected_base_sha }} EXPECTED_HEAD_SHA: ${{ parameters.expected_head_sha }} EXPECTED_MERGE_SHA: ${{ parameters.expected_merge_sha }} + + - bash: | + set -euo pipefail + npm install --global "$(jq -r '.packageManager' package.json)" + pnpm install --frozen-lockfile + displayName: Install DefinitelyTyped tools dependencies + workingDirectory: $(Pipeline.Workspace)/s/DefinitelyTyped-tools + + - bash: pnpm build + displayName: Build DefinitelyTyped tools + workingDirectory: $(Pipeline.Workspace)/s/DefinitelyTyped-tools + + - bash: npm ci + displayName: Install PR TypeScript dependencies + workingDirectory: $(Pipeline.Workspace)/s/TypeScript + + - bash: | + set -euo pipefail + npm run build + npx hereby build:api + displayName: Build PR TypeScript + workingDirectory: $(Pipeline.Workspace)/s/TypeScript + + - bash: | + set -euo pipefail + npm install --global "$(jq -r '.packageManager' package.json)" + pnpm install + displayName: Install DefinitelyTyped dependencies + workingDirectory: $(Pipeline.Workspace)/s/DefinitelyTyped + + - bash: bash .azure-pipelines/scripts/run-typescript-pr-dt.sh PR + displayName: Run dtslint with PR TypeScript + workingDirectory: $(Pipeline.Workspace)/s/DefinitelyTyped-tools + env: SHARD_COUNT: $(System.TotalJobsInPhase) SHARD_ID: $(System.JobPositionInPhase) + - bash: | + set -euo pipefail + git clean -xdf + git switch --detach "$EXPECTED_BASE_SHA" + displayName: Prepare base TypeScript checkout + workingDirectory: $(Pipeline.Workspace)/s/TypeScript + env: + EXPECTED_BASE_SHA: ${{ parameters.expected_base_sha }} + + - bash: npm ci + displayName: Install base TypeScript dependencies + workingDirectory: $(Pipeline.Workspace)/s/TypeScript + + - bash: | + set -euo pipefail + npm run build + npx hereby build:api + displayName: Build base TypeScript + workingDirectory: $(Pipeline.Workspace)/s/TypeScript + + - bash: bash .azure-pipelines/scripts/run-typescript-pr-dt.sh main + displayName: Run dtslint with base TypeScript + workingDirectory: $(Pipeline.Workspace)/s/DefinitelyTyped-tools + env: + SHARD_COUNT: $(System.TotalJobsInPhase) + SHARD_ID: $(System.JobPositionInPhase) + + - bash: bash .azure-pipelines/scripts/compare-typescript-pr-dt.sh + displayName: Compare dtslint logs + workingDirectory: $(Pipeline.Workspace)/s/DefinitelyTyped-tools + - publish: $(Pipeline.Workspace)/pr/prFailures$(System.JobPositionInPhase).json displayName: Publish PR failures artifact: prFailures$(System.JobPositionInPhase)