From bf142b4cd38f7f3b3eeeeee104aa6c8bdab2492c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 20 Nov 2025 17:16:07 +0000 Subject: [PATCH 1/3] Initial plan From fc7887617ad838ca9d0fe16d62e152df3d6a3440 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 20 Nov 2025 17:34:16 +0000 Subject: [PATCH 2/3] Add HEAD-based patch generation with extensive logging - Modified generate_git_patch.sh to detect commits made to current HEAD - Added Strategy 2: Falls back to GITHUB_SHA..HEAD when no branch name found - Enhanced logging throughout patch generation process - Shows environment information, git status, and commit details - Added comprehensive tests for HEAD-based patch generation - All existing tests continue to pass Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- .github/workflows/changeset.lock.yml | 87 +++- .github/workflows/cloclo.lock.yml | 87 +++- .github/workflows/craft.lock.yml | 87 +++- .github/workflows/daily-doc-updater.lock.yml | 87 +++- .../developer-docs-consolidator.lock.yml | 87 +++- .github/workflows/dictation-prompt.lock.yml | 87 +++- .../github-mcp-tools-report.lock.yml | 87 +++- .../workflows/glossary-maintainer.lock.yml | 87 +++- .github/workflows/go-logger.lock.yml | 87 +++- .../workflows/instructions-janitor.lock.yml | 87 +++- .github/workflows/mergefest.lock.yml | 87 +++- .github/workflows/poem-bot.lock.yml | 87 +++- .github/workflows/q.lock.yml | 87 +++- .github/workflows/security-fix-pr.lock.yml | 87 +++- .../workflows/technical-doc-writer.lock.yml | 87 +++- .github/workflows/tidy.lock.yml | 87 +++- .github/workflows/unbloat-docs.lock.yml | 87 +++- pkg/workflow/git_patch_head_test.go | 397 ++++++++++++++++++ pkg/workflow/sh/generate_git_patch.sh | 97 ++++- 19 files changed, 1865 insertions(+), 108 deletions(-) create mode 100644 pkg/workflow/git_patch_head_test.go diff --git a/.github/workflows/changeset.lock.yml b/.github/workflows/changeset.lock.yml index 83a6ac899a8..41448fc022e 100644 --- a/.github/workflows/changeset.lock.yml +++ b/.github/workflows/changeset.lock.yml @@ -4654,9 +4654,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -4666,6 +4673,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -4691,13 +4699,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -4737,10 +4753,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/cloclo.lock.yml b/.github/workflows/cloclo.lock.yml index 60393c93191..afc5d3aee85 100644 --- a/.github/workflows/cloclo.lock.yml +++ b/.github/workflows/cloclo.lock.yml @@ -4726,9 +4726,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -4738,6 +4745,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -4763,13 +4771,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -4809,10 +4825,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/craft.lock.yml b/.github/workflows/craft.lock.yml index 4b87e620db1..dfcbaed2f57 100644 --- a/.github/workflows/craft.lock.yml +++ b/.github/workflows/craft.lock.yml @@ -4744,9 +4744,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -4756,6 +4763,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -4781,13 +4789,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -4827,10 +4843,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/daily-doc-updater.lock.yml b/.github/workflows/daily-doc-updater.lock.yml index 86fc3583a96..78833b3c50b 100644 --- a/.github/workflows/daily-doc-updater.lock.yml +++ b/.github/workflows/daily-doc-updater.lock.yml @@ -3415,9 +3415,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -3427,6 +3434,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -3452,13 +3460,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -3498,10 +3514,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/developer-docs-consolidator.lock.yml b/.github/workflows/developer-docs-consolidator.lock.yml index 435638b382a..9e36c6225ba 100644 --- a/.github/workflows/developer-docs-consolidator.lock.yml +++ b/.github/workflows/developer-docs-consolidator.lock.yml @@ -3967,9 +3967,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -3979,6 +3986,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -4004,13 +4012,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -4050,10 +4066,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/dictation-prompt.lock.yml b/.github/workflows/dictation-prompt.lock.yml index 9ec356f3a85..4138448f1cb 100644 --- a/.github/workflows/dictation-prompt.lock.yml +++ b/.github/workflows/dictation-prompt.lock.yml @@ -3573,9 +3573,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -3585,6 +3592,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -3610,13 +3618,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -3656,10 +3672,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/github-mcp-tools-report.lock.yml b/.github/workflows/github-mcp-tools-report.lock.yml index b3e858cf54e..81edbc5f4c1 100644 --- a/.github/workflows/github-mcp-tools-report.lock.yml +++ b/.github/workflows/github-mcp-tools-report.lock.yml @@ -3789,9 +3789,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -3801,6 +3808,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -3826,13 +3834,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -3872,10 +3888,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/glossary-maintainer.lock.yml b/.github/workflows/glossary-maintainer.lock.yml index 8853ad9c062..b896d68c390 100644 --- a/.github/workflows/glossary-maintainer.lock.yml +++ b/.github/workflows/glossary-maintainer.lock.yml @@ -4546,9 +4546,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -4558,6 +4565,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -4583,13 +4591,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -4629,10 +4645,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/go-logger.lock.yml b/.github/workflows/go-logger.lock.yml index 57e21f2eb27..d7d8436acb7 100644 --- a/.github/workflows/go-logger.lock.yml +++ b/.github/workflows/go-logger.lock.yml @@ -3534,9 +3534,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -3546,6 +3553,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -3571,13 +3579,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -3617,10 +3633,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/instructions-janitor.lock.yml b/.github/workflows/instructions-janitor.lock.yml index 0a675a97d60..394b2c37419 100644 --- a/.github/workflows/instructions-janitor.lock.yml +++ b/.github/workflows/instructions-janitor.lock.yml @@ -3413,9 +3413,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -3425,6 +3432,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -3450,13 +3458,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -3496,10 +3512,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/mergefest.lock.yml b/.github/workflows/mergefest.lock.yml index 215999cb70f..fd9e5db7e11 100644 --- a/.github/workflows/mergefest.lock.yml +++ b/.github/workflows/mergefest.lock.yml @@ -4124,9 +4124,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -4136,6 +4143,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -4161,13 +4169,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -4207,10 +4223,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/poem-bot.lock.yml b/.github/workflows/poem-bot.lock.yml index fdb8c867a38..24a2165fe32 100644 --- a/.github/workflows/poem-bot.lock.yml +++ b/.github/workflows/poem-bot.lock.yml @@ -4974,9 +4974,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -4986,6 +4993,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -5011,13 +5019,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -5057,10 +5073,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/q.lock.yml b/.github/workflows/q.lock.yml index 41717c256df..9dc34de845b 100644 --- a/.github/workflows/q.lock.yml +++ b/.github/workflows/q.lock.yml @@ -5037,9 +5037,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -5049,6 +5056,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -5074,13 +5082,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -5120,10 +5136,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/security-fix-pr.lock.yml b/.github/workflows/security-fix-pr.lock.yml index f7355ee6789..c57a44e8acc 100644 --- a/.github/workflows/security-fix-pr.lock.yml +++ b/.github/workflows/security-fix-pr.lock.yml @@ -3361,9 +3361,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -3373,6 +3380,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -3398,13 +3406,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -3444,10 +3460,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/technical-doc-writer.lock.yml b/.github/workflows/technical-doc-writer.lock.yml index 05b8c2c1bc4..3c2f8cdc1ce 100644 --- a/.github/workflows/technical-doc-writer.lock.yml +++ b/.github/workflows/technical-doc-writer.lock.yml @@ -4728,9 +4728,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -4740,6 +4747,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -4765,13 +4773,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -4811,10 +4827,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/tidy.lock.yml b/.github/workflows/tidy.lock.yml index 31874068fb1..ad93ed05bcb 100644 --- a/.github/workflows/tidy.lock.yml +++ b/.github/workflows/tidy.lock.yml @@ -3927,9 +3927,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -3939,6 +3946,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -3964,13 +3972,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -4010,10 +4026,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/.github/workflows/unbloat-docs.lock.yml b/.github/workflows/unbloat-docs.lock.yml index 9557ec0e8bd..6bfc8af9cdd 100644 --- a/.github/workflows/unbloat-docs.lock.yml +++ b/.github/workflows/unbloat-docs.lock.yml @@ -4442,9 +4442,16 @@ jobs: GITHUB_SHA: ${{ github.sha }} DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | + # Diagnostic logging: Show environment information + echo "=== Diagnostic: Environment Information ===" + echo "GITHUB_SHA: ${GITHUB_SHA}" + echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" + echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" + echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" # Diagnostic logging: Show recent commits before patch generation - echo "=== Diagnostic: Recent commits (last 5) ===" - git log --oneline -5 || echo "Failed to show git log" + echo "" + echo "=== Diagnostic: Recent commits (last 10) ===" + git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" echo "=== Diagnostic: Current git status ===" @@ -4454,6 +4461,7 @@ jobs: if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -4479,13 +4487,21 @@ jobs: fi fi done < "$GH_AW_SAFE_OUTPUTS" + else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi - # If no branch or branch doesn't exist, no patch + # If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi - # If we have a branch name, check if that branch exists and get its diff + # Strategy 1: If we have a branch name, check if that branch exists and get its diff + PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -4525,10 +4541,69 @@ jobs: # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi + # Strategy 2: Check if commits were made to current HEAD since checkout + if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi + fi + # Final status + echo "" + if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" + else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" + fi # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" diff --git a/pkg/workflow/git_patch_head_test.go b/pkg/workflow/git_patch_head_test.go new file mode 100644 index 00000000000..88f56aa3d37 --- /dev/null +++ b/pkg/workflow/git_patch_head_test.go @@ -0,0 +1,397 @@ +package workflow + +import ( + "os" + "os/exec" + "path/filepath" + "strings" + "testing" + + "github.com/githubnext/gh-aw/pkg/testutil" +) + +// TestGitPatchFromHEADCommits tests that the patch generation script can detect +// and create patches from commits made directly to HEAD (without a named branch) +func TestGitPatchFromHEADCommits(t *testing.T) { + // Create a temporary directory for the test + tmpDir := testutil.TempDir(t, "test-patch-head-*") + + // Initialize a git repository + cmd := exec.Command("git", "init") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to init git repo: %v\nOutput: %s", err, output) + } + + // Configure git user for commits + cmd = exec.Command("git", "config", "user.email", "test@example.com") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to config git email: %v\nOutput: %s", err, output) + } + + cmd = exec.Command("git", "config", "user.name", "Test User") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to config git name: %v\nOutput: %s", err, output) + } + + // Create an initial commit (this will be our GITHUB_SHA) + testFile1 := filepath.Join(tmpDir, "initial.txt") + if err := os.WriteFile(testFile1, []byte("initial content\n"), 0644); err != nil { + t.Fatalf("Failed to write initial file: %v", err) + } + + cmd = exec.Command("git", "add", "initial.txt") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to add initial file: %v\nOutput: %s", err, output) + } + + cmd = exec.Command("git", "commit", "-m", "Initial commit") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to create initial commit: %v\nOutput: %s", err, output) + } + + // Get the initial commit SHA (this simulates GITHUB_SHA) + cmd = exec.Command("git", "rev-parse", "HEAD") + cmd.Dir = tmpDir + output, err := cmd.CombinedOutput() + if err != nil { + t.Fatalf("Failed to get initial SHA: %v\nOutput: %s", err, output) + } + initialSHA := strings.TrimSpace(string(output)) + + // Now simulate the LLM making commits directly to HEAD + // Commit 1: Add a new file + testFile2 := filepath.Join(tmpDir, "new-feature.txt") + if err := os.WriteFile(testFile2, []byte("new feature content\n"), 0644); err != nil { + t.Fatalf("Failed to write new file: %v", err) + } + + cmd = exec.Command("git", "add", "new-feature.txt") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to add new file: %v\nOutput: %s", err, output) + } + + cmd = exec.Command("git", "commit", "-m", "Add new feature") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to create first commit: %v\nOutput: %s", err, output) + } + + // Commit 2: Modify existing file + if err := os.WriteFile(testFile1, []byte("initial content\nupdated by LLM\n"), 0644); err != nil { + t.Fatalf("Failed to update initial file: %v", err) + } + + cmd = exec.Command("git", "add", "initial.txt") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to add updated file: %v\nOutput: %s", err, output) + } + + cmd = exec.Command("git", "commit", "-m", "Update initial file") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to create second commit: %v\nOutput: %s", err, output) + } + + // Now run the patch generation script + // The script creates the patch at /tmp/gh-aw/aw.patch + patchFile := "/tmp/gh-aw/aw.patch" + + // Ensure the /tmp/gh-aw directory exists + if err := os.MkdirAll("/tmp/gh-aw", 0755); err != nil { + t.Fatalf("Failed to create /tmp/gh-aw directory: %v", err) + } + + // Remove any existing patch file + os.Remove(patchFile) + + // Create a minimal safe-outputs file (empty - no branch name) + safeOutputsFile := filepath.Join(tmpDir, "safe-outputs.jsonl") + if err := os.WriteFile(safeOutputsFile, []byte(""), 0644); err != nil { + t.Fatalf("Failed to write safe-outputs file: %v", err) + } + + // Run the patch generation script + scriptContent := generateGitPatchScript + scriptFile := filepath.Join(tmpDir, "generate_patch.sh") + if err := os.WriteFile(scriptFile, []byte(scriptContent), 0755); err != nil { + t.Fatalf("Failed to write script file: %v", err) + } + + cmd = exec.Command("bash", scriptFile) + cmd.Dir = tmpDir + cmd.Env = append(os.Environ(), + "GH_AW_SAFE_OUTPUTS="+safeOutputsFile, + "GITHUB_SHA="+initialSHA, + "DEFAULT_BRANCH=main", + "GITHUB_STEP_SUMMARY=/dev/null", + ) + + // Capture the output for debugging + scriptOutput, err := cmd.CombinedOutput() + t.Logf("Script output:\n%s", scriptOutput) + + if err != nil { + t.Fatalf("Failed to run patch generation script: %v\nOutput: %s", err, scriptOutput) + } + + // Verify the patch file was created + if _, err := os.Stat(patchFile); os.IsNotExist(err) { + t.Fatal("Patch file was not created") + } + + // Read and verify the patch content + patchContent, err := os.ReadFile(patchFile) + if err != nil { + t.Fatalf("Failed to read patch file: %v", err) + } + + patchStr := string(patchContent) + + // Verify the patch contains both commits + if !strings.Contains(patchStr, "Add new feature") { + t.Error("Patch does not contain first commit message") + } + + if !strings.Contains(patchStr, "Update initial file") { + t.Error("Patch does not contain second commit message") + } + + // Verify the patch contains file changes + if !strings.Contains(patchStr, "new-feature.txt") { + t.Error("Patch does not contain new file") + } + + if !strings.Contains(patchStr, "initial.txt") { + t.Error("Patch does not contain modified file") + } + + // Verify patch format (should start with "From ") + if !strings.HasPrefix(patchStr, "From ") { + t.Error("Patch does not have correct format (should start with 'From ')") + } + + // Count commits in patch (each commit starts with "From ") + commitCount := strings.Count(patchStr, "\nFrom ") + if strings.HasPrefix(patchStr, "From ") { + commitCount++ // Count the first commit + } + + if commitCount != 2 { + t.Errorf("Expected 2 commits in patch, got %d", commitCount) + } + + // Verify script logged the strategy being used + if !strings.Contains(string(scriptOutput), "Strategy 2: Checking for commits on current HEAD") { + t.Error("Script output does not indicate Strategy 2 was used") + } + + if !strings.Contains(string(scriptOutput), "GITHUB_SHA is an ancestor of HEAD - commits were added") { + t.Error("Script output does not confirm commits were detected") + } + + t.Log("Successfully generated patch from HEAD commits without named branch") +} + +// TestGitPatchPrefersBranchOverHEAD tests that when both a branch name and HEAD commits exist, +// the script prefers the branch-based approach (Strategy 1) +func TestGitPatchPrefersBranchOverHEAD(t *testing.T) { + // Create a temporary directory for the test + tmpDir := testutil.TempDir(t, "test-patch-priority-*") + + // Initialize a git repository + cmd := exec.Command("git", "init") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to init git repo: %v\nOutput: %s", err, output) + } + + // Configure git user + cmd = exec.Command("git", "config", "user.email", "test@example.com") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to config git: %v\nOutput: %s", err, output) + } + + cmd = exec.Command("git", "config", "user.name", "Test User") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to config git: %v\nOutput: %s", err, output) + } + + // Create initial commit + testFile := filepath.Join(tmpDir, "file.txt") + if err := os.WriteFile(testFile, []byte("content\n"), 0644); err != nil { + t.Fatalf("Failed to write file: %v", err) + } + + cmd = exec.Command("git", "add", ".") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to add files: %v\nOutput: %s", err, output) + } + + cmd = exec.Command("git", "commit", "-m", "Initial") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to commit: %v\nOutput: %s", err, output) + } + + // Get initial SHA + cmd = exec.Command("git", "rev-parse", "HEAD") + cmd.Dir = tmpDir + output, err := cmd.CombinedOutput() + if err != nil { + t.Fatalf("Failed to get SHA: %v", err) + } + initialSHA := strings.TrimSpace(string(output)) + + // Create a named branch + cmd = exec.Command("git", "checkout", "-b", "feature-branch") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to create branch: %v\nOutput: %s", err, output) + } + + // Make a commit on the branch + if err := os.WriteFile(testFile, []byte("content\nupdated\n"), 0644); err != nil { + t.Fatalf("Failed to update file: %v", err) + } + + cmd = exec.Command("git", "add", ".") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to add files: %v\nOutput: %s", err, output) + } + + cmd = exec.Command("git", "commit", "-m", "Branch commit") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to commit: %v\nOutput: %s", err, output) + } + + // Create safe-outputs file with branch name + safeOutputsFile := filepath.Join(tmpDir, "safe-outputs.jsonl") + safeOutputsContent := "{\"type\":\"create_pull_request\",\"branch\":\"feature-branch\",\"title\":\"Test\",\"body\":\"Test\"}\n" + if err := os.WriteFile(safeOutputsFile, []byte(safeOutputsContent), 0644); err != nil { + t.Fatalf("Failed to write safe-outputs: %v", err) + } + + // Run the script + scriptFile := filepath.Join(tmpDir, "generate_patch.sh") + if err := os.WriteFile(scriptFile, []byte(generateGitPatchScript), 0755); err != nil { + t.Fatalf("Failed to write script: %v", err) + } + + // Ensure /tmp/gh-aw exists and is clean + patchFile := "/tmp/gh-aw/aw.patch" + if err := os.MkdirAll("/tmp/gh-aw", 0755); err != nil { + t.Fatalf("Failed to create /tmp/gh-aw: %v", err) + } + os.Remove(patchFile) + + cmd = exec.Command("bash", scriptFile) + cmd.Dir = tmpDir + cmd.Env = append(os.Environ(), + "GH_AW_SAFE_OUTPUTS="+safeOutputsFile, + "GITHUB_SHA="+initialSHA, + "DEFAULT_BRANCH=main", + "GITHUB_STEP_SUMMARY=/dev/null", + ) + + scriptOutput, err := cmd.CombinedOutput() + t.Logf("Script output:\n%s", scriptOutput) + + if err != nil { + t.Fatalf("Script failed: %v\nOutput: %s", err, scriptOutput) + } + + // Verify Strategy 1 was used (branch-based) + if !strings.Contains(string(scriptOutput), "Strategy 1: Using named branch from JSONL") { + t.Error("Expected Strategy 1 to be used when branch name is provided") + } + + if strings.Contains(string(scriptOutput), "Strategy 2: Checking for commits on current HEAD") { + t.Error("Strategy 2 should not run when Strategy 1 succeeds") + } +} + +// TestGitPatchNoCommits tests that no patch is generated when there are no commits +func TestGitPatchNoCommits(t *testing.T) { + tmpDir := testutil.TempDir(t, "test-patch-no-commits-*") + + // Initialize git repo + cmd := exec.Command("git", "init") + cmd.Dir = tmpDir + if output, err := cmd.CombinedOutput(); err != nil { + t.Fatalf("Failed to init git: %v\nOutput: %s", err, output) + } + + // Configure git + cmd = exec.Command("git", "config", "user.email", "test@example.com") + cmd.Dir = tmpDir + cmd.Run() + + cmd = exec.Command("git", "config", "user.name", "Test User") + cmd.Dir = tmpDir + cmd.Run() + + // Create and commit a file + testFile := filepath.Join(tmpDir, "file.txt") + os.WriteFile(testFile, []byte("content\n"), 0644) + + cmd = exec.Command("git", "add", ".") + cmd.Dir = tmpDir + cmd.Run() + + cmd = exec.Command("git", "commit", "-m", "Initial") + cmd.Dir = tmpDir + cmd.Run() + + // Get SHA + cmd = exec.Command("git", "rev-parse", "HEAD") + cmd.Dir = tmpDir + output, _ := cmd.CombinedOutput() + currentSHA := strings.TrimSpace(string(output)) + + // Create empty safe-outputs + safeOutputsFile := filepath.Join(tmpDir, "safe-outputs.jsonl") + os.WriteFile(safeOutputsFile, []byte(""), 0644) + + // Run script with GITHUB_SHA = current HEAD (no new commits) + scriptFile := filepath.Join(tmpDir, "generate_patch.sh") + os.WriteFile(scriptFile, []byte(generateGitPatchScript), 0755) + + // Ensure /tmp/gh-aw exists and is clean + patchFile := "/tmp/gh-aw/aw.patch" + os.MkdirAll("/tmp/gh-aw", 0755) + os.Remove(patchFile) + + cmd = exec.Command("bash", scriptFile) + cmd.Dir = tmpDir + cmd.Env = append(os.Environ(), + "GH_AW_SAFE_OUTPUTS="+safeOutputsFile, + "GITHUB_SHA="+currentSHA, + "DEFAULT_BRANCH=main", + "GITHUB_STEP_SUMMARY=/dev/null", + ) + + scriptOutput, _ := cmd.CombinedOutput() + t.Logf("Script output:\n%s", scriptOutput) + + // Verify no patch was generated (patchFile was already defined above) + if _, err := os.Stat(patchFile); err == nil { + t.Error("Patch file should not be created when there are no commits") + } + + // Verify the script logged that no commits were found + if !strings.Contains(string(scriptOutput), "No commits have been made since checkout") { + t.Error("Script should log that no commits were made") + } +} diff --git a/pkg/workflow/sh/generate_git_patch.sh b/pkg/workflow/sh/generate_git_patch.sh index 101d14ee18b..ac064297778 100644 --- a/pkg/workflow/sh/generate_git_patch.sh +++ b/pkg/workflow/sh/generate_git_patch.sh @@ -1,6 +1,14 @@ +# Diagnostic logging: Show environment information +echo "=== Diagnostic: Environment Information ===" +echo "GITHUB_SHA: ${GITHUB_SHA}" +echo "DEFAULT_BRANCH: ${DEFAULT_BRANCH}" +echo "Current HEAD: $(git rev-parse HEAD 2>/dev/null || echo 'unknown')" +echo "Current branch: $(git branch --show-current 2>/dev/null || echo 'detached HEAD')" + # Diagnostic logging: Show recent commits before patch generation -echo "=== Diagnostic: Recent commits (last 5) ===" -git log --oneline -5 || echo "Failed to show git log" +echo "" +echo "=== Diagnostic: Recent commits (last 10) ===" +git log --oneline -10 || echo "Failed to show git log" # Check current git status echo "" @@ -12,6 +20,7 @@ BRANCH_NAME="" if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then echo "" echo "Checking for branch name in JSONL output..." + echo "JSONL file path: $GH_AW_SAFE_OUTPUTS" while IFS= read -r line; do if [ -n "$line" ]; then # Extract branch from create-pull-request line using simple grep and sed @@ -37,15 +46,23 @@ if [ -f "$GH_AW_SAFE_OUTPUTS" ]; then fi fi done < "$GH_AW_SAFE_OUTPUTS" +else + echo "" + echo "GH_AW_SAFE_OUTPUTS file not found at: $GH_AW_SAFE_OUTPUTS" fi -# If no branch or branch doesn't exist, no patch +# If no branch found in JSONL, log it but don't give up yet if [ -z "$BRANCH_NAME" ]; then - echo "No branch found, no patch generation" + echo "" + echo "No branch name found in JSONL output" + echo "Will check for commits made to current HEAD instead" fi -# If we have a branch name, check if that branch exists and get its diff +# Strategy 1: If we have a branch name, check if that branch exists and get its diff +PATCH_GENERATED=false if [ -n "$BRANCH_NAME" ]; then + echo "" + echo "=== Strategy 1: Using named branch from JSONL ===" echo "Looking for branch: $BRANCH_NAME" # Check if the branch exists if git show-ref --verify --quiet "refs/heads/$BRANCH_NAME"; then @@ -90,11 +107,79 @@ if [ -n "$BRANCH_NAME" ]; then # Generate patch from the determined base to the branch git format-patch "$BASE_REF".."$BRANCH_NAME" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from branch" > /tmp/gh-aw/aw.patch echo "Patch file created from branch: $BRANCH_NAME (base: $BASE_REF)" + PATCH_GENERATED=true else - echo "Branch $BRANCH_NAME does not exist, no patch" + echo "Branch $BRANCH_NAME does not exist locally" fi fi +# Strategy 2: Check if commits were made to current HEAD since checkout +if [ "$PATCH_GENERATED" = false ]; then + echo "" + echo "=== Strategy 2: Checking for commits on current HEAD ===" + + # Get current HEAD SHA + CURRENT_HEAD="$(git rev-parse HEAD 2>/dev/null || echo '')" + echo "Current HEAD: $CURRENT_HEAD" + echo "Checkout SHA (GITHUB_SHA): $GITHUB_SHA" + + if [ -z "$CURRENT_HEAD" ]; then + echo "ERROR: Could not determine current HEAD SHA" + elif [ -z "$GITHUB_SHA" ]; then + echo "ERROR: GITHUB_SHA environment variable is not set" + elif [ "$CURRENT_HEAD" = "$GITHUB_SHA" ]; then + echo "No commits have been made since checkout (HEAD == GITHUB_SHA)" + echo "No patch will be generated" + else + echo "HEAD has moved since checkout - checking if commits were added" + + # Check if GITHUB_SHA is an ancestor of current HEAD + if git merge-base --is-ancestor "$GITHUB_SHA" HEAD 2>/dev/null; then + echo "GITHUB_SHA is an ancestor of HEAD - commits were added" + + # Count commits between GITHUB_SHA and HEAD + COMMIT_COUNT="$(git rev-list --count "${GITHUB_SHA}..HEAD" 2>/dev/null || echo "0")" + echo "" + echo "=== Diagnostic: Commits added since checkout ===" + echo "Number of commits: $COMMIT_COUNT" + + if [ "$COMMIT_COUNT" -gt 0 ]; then + echo "Commit SHAs:" + git log --oneline "${GITHUB_SHA}..HEAD" || echo "Failed to list commits" + + # Show diff stats + echo "" + echo "=== Diagnostic: Diff stats for patch generation ===" + echo "Command: git diff --stat ${GITHUB_SHA}..HEAD" + git diff --stat "${GITHUB_SHA}..HEAD" || echo "Failed to show diff stats" + + # Generate patch from GITHUB_SHA to HEAD + echo "" + echo "=== Diagnostic: Generating patch ===" + echo "Command: git format-patch ${GITHUB_SHA}..HEAD --stdout > /tmp/gh-aw/aw.patch" + git format-patch "${GITHUB_SHA}..HEAD" --stdout > /tmp/gh-aw/aw.patch || echo "Failed to generate patch from HEAD" > /tmp/gh-aw/aw.patch + echo "Patch file created from commits on HEAD (base: $GITHUB_SHA)" + PATCH_GENERATED=true + else + echo "No commits found between GITHUB_SHA and HEAD" + fi + else + echo "GITHUB_SHA is not an ancestor of HEAD - repository state has diverged" + echo "This may indicate a rebase or other history rewriting operation" + echo "Will not generate patch due to ambiguous history" + fi + fi +fi + +# Final status +echo "" +if [ "$PATCH_GENERATED" = true ]; then + echo "=== Patch generation completed successfully ===" +else + echo "=== No patch generated ===" + echo "Reason: No commits found via branch name or HEAD analysis" +fi + # Show patch info if it exists if [ -f /tmp/gh-aw/aw.patch ]; then echo "" From 8119e04c6a57d2562431a8d236e210598188df72 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 20 Nov 2025 19:16:38 +0000 Subject: [PATCH 3/3] Add changeset for patch generation fix [skip-ci] --- .changeset/patch-fix-patch-generation-local-commits.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/patch-fix-patch-generation-local-commits.md diff --git a/.changeset/patch-fix-patch-generation-local-commits.md b/.changeset/patch-fix-patch-generation-local-commits.md new file mode 100644 index 00000000000..43a5e7a8f37 --- /dev/null +++ b/.changeset/patch-fix-patch-generation-local-commits.md @@ -0,0 +1,7 @@ +--- +"gh-aw": patch +--- + +Fix aw.patch generation logic to handle local commits + +Fixed a bug where patch generation only captured commits from explicitly named branches. When an LLM makes commits directly to the currently checked out branch during action execution, those commits are now properly captured in the patch file. Added HEAD-based patch generation as a fallback strategy and extensive logging throughout the patch generation process.