@@ -263,16 +263,14 @@ wait_for_synchronize_workflow() {
263263 echo >&2 " Found candidate run IDs: $candidate_run_ids . Checking runs..."
264264 for run_id in $candidate_run_ids ; do
265265 echo >&2 " Checking candidate run ID: $run_id "
266- run_info=$( log_cmd gh run view " $run_id " --repo " $REPO_FULL_NAME " --json headBranch,jobs || echo " {}" )
266+ run_info=$( log_cmd gh run view " $run_id " --repo " $REPO_FULL_NAME " --json headBranch || echo " {}" )
267267
268268 run_head_branch=$( echo " $run_info " | jq -r ' .headBranch // ""' )
269- # Check if this run has the continue-after-conflict-resolution job
270- has_continue_job=$( echo " $run_info " | jq -r ' .jobs[] | select(.name == "continue-after-conflict-resolution") | .name' || echo " " )
271269
272- echo >&2 " Run head branch: $run_head_branch , has continue job: $has_continue_job "
270+ echo >&2 " Run head branch: $run_head_branch "
273271
274- if [[ " $run_head_branch " == " $branch_name " && -n " $has_continue_job " ]]; then
275- echo >&2 " Found matching workflow run ID: $run_id (synchronize with continue job )"
272+ if [[ " $run_head_branch " == " $branch_name " ]]; then
273+ echo >&2 " Found matching workflow run ID: $run_id (branch matches )"
276274 target_run_id=" $run_id "
277275 break
278276 fi
@@ -425,6 +423,34 @@ wait_for_workflow() {
425423# --- Test Execution ---
426424echo >&2 " --- Starting E2E Test ---"
427425
426+ # 0. Sanity checks - ensure we're testing committed code
427+ echo >&2 " 0. Running sanity checks..."
428+
429+ # Check that the working directory is clean
430+ if ! git -C " $PROJECT_ROOT " diff --quiet HEAD 2> /dev/null; then
431+ echo >&2 " ERROR: Repository has uncommitted changes."
432+ echo >&2 " Please commit your changes before running e2e tests."
433+ echo >&2 " This ensures we test exactly what will be deployed."
434+ git -C " $PROJECT_ROOT " status --short >&2
435+ exit 1
436+ fi
437+
438+ # Get the current commit SHA from the action repo
439+ ACTION_REPO_COMMIT=$( git -C " $PROJECT_ROOT " rev-parse HEAD)
440+ echo >&2 " Testing commit: $ACTION_REPO_COMMIT "
441+
442+ # Check that the current commit exists on origin
443+ if ! git -C " $PROJECT_ROOT " fetch origin --quiet 2> /dev/null; then
444+ echo >&2 " WARNING: Could not fetch from origin, skipping remote check"
445+ elif ! git -C " $PROJECT_ROOT " branch -r --contains " $ACTION_REPO_COMMIT " 2> /dev/null | grep -q . ; then
446+ echo >&2 " ERROR: Current commit $ACTION_REPO_COMMIT does not exist on origin."
447+ echo >&2 " Please push your changes before running e2e tests."
448+ echo >&2 " This ensures the workflow can reference the action at this commit."
449+ exit 1
450+ fi
451+
452+ echo >&2 " ✅ Sanity checks passed"
453+
428454# 1. Setup local repository
429455echo >&2 " 1. Setting up local test repository..."
430456TEST_DIR=$( mktemp -d)
@@ -594,63 +620,17 @@ echo >&2 "0e. Installing action and workflow..."
594620log_cmd git checkout main
595621log_cmd git pull origin main
596622
597- # Copy action files
598- cp " $PROJECT_ROOT /action.yml" .
599- cp " $PROJECT_ROOT /update-pr-stack.sh" .
600- cp " $PROJECT_ROOT /command_utils.sh" .
601-
602- # Create workflow file pointing to the local action
623+ # Copy workflow file from the repo and modify it to use the current commit SHA
624+ # This tests the actual deployed action, not a local copy
625+ echo >&2 " Copying workflow file from repo..."
603626mkdir -p .github/workflows
604- cat > .github/workflows/" $WORKFLOW_FILE " << EOF
605- name: Update Stacked PRs on Squash Merge (E2E Test)
606- on:
607- pull_request:
608- types: [closed, synchronize]
609- permissions:
610- contents: write
611- pull-requests: write
612- jobs:
613- update-pr-stack:
614- # Only run on actual squash merges initiated by the test script
615- if: |
616- github.event.action == 'closed' &&
617- github.event.pull_request.merged == true &&
618- github.event.pull_request.merge_commit_sha != ''
619- runs-on: ubuntu-latest
620- steps:
621- - name: Checkout repository
622- uses: actions/checkout@v4
623- with:
624- # Fetch all history for all branches and tags
625- fetch-depth: 0
626- # Use a PAT token for checkout to allow pushing updates
627- token: \$ {{ secrets.GITHUB_TOKEN }}
628- - name: Update PR stack
629- # Use the action from the current repository checkout
630- uses: ./
631- with:
632- github-token: \$ {{ secrets.GITHUB_TOKEN }}
633- continue-after-conflict-resolution:
634- # Run when a PR with the conflict label is updated (user pushed conflict resolution)
635- if: |
636- github.event.action == 'synchronize' &&
637- contains(github.event.pull_request.labels.*.name, 'autorestack-needs-conflict-resolution')
638- runs-on: ubuntu-latest
639- steps:
640- - name: Checkout repository
641- uses: actions/checkout@v4
642- with:
643- fetch-depth: 0
644- token: \$ {{ secrets.GITHUB_TOKEN }}
645- - name: Continue PR stack update after conflict resolution
646- uses: ./
647- with:
648- github-token: \$ {{ secrets.GITHUB_TOKEN }}
649- mode: conflict-resolved
650- pr-branch: \$ {{ github.event.pull_request.head.ref }}
651- EOF
652-
653- log_cmd git add action.yml update-pr-stack.sh command_utils.sh .github/workflows/" $WORKFLOW_FILE "
627+ cp " $PROJECT_ROOT /.github/workflows/$WORKFLOW_FILE " .github/workflows/
628+
629+ # Replace @main with the current commit SHA to test exactly what we pushed
630+ sed -i " s|uses: Phlogistique/autorestack-action@main|uses: Phlogistique/autorestack-action@$ACTION_REPO_COMMIT |g" .github/workflows/" $WORKFLOW_FILE "
631+ echo >&2 " Modified workflow to use action at commit $ACTION_REPO_COMMIT "
632+
633+ log_cmd git add .github/workflows/" $WORKFLOW_FILE "
654634log_cmd git commit -m " Add action and workflow files"
655635log_cmd git push origin main
656636
0 commit comments