Skip to content

Commit 8f2cc53

Browse files
committed
Update PR
* Update PR
1 parent 0d063d6 commit 8f2cc53

2 files changed

Lines changed: 151 additions & 26 deletions

File tree

.github/workflows/e2e-personal.yaml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
permissions:
1010
contents: read
11+
pull-requests: write
1112

1213
jobs:
1314
e2e_personal:
@@ -64,3 +65,102 @@ jobs:
6465
with:
6566
name: e2e-personal
6667
path: ci/e2e/out/**
68+
69+
pr_comment:
70+
name: Post PR summary comment
71+
needs: [ e2e_personal ]
72+
runs-on: ubuntu-latest
73+
if: always()
74+
75+
steps:
76+
- uses: actions/checkout@v4
77+
78+
# Download the artifact produced by the e2e_personal job
79+
- name: Download artefact
80+
uses: actions/download-artifact@v4
81+
with:
82+
name: e2e-personal
83+
path: artifacts/e2e-personal
84+
85+
- name: Build markdown summary
86+
id: summary
87+
run: |
88+
set -euo pipefail
89+
f="artifacts/e2e-personal/results.json"
90+
if [ ! -f "$f" ]; then
91+
echo "md=⚠️ E2E ran but results.json was not found." >> "$GITHUB_OUTPUT"
92+
exit 0
93+
fi
94+
95+
target=$(jq -r '.target // "personal"' "$f")
96+
total=$(jq -r '.cases | length' "$f")
97+
passed=$(jq -r '[.cases[] | select(.status=="pass")] | length' "$f")
98+
failed=$(jq -r '[.cases[] | select(.status=="fail")] | length' "$f")
99+
100+
# Build failures list
101+
failures=$(jq -r '.cases[]
102+
| select(.status=="fail")
103+
| "- Test Case \(.id // "????"): \(.name) — \(.reason // "no reason provided")"' "$f" || true)
104+
105+
md="## ${target^} Account Testing\n"
106+
md+="${total} Test Cases Run \n"
107+
md+="**${passed}** Test Cases Passed \n"
108+
md+="**${failed}** Test Cases Failed \n\n"
109+
110+
if [ "$failed" -gt 0 ] && [ -n "$failures" ]; then
111+
md+="### ${target^} Account Test Failures\n"
112+
md+="$failures\n"
113+
fi
114+
115+
echo "md<<EOF" >> "$GITHUB_OUTPUT"
116+
echo -e "$md" >> "$GITHUB_OUTPUT"
117+
echo "EOF" >> "$GITHUB_OUTPUT"
118+
119+
- name: Find PR associated with this commit
120+
id: pr
121+
uses: actions/github-script@v7
122+
with:
123+
script: |
124+
const { owner, repo } = context.repo;
125+
const sha = context.sha;
126+
127+
const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
128+
owner, repo, commit_sha: sha
129+
});
130+
131+
if (!prs.data.length) {
132+
core.setOutput("found", "false");
133+
return;
134+
}
135+
136+
core.setOutput("found", "true");
137+
core.setOutput("number", String(prs.data[0].number));
138+
139+
- name: Post or update PR comment (sticky)
140+
if: steps.pr.outputs.found == 'true'
141+
uses: actions/github-script@v7
142+
with:
143+
script: |
144+
const { owner, repo } = context.repo;
145+
const issue_number = Number("${{ steps.pr.outputs.number }}");
146+
147+
const marker = "<!-- onedrive-e2e-personal-summary -->";
148+
const body = `${marker}\n${{ toJSON(steps.summary.outputs.md) }}`.slice(1, -1);
149+
150+
const comments = await github.rest.issues.listComments({
151+
owner, repo, issue_number, per_page: 100
152+
});
153+
154+
const existing = comments.data.find(c => c.body && c.body.includes(marker));
155+
156+
if (existing) {
157+
await github.rest.issues.updateComment({
158+
owner, repo, comment_id: existing.id, body
159+
});
160+
} else {
161+
await github.rest.issues.createComment({
162+
owner, repo, issue_number, body
163+
});
164+
}
165+
166+

ci/e2e/run.sh

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,56 @@ set -euo pipefail
55
# ONEDRIVE_BIN
66
# E2E_TARGET
77
# RUN_ID
8+
#
9+
# Optional (provided by GitHub Actions):
10+
# RUNNER_TEMP
811

912
OUT_DIR="ci/e2e/out"
10-
SYNC_ROOT="$RUNNER_TEMP/sync-${E2E_TARGET}"
13+
SYNC_ROOT="${RUNNER_TEMP:-/tmp}/sync-${E2E_TARGET}"
1114

1215
mkdir -p "$OUT_DIR"
1316
mkdir -p "$SYNC_ROOT"
1417

1518
RESULTS_FILE="${OUT_DIR}/results.json"
1619
LOG_FILE="${OUT_DIR}/sync.log"
1720

21+
# We'll collect cases as JSON objects in a bash array, then assemble results.json.
22+
declare -a CASES=()
23+
pass_count=0
24+
fail_count=0
25+
26+
# Helper: add a PASS case
27+
add_pass() {
28+
local id="$1"
29+
local name="$2"
30+
CASES+=("$(jq -cn --arg id "$id" --arg name "$name" \
31+
'{id:$id,name:$name,status:"pass"}')")
32+
pass_count=$((pass_count + 1))
33+
}
34+
35+
# Helper: add a FAIL case (with reason)
36+
add_fail() {
37+
local id="$1"
38+
local name="$2"
39+
local reason="$3"
40+
CASES+=("$(jq -cn --arg id "$id" --arg name "$name" --arg reason "$reason" \
41+
'{id:$id,name:$name,status:"fail",reason:$reason}')")
42+
fail_count=$((fail_count + 1))
43+
}
44+
1845
echo "E2E target: ${E2E_TARGET}"
1946
echo "Sync root: ${SYNC_ROOT}"
2047

21-
CASE_NAME="basic-resync"
22-
23-
pass_count=0
24-
fail_count=0
48+
###############################################
49+
# Test Case 0001: basic resync
50+
###############################################
51+
TC_ID="0001"
52+
TC_NAME="basic-resync (sync + verbose + resync + resync-auth)"
2553

54+
echo "Running test case ${TC_ID}: ${TC_NAME}"
2655
echo "Running: onedrive --sync --verbose --resync --resync-auth"
2756

57+
# Stream output to console AND log file (Option A) while preserving exit code.
2858
set +e
2959
"$ONEDRIVE_BIN" \
3060
--sync \
@@ -37,34 +67,29 @@ rc=${PIPESTATUS[0]}
3767
set -e
3868

3969
if [ "$rc" -eq 0 ]; then
40-
pass_count=1
41-
status="pass"
70+
add_pass "$TC_ID" "$TC_NAME"
4271
else
43-
fail_count=1
44-
status="fail"
72+
add_fail "$TC_ID" "$TC_NAME" "onedrive exited with code ${rc}"
4573
fi
4674

47-
# Write minimal results.json
48-
cat > "$RESULTS_FILE" <<EOF
49-
{
50-
"target": "${E2E_TARGET}",
51-
"run_id": ${RUN_ID},
52-
"cases": [
53-
{
54-
"name": "${CASE_NAME}",
55-
"status": "${status}"
56-
}
57-
]
58-
}
59-
EOF
75+
###############################################
76+
# Write results.json
77+
###############################################
78+
# Build JSON array from CASES[]
79+
cases_json="$(printf '%s\n' "${CASES[@]}" | jq -cs '.')"
80+
81+
jq -n \
82+
--arg target "$E2E_TARGET" \
83+
--argjson run_id "$RUN_ID" \
84+
--argjson cases "$cases_json" \
85+
'{target:$target, run_id:$run_id, cases:$cases}' \
86+
> "$RESULTS_FILE"
6087

61-
echo "Exit code: ${rc}"
6288
echo "Results written to ${RESULTS_FILE}"
6389
echo "Passed: ${pass_count}"
6490
echo "Failed: ${fail_count}"
6591

66-
# Fail job if command failed
67-
if [ "$rc" -ne 0 ]; then
68-
echo "E2E failed - see sync.log"
92+
# Fail the job if any cases failed.
93+
if [ "$fail_count" -ne 0 ]; then
6994
exit 1
7095
fi

0 commit comments

Comments
 (0)