|
8 | 8 |
|
9 | 9 | permissions: |
10 | 10 | contents: read |
| 11 | + pull-requests: write |
11 | 12 |
|
12 | 13 | jobs: |
13 | 14 | e2e_personal: |
@@ -64,3 +65,102 @@ jobs: |
64 | 65 | with: |
65 | 66 | name: e2e-personal |
66 | 67 | 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 | +
|
0 commit comments