-
Notifications
You must be signed in to change notification settings - Fork 42
177 lines (156 loc) · 5.88 KB
/
schedule.sgid-index-validation.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
name: Schedule (SGID Index Validation)
on:
schedule:
- cron: '0 0 * * 1-5'
workflow_dispatch:
issue_comment:
types: [created, edited]
permissions:
issues: write
jobs:
validate:
name: Validate SGID Index
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./scripts
env:
GOOGLE_PRIVATE_KEY: ${{ secrets.SA }}
RESULTS_COMMENT_TITLE: SGID Index Validation
steps:
- name: ✅ Check comment
if: github.event_name == 'issue_comment'
uses: actions/github-script@v7
with:
script: |
const commentBody = context.payload.comment.body;
if (commentBody.startsWith('/validate-sgid-index')) {
github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: '+1'
});
console.log('Validating SGID Index');
github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.issue.number
}).then(({data}) => {
const comment = data.find(comment => comment.user.login === 'github-actions[bot]' && comment.body.includes(process.env.RESULTS_COMMENT_TITLE));
if (comment) {
github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
body: `### ${process.env.RESULTS_COMMENT_TITLE}\n\n♻️Processing...♻️`
});
}
});
} else {
console.log('Skipping SGID Index validation');
process.exit(78);
}
- name: ⬇️ Check out code
uses: actions/checkout@v4
with:
show-progress: false
sparse-checkout: |
scripts
src/data
- name: ⎔ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: npm
- name: 📦 Install script dependencies
run: npm install
- name: ✔ Running script
uses: gh640/command-result-action@v1
id: validate
with:
command: node validate-sgid-index.mjs
cwd: ./scripts
- name: 📝 Create or find existing issue
id: create-or-find-issue
uses: actions/github-script@v7
with:
retries: 3
result-encoding: string
script: |
const label = 'sgid index validation';
const title = 'SGID Index Validation Issues';
console.log('searching for existing issue');
const query = `
{
repository(owner: "${context.repo.owner}", name: "${context.repo.repo}") {
issues(
first: 100
labels: ["${label}"]
states: OPEN
filterBy: {createdBy: "github-actions[bot]"}
) {
nodes {
number
}
}
}
}`;
const result = await github.graphql(query);
if (result.repository.issues.nodes.length > 0) {
const issueNumber = result.repository.issues.nodes[0].number;
console.log(`Issue already exists: ${issueNumber}`);
return issueNumber;
} else if (${{ steps.validate.outputs.exitCode }} !== 0) {
// create new issue if there are validation errors
console.log('Creating new issue');
const body = require('fs').readFileSync(process.env.GITHUB_WORKSPACE + '/.github/SGID_INDEX_ISSUE_TEMPLATE.md', 'utf8');
const issue = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
body,
labels: [label]
});
return issue.data.number;
} else {
return '';
}
- name: Find Comment
uses: peter-evans/find-comment@v3
if: steps.create-or-find-issue.outputs.result
id: find-comment
with:
issue-number: ${{ steps.create-or-find-issue.outputs.result }}
comment-author: github-actions[bot]
body-includes: ${{ env.RESULTS_COMMENT_TITLE}}
- name: 🕰 Get Timestamp
id: timestamp
if: steps.create-or-find-issue.outputs.result
run: echo "result=$(TZ=America/Denver date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT
- name: ✍️ Updating issue comment with results
if: steps.create-or-find-issue.outputs.result
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ steps.create-or-find-issue.outputs.result }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: |
### ${{ env.RESULTS_COMMENT_TITLE }}
*${{ steps.timestamp.outputs.result }}*
#### Script Output
```
${{ steps.validate.outputs.stdout }}
```
#### Validation Errors
${{ steps.validate.outputs.stderr }}
- name: 🚦 Check for errors
if: steps.validate.outputs.exitCode != 0
run: |
echo "::error::Validate stderr${{ steps.validate.outputs.stderr }}"
exit ${{ steps.validate.outputs.exitCode }}
- name: 🎉 Close issue
if: steps.validate.outputs.exitCode == 0
run: gh issue close --comment "All validations have passed successfully" "${{ steps.create-or-find-issue.outputs.result }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}