-
Notifications
You must be signed in to change notification settings - Fork 55
57 lines (48 loc) · 2.05 KB
/
Copy pathmark-metrics-stale.yml
File metadata and controls
57 lines (48 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
name: Mark Metrics Comment Stale
# Runs on pull_request_target so it gets write permissions even for PRs
# from forks (the original placement under `pull_request` in
# build-package.yml silently lost write perms for fork PRs and 403'd).
#
# This workflow does NOT check out the PR's code — it only calls the
# GitHub API — so pull_request_target is safe here.
on:
pull_request_target:
types: [opened, synchronize, reopened]
branches: [ "main" ]
permissions:
pull-requests: write
jobs:
mark-stale:
runs-on: ubuntu-latest
steps:
- name: Mark metrics comment as stale
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const allComments = await github.paginate(github.rest.issues.listComments, {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
per_page: 100,
});
const existing = allComments.find(c => c.body &&
(c.body.includes('<!-- build-metrics-report -->') || c.body.includes('<!-- binary-size-report -->')));
if (!existing) {
core.info('No existing metrics comment found, nothing to mark stale.');
return;
}
// Skip if already marked stale
if (existing.body.includes('<!-- build-metrics-stale -->')) {
core.info('Comment is already marked stale.');
return;
}
const staleBanner = '> :hourglass_flowing_sand: **Build in progress** — metrics below are from a previous commit and will update when the current build finishes.\n>\n<!-- build-metrics-stale -->\n\n';
const updatedBody = staleBanner + existing.body;
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: updatedBody,
});
core.info(`Marked comment ${existing.id} as stale.`);