-
Notifications
You must be signed in to change notification settings - Fork 3
71 lines (60 loc) · 2.03 KB
/
check-sample.yml
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
name: Check Samples
on:
pull_request:
paths:
- 'samples/**'
jobs:
check_samples:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run Checks
id: checks
run: |
./scripts/check-sample-files.sh > checklist.txt
- name: Add checklist to PR description
uses: actions/github-script@v5
with:
script: |
const fs = require('fs');
const pr_number = context.issue.number;
const marker = '## Samples Checklist';
// Read the checklist from the file
let checklist = fs.readFileSync('checklist.txt', 'utf8').trim();
let error = false;
if(!checklist) {
checklist = "✅"
}
else {
error = true;
}
// Get the current PR
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr_number
});
let newBody;
const body = pullRequest.body || "";
const markerIndex = body.indexOf(marker);
if (markerIndex !== -1) {
// Replace the content below the marker
newBody = body.substring(0, markerIndex + marker.length) + "\n" + checklist;
} else {
// Append the checklist if the marker doesn't exist
newBody = body + "\n" + marker + "\n" + checklist;
}
// Update the PR description
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr_number,
body: newBody
});
if(error) {
throw new Error("Incomplete samples checklist. Please fix the issues and try again.");
}