-
Notifications
You must be signed in to change notification settings - Fork 717
69 lines (59 loc) · 3.14 KB
/
validation-check.yaml
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
name: Validation Check
on:
pull_request_review:
types: [submitted]
jobs:
check-reaction:
name: Check for positive reaction on bot's latest validation comment
if: startsWith(github.event.pull_request.base.ref, 'dev-v') || startsWith(github.event.pull_request.base.ref, 'release-v')
runs-on: ubuntu-latest
steps:
- name: Check for modifications in specified folders
id: check-modifications
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
// Get the list of files modified in the PR
const files = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
// Check if any of the modified files are in the specified folders
const modifiedSpecifiedFolders = files.data.some(file => file.filename.startsWith('assets/') || file.filename.startsWith('charts/') || file.filename.startsWith('packages/'));
return modifiedSpecifiedFolders;
- name: Check for positive reaction on bot's latest validation comment
if: steps.check-modifications.outputs.result == 'true'
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
// Get comments on the PR
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
// Sort comments based on their creation datetime in descending order
const sortedComments = comments.data.sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
// Find the latest validation comment by github-actions[bot]
const latestValidationComment = sortedComments.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.startsWith("## Validation steps"));
if (latestValidationComment) {
const reactions = await github.rest.reactions.listForIssueComment({
comment_id: latestValidationComment.id,
owner: context.repo.owner,
repo: context.repo.repo
});
// Check if there's a thumbs-up reaction on the bot's validation comment
const thumbsUpReaction = reactions.data.some(reaction => reaction.content === '+1');
if (thumbsUpReaction) {
console.log("The validation comment by github-actions[bot] has the required thumbs-up reaction.");
} else {
const createdAt = new Date(latestValidationComment.created_at).toLocaleString('en-US', { timeZoneName: 'short' });
console.error("Failed Check - Comment Created At:", createdAt);
core.setFailed("The latest validation comment by github-actions[bot] does not have the required thumbs-up reaction!");
}
} else {
core.setFailed("No validation comments by github-actions[bot] found.");
}