From dbcc82aa67048c75a2743ac0edaf6dff62d0360e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Jun 2026 02:07:08 +0000 Subject: [PATCH 1/7] Fix TypeSpec Python regenerate workflow to fetch README template from typespec-python-generated-tests branch Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --- .github/workflows/typespec-python-regenerate.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/typespec-python-regenerate.yml b/.github/workflows/typespec-python-regenerate.yml index 979f06cacfd1..7797b965433b 100644 --- a/.github/workflows/typespec-python-regenerate.yml +++ b/.github/workflows/typespec-python-regenerate.yml @@ -143,12 +143,21 @@ jobs: run: rm -rf "_typespec" - name: Apply README template to generated test packages + env: + GH_TOKEN: ${{ github.token }} run: | set -euo pipefail TARGET="eng/tools/azure-sdk-tools/emitter/generated" - TEMPLATE="$TARGET/template/README.md" - if [ ! -f "$TEMPLATE" ]; then - echo "::error::Template README not found at $TEMPLATE" + # The emitter/generated directory (including the README template) was + # removed from main by design (PR #47288); it now lives only on the + # typespec-python-generated-tests branch. Fetch the template from there + # rather than expecting it in the main checkout. + TARGET_BRANCH="typespec-python-generated-tests" + TEMPLATE_PATH="$TARGET/template/README.md" + TEMPLATE="$(mktemp)" + if ! git fetch --no-tags --depth=1 origin "$TARGET_BRANCH" 2>/dev/null \ + || ! git show "FETCH_HEAD:$TEMPLATE_PATH" > "$TEMPLATE" 2>/dev/null; then + echo "::error::Template README not found at $TEMPLATE_PATH on branch $TARGET_BRANCH" exit 1 fi # Replace every README.md under generated/ with the template, except: @@ -159,6 +168,7 @@ jobs: ! -path "$TARGET/README.md" \ ! -path "$TARGET/template/*" \ -print -exec cp -f "$TEMPLATE" {} \; + rm -f "$TEMPLATE" - name: Create or update tracking issue with PR link env: From ce1afd8c09fc37ab1f03c2e0fdeb83b36990a45e Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Mon, 15 Jun 2026 11:03:47 +0800 Subject: [PATCH 2/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .github/workflows/typespec-python-regenerate.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/typespec-python-regenerate.yml b/.github/workflows/typespec-python-regenerate.yml index 7797b965433b..58e45d29f708 100644 --- a/.github/workflows/typespec-python-regenerate.yml +++ b/.github/workflows/typespec-python-regenerate.yml @@ -143,8 +143,6 @@ jobs: run: rm -rf "_typespec" - name: Apply README template to generated test packages - env: - GH_TOKEN: ${{ github.token }} run: | set -euo pipefail TARGET="eng/tools/azure-sdk-tools/emitter/generated" From aa6964df030bb36e0c98388ccb321f734fede078 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Mon, 15 Jun 2026 11:04:04 +0800 Subject: [PATCH 3/7] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .github/workflows/typespec-python-regenerate.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/typespec-python-regenerate.yml b/.github/workflows/typespec-python-regenerate.yml index 58e45d29f708..9d9eb50180e3 100644 --- a/.github/workflows/typespec-python-regenerate.yml +++ b/.github/workflows/typespec-python-regenerate.yml @@ -153,6 +153,7 @@ jobs: TARGET_BRANCH="typespec-python-generated-tests" TEMPLATE_PATH="$TARGET/template/README.md" TEMPLATE="$(mktemp)" + trap 'rm -f "$TEMPLATE"' EXIT if ! git fetch --no-tags --depth=1 origin "$TARGET_BRANCH" 2>/dev/null \ || ! git show "FETCH_HEAD:$TEMPLATE_PATH" > "$TEMPLATE" 2>/dev/null; then echo "::error::Template README not found at $TEMPLATE_PATH on branch $TARGET_BRANCH" From 4935af0b900da92d6689afa4149c2c0aaa8e816f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Jun 2026 03:50:46 +0000 Subject: [PATCH 4/7] Update typespec regenerate workflow to use generated-tests branch layout Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --- .../workflows/typespec-python-regenerate.yml | 57 +++++++------------ 1 file changed, 19 insertions(+), 38 deletions(-) diff --git a/.github/workflows/typespec-python-regenerate.yml b/.github/workflows/typespec-python-regenerate.yml index 9d9eb50180e3..09a39331f34e 100644 --- a/.github/workflows/typespec-python-regenerate.yml +++ b/.github/workflows/typespec-python-regenerate.yml @@ -130,6 +130,22 @@ jobs: run: | npm run regenerate + - name: Checkout generated tests source branch + run: | + set -euo pipefail + TARGET_BRANCH="typespec-python-generated-tests" + PR_NUMBER="${{ steps.typespec-info.outputs.typespec_pr_number }}" + if [ -n "$PR_NUMBER" ]; then + SOURCE_BRANCH="regen/typespec-python-pr-${PR_NUMBER}" + else + SOURCE_BRANCH="regen/typespec-python-main" + fi + if ! git fetch --no-tags --depth=1 origin "$TARGET_BRANCH" 2>/dev/null; then + echo "::error::Branch $TARGET_BRANCH not found. It must exist because it contains eng/tools/azure-sdk-tools/emitter/generated/template/README.md." + exit 1 + fi + git checkout -B "$SOURCE_BRANCH" "origin/$TARGET_BRANCH" + - name: Copy regenerated tests run: | set -euo pipefail @@ -146,17 +162,9 @@ jobs: run: | set -euo pipefail TARGET="eng/tools/azure-sdk-tools/emitter/generated" - # The emitter/generated directory (including the README template) was - # removed from main by design (PR #47288); it now lives only on the - # typespec-python-generated-tests branch. Fetch the template from there - # rather than expecting it in the main checkout. - TARGET_BRANCH="typespec-python-generated-tests" - TEMPLATE_PATH="$TARGET/template/README.md" - TEMPLATE="$(mktemp)" - trap 'rm -f "$TEMPLATE"' EXIT - if ! git fetch --no-tags --depth=1 origin "$TARGET_BRANCH" 2>/dev/null \ - || ! git show "FETCH_HEAD:$TEMPLATE_PATH" > "$TEMPLATE" 2>/dev/null; then - echo "::error::Template README not found at $TEMPLATE_PATH on branch $TARGET_BRANCH" + TEMPLATE="$TARGET/template/README.md" + if [ ! -f "$TEMPLATE" ]; then + echo "::error::Template README not found at $TEMPLATE" exit 1 fi # Replace every README.md under generated/ with the template, except: @@ -167,7 +175,6 @@ jobs: ! -path "$TARGET/README.md" \ ! -path "$TARGET/template/*" \ -print -exec cp -f "$TEMPLATE" {} \; - rm -f "$TEMPLATE" - name: Create or update tracking issue with PR link env: @@ -196,32 +203,6 @@ jobs: SOURCE_LABEL="microsoft/typespec@main" SOURCE_BRANCH="regen/typespec-python-main" fi - - # Save regenerated files to a temp dir before switching branches, - # since they are untracked and would be lost on checkout. - TMPDIR=$(mktemp -d) - cp -r "$GENERATED_DIR"/. "$TMPDIR" - - # Ensure the target branch exists; create from origin/main if not. - git fetch --no-tags --depth=1 origin main - if ! git fetch --no-tags --depth=1 origin "$TARGET_BRANCH" 2>/dev/null; then - git push origin "origin/main:refs/heads/$TARGET_BRANCH" - git fetch --no-tags --depth=1 origin "$TARGET_BRANCH" - fi - - # Clean up untracked generated files so checkout doesn't conflict. - rm -rf "$GENERATED_DIR" - - # Create source branch based on the target branch. - git checkout -B "$SOURCE_BRANCH" "origin/$TARGET_BRANCH" - - # Restore regenerated files from the temp dir. - mkdir -p "$GENERATED_DIR" - # Use ${var:?} so that if GENERATED_DIR is empty, the command aborts - # instead of expanding to "rm -rf /*" and deleting the filesystem. - rm -rf "${GENERATED_DIR:?}"/* - cp -r "$TMPDIR"/. "$GENERATED_DIR" - rm -rf "$TMPDIR" git add -f "$GENERATED_DIR"/ if git diff --cached --quiet; then From 11757f5b86ec001a9dda3fc99a8886d2da0d38cc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Jun 2026 03:51:48 +0000 Subject: [PATCH 5/7] Preserve regenerated tests before switching workflow branches Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --- .github/workflows/typespec-python-regenerate.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/typespec-python-regenerate.yml b/.github/workflows/typespec-python-regenerate.yml index 09a39331f34e..931b3fa4ab9e 100644 --- a/.github/workflows/typespec-python-regenerate.yml +++ b/.github/workflows/typespec-python-regenerate.yml @@ -130,6 +130,16 @@ jobs: run: | npm run regenerate + - name: Stage regenerated tests + run: | + set -euo pipefail + GENERATED_STAGE_DIR="${RUNNER_TEMP}/typespec-python-generated" + rm -rf "$GENERATED_STAGE_DIR" + mkdir -p "$GENERATED_STAGE_DIR" + cp -r "_typespec/packages/http-client-python/tests/generated/azure" "$GENERATED_STAGE_DIR/azure" + cp -r "_typespec/packages/http-client-python/tests/generated/unbranded" "$GENERATED_STAGE_DIR/unbranded" + echo "GENERATED_STAGE_DIR=$GENERATED_STAGE_DIR" >> "$GITHUB_ENV" + - name: Checkout generated tests source branch run: | set -euo pipefail @@ -152,11 +162,11 @@ jobs: TARGET="eng/tools/azure-sdk-tools/emitter/generated" rm -rf "$TARGET/azure" "$TARGET/unbranded" mkdir -p "$TARGET" - cp -r "_typespec/packages/http-client-python/tests/generated/azure" "$TARGET/azure" - cp -r "_typespec/packages/http-client-python/tests/generated/unbranded" "$TARGET/unbranded" + cp -r "$GENERATED_STAGE_DIR/azure" "$TARGET/azure" + cp -r "$GENERATED_STAGE_DIR/unbranded" "$TARGET/unbranded" - name: Clean up typespec checkout - run: rm -rf "_typespec" + run: rm -rf "_typespec" "$GENERATED_STAGE_DIR" - name: Apply README template to generated test packages run: | From 37b798c1434952bfa3ddd6efa2416900330267ae Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Jun 2026 03:52:39 +0000 Subject: [PATCH 6/7] Harden generated-tests workflow branch setup Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --- .github/workflows/typespec-python-regenerate.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/typespec-python-regenerate.yml b/.github/workflows/typespec-python-regenerate.yml index 931b3fa4ab9e..03c76c5ebb2f 100644 --- a/.github/workflows/typespec-python-regenerate.yml +++ b/.github/workflows/typespec-python-regenerate.yml @@ -151,7 +151,7 @@ jobs: SOURCE_BRANCH="regen/typespec-python-main" fi if ! git fetch --no-tags --depth=1 origin "$TARGET_BRANCH" 2>/dev/null; then - echo "::error::Branch $TARGET_BRANCH not found. It must exist because it contains eng/tools/azure-sdk-tools/emitter/generated/template/README.md." + echo "::error::Branch $TARGET_BRANCH not found. Initialize it with eng/tools/azure-sdk-tools/emitter/generated/template/README.md before rerunning this workflow." exit 1 fi git checkout -B "$SOURCE_BRANCH" "origin/$TARGET_BRANCH" @@ -166,7 +166,7 @@ jobs: cp -r "$GENERATED_STAGE_DIR/unbranded" "$TARGET/unbranded" - name: Clean up typespec checkout - run: rm -rf "_typespec" "$GENERATED_STAGE_DIR" + run: rm -rf "_typespec" "${GENERATED_STAGE_DIR:-}" - name: Apply README template to generated test packages run: | From 7bbf397893c39bda4b5a6748c2da35a6ed689259 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Jun 2026 03:53:27 +0000 Subject: [PATCH 7/7] Refine workflow cleanup and branch error handling Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --- .github/workflows/typespec-python-regenerate.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/typespec-python-regenerate.yml b/.github/workflows/typespec-python-regenerate.yml index 03c76c5ebb2f..e1e6fd7f951d 100644 --- a/.github/workflows/typespec-python-regenerate.yml +++ b/.github/workflows/typespec-python-regenerate.yml @@ -151,7 +151,7 @@ jobs: SOURCE_BRANCH="regen/typespec-python-main" fi if ! git fetch --no-tags --depth=1 origin "$TARGET_BRANCH" 2>/dev/null; then - echo "::error::Branch $TARGET_BRANCH not found. Initialize it with eng/tools/azure-sdk-tools/emitter/generated/template/README.md before rerunning this workflow." + echo "::error::Branch $TARGET_BRANCH not found. Initialize it from the generated-tests history so eng/tools/azure-sdk-tools/emitter/generated/template/README.md is present before rerunning this workflow." exit 1 fi git checkout -B "$SOURCE_BRANCH" "origin/$TARGET_BRANCH" @@ -166,7 +166,11 @@ jobs: cp -r "$GENERATED_STAGE_DIR/unbranded" "$TARGET/unbranded" - name: Clean up typespec checkout - run: rm -rf "_typespec" "${GENERATED_STAGE_DIR:-}" + run: | + rm -rf "_typespec" + if [ -n "${GENERATED_STAGE_DIR:-}" ]; then + rm -rf "$GENERATED_STAGE_DIR" + fi - name: Apply README template to generated test packages run: |