async pipeline
parent
de55a733c5
commit
f10887252c
|
|
@ -6342,36 +6342,49 @@ const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
|
|||
const cloud_runner_options_1 = __importDefault(__nccwpck_require__(96552));
|
||||
const core_1 = __nccwpck_require__(76762);
|
||||
class GitHub {
|
||||
static get octokit() {
|
||||
return new core_1.Octokit({
|
||||
auth: process.env.GITHUB_TOKEN,
|
||||
});
|
||||
}
|
||||
static get sha() {
|
||||
return cloud_runner_1.default.buildParameters.gitSha;
|
||||
}
|
||||
static get checkName() {
|
||||
return `Cloud Runner (${cloud_runner_1.default.buildParameters.buildGuid})`;
|
||||
}
|
||||
static get nameReadable() {
|
||||
return GitHub.checkName;
|
||||
}
|
||||
static get checkRunId() {
|
||||
return cloud_runner_1.default.githubCheckId;
|
||||
}
|
||||
static get owner() {
|
||||
return cloud_runner_options_1.default.githubOwner;
|
||||
}
|
||||
static get repo() {
|
||||
return cloud_runner_options_1.default.githubRepoName;
|
||||
}
|
||||
static createGitHubCheck(summary) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!cloud_runner_options_1.default.githubChecks) {
|
||||
return ``;
|
||||
}
|
||||
const sha = cloud_runner_1.default.buildParameters.gitSha;
|
||||
const name = `Cloud Runner (${cloud_runner_1.default.buildParameters.buildGuid})`;
|
||||
const nameReadable = name;
|
||||
const token = process.env.GITHUB_TOKEN;
|
||||
const owner = cloud_runner_options_1.default.githubOwner;
|
||||
const repo = cloud_runner_options_1.default.githubRepoName;
|
||||
GitHub.startedDate = new Date().toISOString();
|
||||
// call github api to create a check
|
||||
const octokit = new core_1.Octokit({
|
||||
auth: token,
|
||||
});
|
||||
cloud_runner_logger_1.default.log(`POST /repos/${owner}/${repo}/check-runs`);
|
||||
const result = yield octokit.request(`POST /repos/${owner}/${repo}/check-runs`, {
|
||||
owner,
|
||||
repo,
|
||||
name,
|
||||
cloud_runner_logger_1.default.log(`POST /repos/${GitHub.owner}/${GitHub.repo}/check-runs`);
|
||||
const data = {
|
||||
owner: GitHub.owner,
|
||||
repo: GitHub.repo,
|
||||
name: GitHub.checkName,
|
||||
// eslint-disable-next-line camelcase
|
||||
head_sha: sha,
|
||||
head_sha: GitHub.sha,
|
||||
status: 'queued',
|
||||
// eslint-disable-next-line camelcase
|
||||
external_id: cloud_runner_1.default.buildParameters.buildGuid,
|
||||
// eslint-disable-next-line camelcase
|
||||
started_at: GitHub.startedDate,
|
||||
output: {
|
||||
title: nameReadable,
|
||||
title: GitHub.nameReadable,
|
||||
summary,
|
||||
text: '',
|
||||
images: [
|
||||
|
|
@ -6382,39 +6395,62 @@ class GitHub {
|
|||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
};
|
||||
if (yield cloud_runner_options_1.default.asyncCloudRunner) {
|
||||
yield GitHub.runUpdateAsyncChecksWorkflow(data, `update`);
|
||||
return;
|
||||
}
|
||||
const result = yield GitHub.octokit.request(`POST /repos/${GitHub.owner}/${GitHub.repo}/check-runs`, data);
|
||||
return result.data.id;
|
||||
});
|
||||
}
|
||||
static runUpdateAsyncChecksWorkflow(data, mode) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const workflowsResult = yield GitHub.octokit.request(`GET /repos/${GitHub.owner}/${GitHub.repo}/actions/workflows`, {
|
||||
owner: GitHub.owner,
|
||||
repo: GitHub.repo,
|
||||
});
|
||||
const workflows = workflowsResult.data.workflows;
|
||||
let selectedId = ``;
|
||||
for (let index = 0; index < workflowsResult.data.total_count; index++) {
|
||||
if (workflows[index].name === `Async Checks API`) {
|
||||
selectedId = workflows[index].id;
|
||||
}
|
||||
}
|
||||
if (selectedId === ``) {
|
||||
throw new Error(`no workflow with name "Async Checks API"`);
|
||||
}
|
||||
yield GitHub.octokit.request(`POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches`, {
|
||||
owner: GitHub.owner,
|
||||
repo: GitHub.repo,
|
||||
// eslint-disable-next-line camelcase
|
||||
workflow_id: selectedId,
|
||||
ref: 'topic-branch',
|
||||
inputs: {
|
||||
checksObject: JSON.stringify({ data, mode }),
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
static updateGitHubCheck(longDescription, summary, result = `neutral`, status = `in_progress`) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!cloud_runner_options_1.default.githubChecks) {
|
||||
return;
|
||||
}
|
||||
GitHub.longDescriptionContent += `\n${longDescription}`;
|
||||
const sha = cloud_runner_1.default.buildParameters.gitSha;
|
||||
const name = `Cloud Runner (${cloud_runner_1.default.buildParameters.buildGuid})`;
|
||||
const nameReadable = name;
|
||||
const token = process.env.GITHUB_TOKEN;
|
||||
const checkRunId = cloud_runner_1.default.githubCheckId;
|
||||
const owner = cloud_runner_options_1.default.githubOwner;
|
||||
const repo = cloud_runner_options_1.default.githubRepoName;
|
||||
const octokit = new core_1.Octokit({
|
||||
auth: token,
|
||||
});
|
||||
const data = {
|
||||
owner,
|
||||
repo,
|
||||
owner: GitHub.owner,
|
||||
repo: GitHub.owner,
|
||||
// eslint-disable-next-line camelcase
|
||||
check_run_id: checkRunId,
|
||||
name,
|
||||
check_run_id: GitHub.checkRunId,
|
||||
name: GitHub.checkName,
|
||||
// eslint-disable-next-line camelcase
|
||||
head_sha: sha,
|
||||
head_sha: GitHub.sha,
|
||||
// eslint-disable-next-line camelcase
|
||||
started_at: GitHub.startedDate,
|
||||
status,
|
||||
output: {
|
||||
title: nameReadable,
|
||||
title: GitHub.nameReadable,
|
||||
summary,
|
||||
text: GitHub.longDescriptionContent,
|
||||
annotations: [],
|
||||
|
|
@ -6428,7 +6464,11 @@ class GitHub {
|
|||
data.completed_at = GitHub.endedDate || GitHub.startedDate;
|
||||
data.conclusion = result;
|
||||
}
|
||||
yield octokit.request(`PATCH /repos/${owner}/${repo}/check-runs/${checkRunId}`, data);
|
||||
if (yield cloud_runner_options_1.default.asyncCloudRunner) {
|
||||
yield GitHub.runUpdateAsyncChecksWorkflow(data, `update`);
|
||||
return;
|
||||
}
|
||||
yield GitHub.octokit.request(`PATCH /repos/${GitHub.owner}/${GitHub.repo}/check-runs/${GitHub.checkRunId}`, data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -7,39 +7,56 @@ class GitHub {
|
|||
private static longDescriptionContent: string = ``;
|
||||
private static startedDate: string;
|
||||
private static endedDate: string;
|
||||
private static get octokit() {
|
||||
return new Octokit({
|
||||
auth: process.env.GITHUB_TOKEN,
|
||||
});
|
||||
}
|
||||
private static get sha() {
|
||||
return CloudRunner.buildParameters.gitSha;
|
||||
}
|
||||
|
||||
private static get checkName() {
|
||||
return `Cloud Runner (${CloudRunner.buildParameters.buildGuid})`;
|
||||
}
|
||||
|
||||
private static get nameReadable() {
|
||||
return GitHub.checkName;
|
||||
}
|
||||
|
||||
private static get checkRunId() {
|
||||
return CloudRunner.githubCheckId;
|
||||
}
|
||||
|
||||
private static get owner() {
|
||||
return CloudRunnerOptions.githubOwner;
|
||||
}
|
||||
|
||||
private static get repo() {
|
||||
return CloudRunnerOptions.githubRepoName;
|
||||
}
|
||||
|
||||
public static async createGitHubCheck(summary) {
|
||||
if (!CloudRunnerOptions.githubChecks) {
|
||||
return ``;
|
||||
}
|
||||
const sha = CloudRunner.buildParameters.gitSha;
|
||||
const name = `Cloud Runner (${CloudRunner.buildParameters.buildGuid})`;
|
||||
const nameReadable = name;
|
||||
const token = process.env.GITHUB_TOKEN;
|
||||
const owner = CloudRunnerOptions.githubOwner;
|
||||
const repo = CloudRunnerOptions.githubRepoName;
|
||||
GitHub.startedDate = new Date().toISOString();
|
||||
|
||||
// call github api to create a check
|
||||
const octokit = new Octokit({
|
||||
auth: token,
|
||||
});
|
||||
CloudRunnerLogger.log(`POST /repos/${GitHub.owner}/${GitHub.repo}/check-runs`);
|
||||
|
||||
CloudRunnerLogger.log(`POST /repos/${owner}/${repo}/check-runs`);
|
||||
|
||||
const result = await octokit.request(`POST /repos/${owner}/${repo}/check-runs`, {
|
||||
owner,
|
||||
repo,
|
||||
name,
|
||||
const data = {
|
||||
owner: GitHub.owner,
|
||||
repo: GitHub.repo,
|
||||
name: GitHub.checkName,
|
||||
// eslint-disable-next-line camelcase
|
||||
head_sha: sha,
|
||||
head_sha: GitHub.sha,
|
||||
status: 'queued',
|
||||
// eslint-disable-next-line camelcase
|
||||
external_id: CloudRunner.buildParameters.buildGuid,
|
||||
// eslint-disable-next-line camelcase
|
||||
started_at: GitHub.startedDate,
|
||||
output: {
|
||||
title: nameReadable,
|
||||
title: GitHub.nameReadable,
|
||||
summary,
|
||||
text: '',
|
||||
images: [
|
||||
|
|
@ -50,41 +67,67 @@ class GitHub {
|
|||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
if (await CloudRunnerOptions.asyncCloudRunner) {
|
||||
await GitHub.runUpdateAsyncChecksWorkflow(data, `update`);
|
||||
|
||||
return;
|
||||
}
|
||||
const result = await GitHub.octokit.request(`POST /repos/${GitHub.owner}/${GitHub.repo}/check-runs`, data);
|
||||
|
||||
return result.data.id;
|
||||
}
|
||||
|
||||
public static async runUpdateAsyncChecksWorkflow(data, mode) {
|
||||
const workflowsResult = await GitHub.octokit.request(
|
||||
`GET /repos/${GitHub.owner}/${GitHub.repo}/actions/workflows`,
|
||||
{
|
||||
owner: GitHub.owner,
|
||||
repo: GitHub.repo,
|
||||
},
|
||||
);
|
||||
const workflows = workflowsResult.data.workflows;
|
||||
let selectedId = ``;
|
||||
for (let index = 0; index < workflowsResult.data.total_count; index++) {
|
||||
if (workflows[index].name === `Async Checks API`) {
|
||||
selectedId = workflows[index].id;
|
||||
}
|
||||
}
|
||||
if (selectedId === ``) {
|
||||
throw new Error(`no workflow with name "Async Checks API"`);
|
||||
}
|
||||
await GitHub.octokit.request(`POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches`, {
|
||||
owner: GitHub.owner,
|
||||
repo: GitHub.repo,
|
||||
// eslint-disable-next-line camelcase
|
||||
workflow_id: selectedId,
|
||||
ref: 'topic-branch',
|
||||
inputs: {
|
||||
checksObject: JSON.stringify({ data, mode }),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
public static async updateGitHubCheck(longDescription, summary, result = `neutral`, status = `in_progress`) {
|
||||
if (!CloudRunnerOptions.githubChecks) {
|
||||
return;
|
||||
}
|
||||
GitHub.longDescriptionContent += `\n${longDescription}`;
|
||||
const sha = CloudRunner.buildParameters.gitSha;
|
||||
const name = `Cloud Runner (${CloudRunner.buildParameters.buildGuid})`;
|
||||
const nameReadable = name;
|
||||
const token = process.env.GITHUB_TOKEN;
|
||||
const checkRunId = CloudRunner.githubCheckId;
|
||||
const owner = CloudRunnerOptions.githubOwner;
|
||||
const repo = CloudRunnerOptions.githubRepoName;
|
||||
|
||||
const octokit = new Octokit({
|
||||
auth: token,
|
||||
});
|
||||
|
||||
const data: any = {
|
||||
owner,
|
||||
repo,
|
||||
owner: GitHub.owner,
|
||||
repo: GitHub.owner,
|
||||
// eslint-disable-next-line camelcase
|
||||
check_run_id: checkRunId,
|
||||
name,
|
||||
check_run_id: GitHub.checkRunId,
|
||||
name: GitHub.checkName,
|
||||
// eslint-disable-next-line camelcase
|
||||
head_sha: sha,
|
||||
head_sha: GitHub.sha,
|
||||
// eslint-disable-next-line camelcase
|
||||
started_at: GitHub.startedDate,
|
||||
status,
|
||||
output: {
|
||||
title: nameReadable,
|
||||
title: GitHub.nameReadable,
|
||||
summary,
|
||||
text: GitHub.longDescriptionContent,
|
||||
annotations: [],
|
||||
|
|
@ -100,7 +143,12 @@ class GitHub {
|
|||
data.conclusion = result;
|
||||
}
|
||||
|
||||
await octokit.request(`PATCH /repos/${owner}/${repo}/check-runs/${checkRunId}`, data);
|
||||
if (await CloudRunnerOptions.asyncCloudRunner) {
|
||||
await GitHub.runUpdateAsyncChecksWorkflow(data, `update`);
|
||||
|
||||
return;
|
||||
}
|
||||
await GitHub.octokit.request(`PATCH /repos/${GitHub.owner}/${GitHub.repo}/check-runs/${GitHub.checkRunId}`, data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue