Skip to content

Commit 165198c

Browse files
committed
Merge main: resolve conflict in e2e test workflow setup
2 parents fb19aef + 0c074c5 commit 165198c

3 files changed

Lines changed: 74 additions & 98 deletions

File tree

.github/workflows/update-pr-stack.yml

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,11 @@ on:
77
permissions:
88
contents: write
99
pull-requests: write
10-
repository-projects: read # See https://github.com/cli/cli/discussions/5307
1110

1211
jobs:
1312
update-pr-stack:
14-
if: github.event.action == 'closed' && github.event.pull_request.merged == true && github.event.pull_request.merge_commit_sha != ''
1513
runs-on: ubuntu-latest
1614
steps:
17-
- name: Checkout repository
18-
uses: actions/checkout@v3
19-
with:
20-
fetch-depth: 0
21-
22-
- name: Update PR stack
23-
uses: ./
24-
with:
25-
github-token: ${{ secrets.GITHUB_TOKEN }}
26-
27-
continue-after-conflict-resolution:
28-
if: github.event.action == 'synchronize' && contains(github.event.pull_request.labels.*.name, 'autorestack-needs-conflict-resolution')
29-
runs-on: ubuntu-latest
30-
steps:
31-
- name: Checkout repository
32-
uses: actions/checkout@v3
33-
with:
34-
fetch-depth: 0
35-
36-
- name: Continue PR stack update after conflict resolution
37-
uses: ./
15+
- uses: Phlogistique/autorestack-action@main
3816
with:
3917
github-token: ${{ secrets.GITHUB_TOKEN }}
40-
mode: conflict-resolved
41-
pr-branch: ${{ github.event.pull_request.head.ref }}

action.yml

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,52 @@ inputs:
77
description: 'GitHub token for API access'
88
required: true
99
default: ${{ github.token }}
10-
mode:
11-
description: 'Action mode: squash-merge (after PR merge) or conflict-resolved (after manual resolution)'
12-
required: false
13-
default: 'squash-merge'
14-
pr-branch:
15-
description: 'The PR branch that was pushed (required for conflict-resolved mode)'
16-
required: false
17-
default: ''
1810

1911
runs:
2012
using: 'composite'
2113
steps:
14+
- name: Check if action should run
15+
id: check
16+
shell: bash
17+
env:
18+
EVENT_ACTION: ${{ github.event.action }}
19+
PR_LABELS: ${{ join(github.event.pull_request.labels.*.name, ',') }}
20+
PR_MERGED: ${{ github.event.pull_request.merged }}
21+
MERGE_COMMIT_SHA: ${{ github.event.pull_request.merge_commit_sha }}
22+
run: |
23+
if [[ "$EVENT_ACTION" == "closed" && "$PR_MERGED" == "true" && -n "$MERGE_COMMIT_SHA" ]]; then
24+
echo "mode=squash-merge" >> $GITHUB_OUTPUT
25+
elif [[ "$EVENT_ACTION" == "synchronize" && "$PR_LABELS" == *autorestack-needs-conflict-resolution* ]]; then
26+
echo "mode=conflict-resolved" >> $GITHUB_OUTPUT
27+
else
28+
echo "Event does not match any action trigger (action=$EVENT_ACTION, merged=$PR_MERGED, labels=$PR_LABELS)"
29+
echo "mode=skip" >> $GITHUB_OUTPUT
30+
fi
31+
32+
- name: Checkout repository
33+
if: steps.check.outputs.mode != 'skip'
34+
uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 0
37+
token: ${{ inputs.github-token }}
38+
2239
- name: Update PR stack
40+
if: steps.check.outputs.mode != 'skip'
2341
shell: bash
2442
env:
2543
GITHUB_TOKEN: ${{ inputs.github-token }}
2644
GIT_AUTHOR_NAME: github-actions
2745
GIT_AUTHOR_EMAIL: github-actions@github.com
2846
GIT_COMMITTER_NAME: github-actions
2947
GIT_COMMITTER_EMAIL: github-actions@github.com
30-
ACTION_MODE: ${{ inputs.mode }}
48+
ACTION_MODE: ${{ steps.check.outputs.mode }}
3149
SQUASH_COMMIT: ${{ github.event.pull_request.merge_commit_sha }}
3250
MERGED_BRANCH: ${{ github.event.pull_request.head.ref }}
3351
TARGET_BRANCH: ${{ github.event.pull_request.base.ref }}
34-
PR_BRANCH: ${{ inputs.pr-branch }}
35-
run: ${{ github.action_path }}/update-pr-stack.sh
52+
PR_BRANCH: ${{ github.event.pull_request.head.ref }}
53+
run: |
54+
echo "Running in $ACTION_MODE mode"
55+
${{ github.action_path }}/update-pr-stack.sh
3656
3757
branding:
3858
icon: 'git-pull-request'

tests/test_e2e.sh

Lines changed: 42 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -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 ---
426424
echo >&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
429455
echo >&2 "1. Setting up local test repository..."
430456
TEST_DIR=$(mktemp -d)
@@ -594,63 +620,17 @@ echo >&2 "0e. Installing action and workflow..."
594620
log_cmd git checkout main
595621
log_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..."
603626
mkdir -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"
654634
log_cmd git commit -m "Add action and workflow files"
655635
log_cmd git push origin main
656636

0 commit comments

Comments
 (0)