chore: revise github actions (#13612)

* chore: rename actions

* chore: fix path maintainer build

* feat: prepare script for node20

* chore: fix semgrep cant access secret
This commit is contained in:
Tony
2023-10-23 03:44:46 +08:00
committed by GitHub
parent 74fb6c6db9
commit 475372751f
34 changed files with 150 additions and 123 deletions
@@ -44,6 +44,9 @@ async function parseBodyRoutes(body, core) {
}
async function getMaintainersByRoutes(routes, core) {
// TODO: change me when https://github.com/actions/github-script is run on node20
// const response = await fetch(maintainerURL);
// const maintainers = await response.json();
const maintainers = await got(maintainerURL).json();
return routes.map((e) => {
+22 -12
View File
@@ -8,12 +8,12 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
core.debug(`match: ${m}`);
let res = null;
const issue_facts = {
const issueFacts = {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
};
const pr_facts = {
const prFacts = {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: number,
@@ -22,7 +22,7 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
const addLabels = (labels) =>
github.rest.issues
.addLabels({
...issue_facts,
...issueFacts,
labels,
})
.catch((e) => {
@@ -32,7 +32,7 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
const removeLabel = () =>
github.rest.issues
.removeLabel({
...issue_facts,
...issueFacts,
name: noFound,
})
.catch((e) => {
@@ -42,7 +42,7 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
const updatePrState = (state) =>
github.rest.pulls
.update({
...pr_facts,
...prFacts,
state,
})
.catch((e) => {
@@ -52,20 +52,28 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
const createComment = (body) =>
github.rest.issues
.createComment({
...issue_facts,
...issueFacts,
body,
})
.catch((e) => {
core.warning(e);
});
const createFailedComment = () =>
createComment(`自动检测失败,请确认 PR 正文部分符合格式规范并重新开启,详情请检查日志
Auto Route test failed, please check your PR body format and reopen pull request. Check logs for more details`);
const createFailedComment = () => {
const logUrl = `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
if (process.env.PULL_REQUEST) {
return createComment(`Auto Route Test failed, please check your PR body format and reopen pull request. Check [logs](${logUrl}) for more details.
自动路由测试失败,请确认 PR 正文部分符合格式规范并重新开启,详情请检查 [日志](${logUrl})。`);
}
return createComment(`Route Test failed, please check your comment body. Check [logs](${logUrl}) for more details.
路由测试失败,请确认评论部分符合格式规范,详情请检查 [日志](${logUrl})。`);
};
const pr = await github.rest.issues
.get({
...issue_facts,
...issueFacts,
})
.catch((e) => {
core.warning(e);
@@ -102,9 +110,11 @@ module.exports = async ({ github, context, core }, body, number, sender) => {
core.warning('Seems like no valid routes can be found. Failing.');
await addLabels([noFound]);
await createFailedComment();
await updatePrState('closed');
if (process.env.PULL_REQUEST) {
await addLabels([noFound]);
await updatePrState('closed');
}
throw Error('Please follow the PR rules: failed to detect route');
};
+12 -1
View File
@@ -17,14 +17,25 @@ module.exports = async ({ github, context, core, got }, baseUrl, routes, number)
core.info(`testing route: ${lks}`);
// Intended, one at a time
let success = false;
let detail = 'no detail';
let detail;
try {
// TODO: change me when https://github.com/actions/github-script is run on node20
// const res = await fetch(lks);
// if (!res.ok) {
// throw res;
// }
// success = true;
// detail = (await res.text()).replace(/\s+(\n|$)/g, '\n');
const res = await got(lks);
if (res && res.body) {
success = true;
detail = res.body.replace(/\s+(\n|$)/g, '\n');
}
} catch (err) {
// TODO: change me when https://github.com/actions/github-script is run on node20
// detail = `HTTPError: Response code ${err.status} (${err.statusText})`;
// const res = await err.text();
// const errInfoList = err.body && res.match(/(?<=<pre class="message">)(.+?)(?=<\/pre>)/gs);
detail = err.toString();
const errInfoList = err.response && err.response.body && err.response.body.match(/(?<=<pre class="message">)(.+?)(?=<\/pre>)/gs);
if (errInfoList) {