@@ -210,16 +210,14 @@ wait_for_synchronize_workflow() {
210210 echo >&2 " Found candidate run IDs: $candidate_run_ids . Checking runs..."
211211 for run_id in $candidate_run_ids ; do
212212 echo >&2 " Checking candidate run ID: $run_id "
213- run_info=$( log_cmd gh run view " $run_id " --repo " $REPO_FULL_NAME " --json headBranch,jobs || echo " {}" )
213+ run_info=$( log_cmd gh run view " $run_id " --repo " $REPO_FULL_NAME " --json headBranch || echo " {}" )
214214
215215 run_head_branch=$( echo " $run_info " | jq -r ' .headBranch // ""' )
216- # Check if this run has the continue-after-conflict-resolution job
217- has_continue_job=$( echo " $run_info " | jq -r ' .jobs[] | select(.name == "continue-after-conflict-resolution") | .name' || echo " " )
218216
219- echo >&2 " Run head branch: $run_head_branch , has continue job: $has_continue_job "
217+ echo >&2 " Run head branch: $run_head_branch "
220218
221- if [[ " $run_head_branch " == " $branch_name " && -n " $has_continue_job " ]]; then
222- echo >&2 " Found matching workflow run ID: $run_id (synchronize with continue job )"
219+ if [[ " $run_head_branch " == " $branch_name " ]]; then
220+ echo >&2 " Found matching workflow run ID: $run_id (branch matches )"
223221 target_run_id=" $run_id "
224222 break
225223 fi
@@ -372,6 +370,34 @@ wait_for_workflow() {
372370# --- Test Execution ---
373371echo >&2 " --- Starting E2E Test ---"
374372
373+ # 0. Sanity checks - ensure we're testing committed code
374+ echo >&2 " 0. Running sanity checks..."
375+
376+ # Check that the working directory is clean
377+ if ! git -C " $PROJECT_ROOT " diff --quiet HEAD 2> /dev/null; then
378+ echo >&2 " ERROR: Repository has uncommitted changes."
379+ echo >&2 " Please commit your changes before running e2e tests."
380+ echo >&2 " This ensures we test exactly what will be deployed."
381+ git -C " $PROJECT_ROOT " status --short >&2
382+ exit 1
383+ fi
384+
385+ # Get the current commit SHA from the action repo
386+ ACTION_REPO_COMMIT=$( git -C " $PROJECT_ROOT " rev-parse HEAD)
387+ echo >&2 " Testing commit: $ACTION_REPO_COMMIT "
388+
389+ # Check that the current commit exists on origin
390+ if ! git -C " $PROJECT_ROOT " fetch origin --quiet 2> /dev/null; then
391+ echo >&2 " WARNING: Could not fetch from origin, skipping remote check"
392+ elif ! git -C " $PROJECT_ROOT " branch -r --contains " $ACTION_REPO_COMMIT " 2> /dev/null | grep -q . ; then
393+ echo >&2 " ERROR: Current commit $ACTION_REPO_COMMIT does not exist on origin."
394+ echo >&2 " Please push your changes before running e2e tests."
395+ echo >&2 " This ensures the workflow can reference the action at this commit."
396+ exit 1
397+ fi
398+
399+ echo >&2 " ✅ Sanity checks passed"
400+
375401# 1. Setup local repository
376402echo >&2 " 1. Setting up local test repository..."
377403TEST_DIR=$( mktemp -d)
@@ -394,65 +420,17 @@ log_cmd git add file.txt
394420log_cmd git commit -m " Initial commit"
395421INITIAL_COMMIT_SHA=$( git rev-parse HEAD)
396422
397- # Copy action files
398- echo >&2 " Copying action files..."
399- cp " $PROJECT_ROOT /action.yml" .
400- cp " $PROJECT_ROOT /update-pr-stack.sh" .
401- cp " $PROJECT_ROOT /command_utils.sh" .
402-
403- # Create workflow file pointing to the local action
404- echo >&2 " Creating workflow file..."
423+ # Copy workflow file from the repo and modify it to use the current commit SHA
424+ # This tests the actual deployed action, not a local copy
425+ echo >&2 " Copying workflow file from repo..."
405426mkdir -p .github/workflows
406- cat > .github/workflows/" $WORKFLOW_FILE " << EOF
407- name: Update Stacked PRs on Squash Merge (E2E Test)
408- on:
409- pull_request:
410- types: [closed, synchronize]
411- permissions:
412- contents: write
413- pull-requests: write
414- jobs:
415- update-pr-stack:
416- # Only run on actual squash merges initiated by the test script
417- if: |
418- github.event.action == 'closed' &&
419- github.event.pull_request.merged == true &&
420- github.event.pull_request.merge_commit_sha != ''
421- runs-on: ubuntu-latest
422- steps:
423- - name: Checkout repository
424- uses: actions/checkout@v4
425- with:
426- # Fetch all history for all branches and tags
427- fetch-depth: 0
428- # Use a PAT token for checkout to allow pushing updates
429- token: \$ {{ secrets.GITHUB_TOKEN }}
430- - name: Update PR stack
431- # Use the action from the current repository checkout
432- uses: ./
433- with:
434- github-token: \$ {{ secrets.GITHUB_TOKEN }}
435- continue-after-conflict-resolution:
436- # Run when a PR with the conflict label is updated (user pushed conflict resolution)
437- if: |
438- github.event.action == 'synchronize' &&
439- contains(github.event.pull_request.labels.*.name, 'autorestack-needs-conflict-resolution')
440- runs-on: ubuntu-latest
441- steps:
442- - name: Checkout repository
443- uses: actions/checkout@v4
444- with:
445- fetch-depth: 0
446- token: \$ {{ secrets.GITHUB_TOKEN }}
447- - name: Continue PR stack update after conflict resolution
448- uses: ./
449- with:
450- github-token: \$ {{ secrets.GITHUB_TOKEN }}
451- mode: conflict-resolved
452- pr-branch: \$ {{ github.event.pull_request.head.ref }}
453- EOF
454-
455- log_cmd git add action.yml update-pr-stack.sh command_utils.sh .github/workflows/" $WORKFLOW_FILE "
427+ cp " $PROJECT_ROOT /.github/workflows/$WORKFLOW_FILE " .github/workflows/
428+
429+ # Replace @main with the current commit SHA to test exactly what we pushed
430+ sed -i " s|uses: Phlogistique/autorestack-action@main|uses: Phlogistique/autorestack-action@$ACTION_REPO_COMMIT |g" .github/workflows/" $WORKFLOW_FILE "
431+ echo >&2 " Modified workflow to use action at commit $ACTION_REPO_COMMIT "
432+
433+ log_cmd git add .github/workflows/" $WORKFLOW_FILE "
456434log_cmd git commit -m " Add action and workflow files"
457435ACTION_COMMIT_SHA=$( git rev-parse HEAD)
458436
0 commit comments