mirror of
https://github.com/game-ci/unity-builder.git
synced 2026-06-01 06:16:14 -07:00
* Rename "Cloud Runner" to "Orchestrator" across entire codebase Breaking change: All CloudRunner classes, options, environment variables, and action.yml inputs have been renamed to Orchestrator equivalents. - Renamed src/model/cloud-runner/ directory to src/model/orchestrator/ - Renamed all cloud-runner-* files to orchestrator-* - Renamed all CloudRunner* classes to Orchestrator* (15+ classes) - Renamed all cloudRunner* properties to orchestrator* equivalents - Renamed CLOUD_RUNNER_* env vars to ORCHESTRATOR_* - Updated action.yml [CloudRunner] markers to [Orchestrator] - Updated workflow files and package.json test scripts - Updated all runtime strings (cache paths, log messages, branch refs) - Rebuilt dist/index.js No backward compatibility layer is provided. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Remove tracked log/temp files and add to .gitignore Remove $LOG_FILE and temp/job-log.txt debug artifacts that should not be in the repository. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
223 lines
7.4 KiB
TypeScript
223 lines
7.4 KiB
TypeScript
import OrchestratorLogger from './orchestrator/services/core/orchestrator-logger';
|
|
import Orchestrator from './orchestrator/orchestrator';
|
|
import OrchestratorOptions from './orchestrator/options/orchestrator-options';
|
|
import * as core from '@actions/core';
|
|
import { Octokit } from '@octokit/core';
|
|
|
|
class GitHub {
|
|
private static readonly asyncChecksApiWorkflowName = `Async Checks API`;
|
|
public static githubInputEnabled: boolean = true;
|
|
private static longDescriptionContent: string = ``;
|
|
private static startedDate: string;
|
|
private static endedDate: string;
|
|
static result: string = ``;
|
|
static forceAsyncTest: boolean;
|
|
private static get octokitDefaultToken() {
|
|
return new Octokit({
|
|
auth: process.env.GITHUB_TOKEN,
|
|
});
|
|
}
|
|
private static get octokitPAT() {
|
|
return new Octokit({
|
|
auth: Orchestrator.buildParameters.gitPrivateToken,
|
|
});
|
|
}
|
|
private static get sha() {
|
|
return Orchestrator.buildParameters.gitSha;
|
|
}
|
|
|
|
private static get checkName() {
|
|
return `Orchestrator (${Orchestrator.buildParameters.buildGuid})`;
|
|
}
|
|
|
|
private static get nameReadable() {
|
|
return GitHub.checkName;
|
|
}
|
|
|
|
private static get checkRunId() {
|
|
return Orchestrator.buildParameters.githubCheckId;
|
|
}
|
|
|
|
private static get owner() {
|
|
return OrchestratorOptions.githubOwner;
|
|
}
|
|
|
|
private static get repo() {
|
|
return OrchestratorOptions.githubRepoName;
|
|
}
|
|
|
|
public static async createGitHubCheck(summary: string) {
|
|
if (!Orchestrator.buildParameters.githubChecks) {
|
|
return ``;
|
|
}
|
|
GitHub.startedDate = new Date().toISOString();
|
|
|
|
OrchestratorLogger.log(`Creating github check`);
|
|
const data = {
|
|
owner: GitHub.owner,
|
|
repo: GitHub.repo,
|
|
name: GitHub.checkName,
|
|
// eslint-disable-next-line camelcase
|
|
head_sha: GitHub.sha,
|
|
status: 'queued',
|
|
// eslint-disable-next-line camelcase
|
|
external_id: Orchestrator.buildParameters.buildGuid,
|
|
// eslint-disable-next-line camelcase
|
|
started_at: GitHub.startedDate,
|
|
output: {
|
|
title: GitHub.nameReadable,
|
|
summary,
|
|
text: '',
|
|
images: [
|
|
{
|
|
alt: 'Game-CI',
|
|
// eslint-disable-next-line camelcase
|
|
image_url: 'https://game.ci/assets/images/game-ci-brand-logo-wordmark.svg',
|
|
},
|
|
],
|
|
},
|
|
};
|
|
const result = await GitHub.createGitHubCheckRequest(data);
|
|
|
|
OrchestratorLogger.log(`Creating github check ${result.status}`);
|
|
|
|
return result.data.id.toString();
|
|
}
|
|
|
|
public static async updateGitHubCheck(
|
|
longDescription: string,
|
|
summary: string,
|
|
result = `neutral`,
|
|
status = `in_progress`,
|
|
) {
|
|
if (`${Orchestrator.buildParameters.githubChecks}` !== `true`) {
|
|
return;
|
|
}
|
|
OrchestratorLogger.log(
|
|
`githubChecks: ${Orchestrator.buildParameters.githubChecks} checkRunId: ${GitHub.checkRunId} sha: ${GitHub.sha} async: ${Orchestrator.isOrchestratorAsyncEnvironment}`,
|
|
);
|
|
GitHub.longDescriptionContent += `\n${longDescription}`;
|
|
if (GitHub.result !== `success` && GitHub.result !== `failure`) {
|
|
GitHub.result = result;
|
|
} else {
|
|
result = GitHub.result;
|
|
}
|
|
const data: any = {
|
|
owner: GitHub.owner,
|
|
repo: GitHub.repo,
|
|
// eslint-disable-next-line camelcase
|
|
check_run_id: GitHub.checkRunId,
|
|
name: GitHub.checkName,
|
|
// eslint-disable-next-line camelcase
|
|
head_sha: GitHub.sha,
|
|
// eslint-disable-next-line camelcase
|
|
started_at: GitHub.startedDate,
|
|
status,
|
|
output: {
|
|
title: GitHub.nameReadable,
|
|
summary,
|
|
text: GitHub.longDescriptionContent,
|
|
annotations: [],
|
|
},
|
|
};
|
|
|
|
if (status === `completed`) {
|
|
if (GitHub.endedDate !== undefined) {
|
|
GitHub.endedDate = new Date().toISOString();
|
|
}
|
|
// eslint-disable-next-line camelcase
|
|
data.completed_at = GitHub.endedDate || GitHub.startedDate;
|
|
data.conclusion = result;
|
|
}
|
|
|
|
await (Orchestrator.isOrchestratorAsyncEnvironment || GitHub.forceAsyncTest
|
|
? GitHub.runUpdateAsyncChecksWorkflow(data, `update`)
|
|
: GitHub.updateGitHubCheckRequest(data));
|
|
}
|
|
|
|
public static async updateGitHubCheckRequest(data: any) {
|
|
return await GitHub.octokitDefaultToken.request(`PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}`, data);
|
|
}
|
|
|
|
public static async createGitHubCheckRequest(data: any) {
|
|
return await GitHub.octokitDefaultToken.request(`POST /repos/{owner}/{repo}/check-runs`, data);
|
|
}
|
|
|
|
public static async runUpdateAsyncChecksWorkflow(data: any, mode: string) {
|
|
if (mode === `create`) {
|
|
throw new Error(`Not supported: only use update`);
|
|
}
|
|
const workflowsResult = await GitHub.octokitPAT.request(`GET /repos/{owner}/{repo}/actions/workflows`, {
|
|
owner: GitHub.owner,
|
|
repo: GitHub.repo,
|
|
});
|
|
const workflows = workflowsResult.data.workflows;
|
|
OrchestratorLogger.log(`Got ${workflows.length} workflows`);
|
|
let selectedId = ``;
|
|
for (let index = 0; index < workflowsResult.data.total_count; index++) {
|
|
if (workflows[index].name === GitHub.asyncChecksApiWorkflowName) {
|
|
selectedId = workflows[index].id.toString();
|
|
}
|
|
}
|
|
if (selectedId === ``) {
|
|
core.info(JSON.stringify(workflows));
|
|
throw new Error(`no workflow with name "${GitHub.asyncChecksApiWorkflowName}"`);
|
|
}
|
|
await GitHub.octokitPAT.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: OrchestratorOptions.branch,
|
|
inputs: {
|
|
checksObject: JSON.stringify({ data, mode }),
|
|
},
|
|
});
|
|
}
|
|
|
|
static async triggerWorkflowOnComplete(triggerWorkflowOnComplete: string[]) {
|
|
const isLocalAsync = Orchestrator.buildParameters.asyncWorkflow && !Orchestrator.isOrchestratorAsyncEnvironment;
|
|
if (isLocalAsync || triggerWorkflowOnComplete === undefined || triggerWorkflowOnComplete.length === 0) {
|
|
return;
|
|
}
|
|
try {
|
|
const workflowsResult = await GitHub.octokitPAT.request(`GET /repos/{owner}/{repo}/actions/workflows`, {
|
|
owner: GitHub.owner,
|
|
repo: GitHub.repo,
|
|
});
|
|
const workflows = workflowsResult.data.workflows;
|
|
OrchestratorLogger.log(`Got ${workflows.length} workflows`);
|
|
for (const element of triggerWorkflowOnComplete) {
|
|
let selectedId = ``;
|
|
for (let index = 0; index < workflowsResult.data.total_count; index++) {
|
|
if (workflows[index].name === element) {
|
|
selectedId = workflows[index].id.toString();
|
|
}
|
|
}
|
|
if (selectedId === ``) {
|
|
core.info(JSON.stringify(workflows));
|
|
throw new Error(`no workflow with name "${GitHub.asyncChecksApiWorkflowName}"`);
|
|
}
|
|
await GitHub.octokitPAT.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: OrchestratorOptions.branch,
|
|
inputs: {
|
|
buildGuid: Orchestrator.buildParameters.buildGuid,
|
|
},
|
|
});
|
|
}
|
|
} catch {
|
|
core.info(`github workflow complete hook not found`);
|
|
}
|
|
}
|
|
|
|
public static async getCheckStatus() {
|
|
return await GitHub.octokitDefaultToken.request(`GET /repos/{owner}/{repo}/check-runs/{check_run_id}`);
|
|
}
|
|
}
|
|
|
|
export default GitHub;
|