Skip to content

Commit af2644b

Browse files
Implement production testing
1 parent e6dc648 commit af2644b

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Test Autoupdate Action on Real Repo
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
test-autoupdate:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout this repo
11+
uses: actions/checkout@v4
12+
13+
- name: Checkout target repo (autoupdate-action-unstable)
14+
uses: actions/checkout@v4
15+
with:
16+
repository: CSSUoB/autoupdate-action-unstable
17+
token: ${{ secrets.PR_AUTO_UPDATE_TOKEN }}
18+
path: autoupdate-action-unstable
19+
20+
- name: Run test logic
21+
env:
22+
GH_TOKEN: ${{ secrets.PR_AUTO_UPDATE_TOKEN }}
23+
run: |
24+
cd autoupdate-action-unstable
25+
git checkout main
26+
git pull
27+
# Create a branch with no conflict
28+
git checkout -b test-non-conflict
29+
NON_CONFLICT_FILE="non_conflict.txt"
30+
echo "non-conflict change $(date)" >> "$NON_CONFLICT_FILE"
31+
git add "$NON_CONFLICT_FILE"
32+
git commit -m "Non-conflicting change"
33+
git push origin test-non-conflict
34+
# Create a branch with a conflict
35+
git checkout main
36+
git pull
37+
git checkout -b test-conflict
38+
CONFLICT_FILE="conflict.txt"
39+
echo "conflict change $(date)" > "$CONFLICT_FILE"
40+
git add "$CONFLICT_FILE"
41+
git commit -m "Conflicting change"
42+
git push origin test-conflict
43+
# Simulate a conflict: change the same file on main
44+
git checkout main
45+
echo "main branch change $(date)" > "$CONFLICT_FILE"
46+
git add "$CONFLICT_FILE"
47+
git commit -m "Main branch conflicting change"
48+
git push origin main
49+
# Open PRs using gh CLI
50+
gh pr create --base main --head test-non-conflict --title "Test Non-Conflict" --body "Testing non-conflicting PR" --repo "CSSUoB/autoupdate-action-unstable" --label "autoupdate-test"
51+
gh pr create --base main --head test-conflict --title "Test Conflict" --body "Testing conflicting PR" --repo "CSSUoB/autoupdate-action-unstable" --label "autoupdate-test"
52+
# Wait for autoupdate action to run (adjust sleep as needed)
53+
sleep 120
54+
# Get PR numbers
55+
NON_CONFLICT_PR=$(gh pr list --head test-non-conflict --json number --jq '.[0].number' --repo "CSSUoB/autoupdate-action-unstable")
56+
CONFLICT_PR=$(gh pr list --head test-conflict --json number --jq '.[0].number' --repo "CSSUoB/autoupdate-action-unstable")
57+
# Check if non-conflicting PR is mergeable (should be true)
58+
NON_CONFLICT_STATUS=$(gh pr view "$NON_CONFLICT_PR" --json mergeable --jq '.mergeable' --repo "CSSUoB/autoupdate-action-unstable")
59+
if [[ "$NON_CONFLICT_STATUS" != "MERGEABLE" ]]; then
60+
echo "Non-conflicting PR is not mergeable"
61+
exit 1
62+
fi
63+
# Check if conflicting PR is labelled as conflict
64+
CONFLICT_LABELS=$(gh pr view "$CONFLICT_PR" --json labels --jq '.labels[].name' --repo "CSSUoB/autoupdate-action-unstable")
65+
if ! echo "$CONFLICT_LABELS" | grep -q "conflict"; then
66+
echo "Conflicting PR is not labelled as conflict"
67+
exit 1
68+
fi
69+
echo "Test passed: Non-conflicting PR is mergeable and conflicting PR is labelled"

0 commit comments

Comments
 (0)