Skip to content

Commit e8d0a95

Browse files
committed
update
1 parent 631217f commit e8d0a95

File tree

1 file changed

+51
-48
lines changed

1 file changed

+51
-48
lines changed

.github/workflows/build-preview.yml

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ on:
1313
permissions:
1414
contents: write
1515
pull-requests: write
16-
issues: write
1716

1817
concurrency:
1918
group: preview-build-pr-${{ github.event.pull_request.number || inputs.pr_number }}
@@ -25,23 +24,23 @@ jobs:
2524
runs-on: ubuntu-latest
2625
outputs:
2726
sha: ${{ steps.pr.outputs.sha }}
28-
short_sha: ${{ steps.pr.outputs.short_sha }}
2927
release_tag: ${{ steps.pr.outputs.release_tag }}
3028
pr_number: ${{ steps.pr.outputs.pr_number }}
3129

3230
steps:
33-
- name: Check org membership
31+
- name: Check permissions
3432
if: github.event_name == 'pull_request'
3533
uses: actions/github-script@v7
3634
with:
3735
script: |
38-
try {
39-
await github.rest.orgs.checkMembershipForUser({
40-
org: 'oven-sh',
41-
username: context.actor
42-
});
43-
} catch (e) {
44-
core.setFailed(`${context.actor} is not a member of oven-sh. Preview builds must be triggered manually via workflow_dispatch.`);
36+
const { data: permission } = await github.rest.repos.getCollaboratorPermissionLevel({
37+
owner: context.repo.owner,
38+
repo: context.repo.repo,
39+
username: context.actor
40+
});
41+
42+
if (!['admin', 'write'].includes(permission.permission)) {
43+
core.setFailed(`${context.actor} does not have write access. Preview builds must be triggered manually via workflow_dispatch.`);
4544
}
4645
4746
- name: Get PR information
@@ -68,7 +67,6 @@ jobs:
6867
const releaseTag = `autobuild-preview-pr-${prNumber}-${shortSha}`;
6968
7069
core.setOutput('sha', sha);
71-
core.setOutput('short_sha', shortSha);
7270
core.setOutput('release_tag', releaseTag);
7371
core.setOutput('pr_number', prNumber);
7472
@@ -85,56 +83,61 @@ jobs:
8583
llvm_version: '19'
8684

8785
notify:
88-
name: Notify Completion
86+
name: Update PR Comment
8987
needs: [trigger, build]
9088
runs-on: ubuntu-latest
91-
if: always()
89+
if: needs.build.result == 'success'
9290
permissions:
93-
issues: write
9491
pull-requests: write
9592
steps:
96-
- name: Post success comment
97-
if: needs.build.result == 'success'
93+
- name: Update preview build comment
9894
uses: actions/github-script@v7
9995
with:
10096
script: |
97+
const marker = '<!-- preview-build-comment -->';
98+
const prNumber = ${{ needs.trigger.outputs.pr_number }};
10199
const releaseTag = '${{ needs.trigger.outputs.release_tag }}';
102-
const body = "✅ Preview build completed\n\n" +
103-
"**Release**: [" + releaseTag + "](https://github.com/" + context.repo.owner + "/" + context.repo.repo + "/releases/tag/" + releaseTag + ")";
100+
const sha = '${{ needs.trigger.outputs.sha }}';
101+
const shortSha = sha.substring(0, 8);
102+
const releaseUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/releases/tag/${releaseTag}`;
103+
const newEntry = `| \`${shortSha}\` | [\`${releaseTag}\`](${releaseUrl}) | ${new Date().toISOString().replace('T', ' ').substring(0, 19)} UTC |`;
104104
105-
await github.rest.issues.createComment({
105+
// Find existing comment
106+
const { data: comments } = await github.rest.issues.listComments({
106107
owner: context.repo.owner,
107108
repo: context.repo.repo,
108-
issue_number: ${{ needs.trigger.outputs.pr_number }},
109-
body: body
109+
issue_number: prNumber,
110+
per_page: 100
110111
});
112+
const existing = comments.find(c => c.body.includes(marker));
113+
114+
// Build table
115+
let previousRows = '';
116+
if (existing) {
117+
const lines = existing.body.split('\n');
118+
const tableLines = lines.filter(l => l.startsWith('| `'));
119+
previousRows = tableLines.length > 0 ? '\n' + tableLines.join('\n') : '';
120+
}
111121
112-
- name: Post failure comment
113-
if: needs.build.result == 'failure'
114-
uses: actions/github-script@v7
115-
with:
116-
script: |
117-
const body = "❌ Preview build failed\n\n" +
118-
"Check the [workflow run](" + context.serverUrl + "/" + context.repo.owner + "/" + context.repo.repo + "/actions/runs/" + context.runId + ") for details.";
119-
120-
await github.rest.issues.createComment({
121-
owner: context.repo.owner,
122-
repo: context.repo.repo,
123-
issue_number: ${{ needs.trigger.outputs.pr_number }},
124-
body: body
125-
});
122+
const body = `${marker}
123+
## Preview Builds
126124

127-
- name: Post cancellation comment
128-
if: needs.build.result == 'cancelled'
129-
uses: actions/github-script@v7
130-
with:
131-
script: |
132-
const body = "⚠️ Preview build was cancelled\n\n" +
133-
"This may have been caused by a newer commit being pushed to the same PR.";
125+
| Commit | Release | Date |
126+
|--------|---------|------|
127+
${newEntry}${previousRows}`;
134128

135-
await github.rest.issues.createComment({
136-
owner: context.repo.owner,
137-
repo: context.repo.repo,
138-
issue_number: ${{ needs.trigger.outputs.pr_number }},
139-
body: body
140-
});
129+
if (existing) {
130+
await github.rest.issues.updateComment({
131+
owner: context.repo.owner,
132+
repo: context.repo.repo,
133+
comment_id: existing.id,
134+
body: body
135+
});
136+
} else {
137+
await github.rest.issues.createComment({
138+
owner: context.repo.owner,
139+
repo: context.repo.repo,
140+
issue_number: prNumber,
141+
body: body
142+
});
143+
}

0 commit comments

Comments
 (0)