async workflow test

pull/479/head
Frostebite 2022-12-06 01:19:45 +00:00
parent 376625a8bd
commit b59e017b54
3 changed files with 42 additions and 42 deletions

View File

@ -15,6 +15,7 @@ import LocalCloudRunner from './providers/local';
import LocalDockerCloudRunner from './providers/docker'; import LocalDockerCloudRunner from './providers/docker';
import GitHub from '../github'; import GitHub from '../github';
import SharedWorkspaceLocking from './services/shared-workspace-locking'; import SharedWorkspaceLocking from './services/shared-workspace-locking';
import CloudRunnerOptions from './cloud-runner-options';
class CloudRunner { class CloudRunner {
public static Provider: ProviderInterface; public static Provider: ProviderInterface;
@ -23,6 +24,7 @@ class CloudRunner {
private static cloudRunnerEnvironmentVariables: CloudRunnerEnvironmentVariable[]; private static cloudRunnerEnvironmentVariables: CloudRunnerEnvironmentVariable[];
static lockedWorkspace: string | undefined; static lockedWorkspace: string | undefined;
public static readonly retainedWorkspacePrefix: string = `retained-workspace`; public static readonly retainedWorkspacePrefix: string = `retained-workspace`;
static githubCheckId;
public static setup(buildParameters: BuildParameters) { public static setup(buildParameters: BuildParameters) {
CloudRunnerLogger.setup(); CloudRunnerLogger.setup();
CloudRunnerLogger.log(`Setting up cloud runner`); CloudRunnerLogger.log(`Setting up cloud runner`);
@ -68,6 +70,17 @@ class CloudRunner {
static async run(buildParameters: BuildParameters, baseImage: string) { static async run(buildParameters: BuildParameters, baseImage: string) {
CloudRunner.setup(buildParameters); CloudRunner.setup(buildParameters);
try { try {
if (CloudRunnerOptions.githubChecksEnabled) {
CloudRunner.githubCheckId = await GitHub.createGitHubCheck(
CloudRunnerOptions.githubOwner,
CloudRunnerOptions.githubRepoName,
CloudRunner.buildParameters.gitPrivateToken,
`Cloud Runner (${CloudRunner.buildParameters.buildGuid})`,
CloudRunner.buildParameters.gitSha,
`Cloud Runner (${CloudRunner.buildParameters.buildGuid})`,
CloudRunner.buildParameters.buildGuid,
);
}
if (buildParameters.retainWorkspace) { if (buildParameters.retainWorkspace) {
CloudRunner.lockedWorkspace = `${CloudRunner.retainedWorkspacePrefix}-${CloudRunner.buildParameters.buildGuid}`; CloudRunner.lockedWorkspace = `${CloudRunner.retainedWorkspacePrefix}-${CloudRunner.buildParameters.buildGuid}`;
@ -123,8 +136,35 @@ class CloudRunner {
CloudRunner.Provider.garbageCollect(``, true, buildParameters.garbageCollectionMaxAge, true, true); CloudRunner.Provider.garbageCollect(``, true, buildParameters.garbageCollectionMaxAge, true, true);
} }
if (CloudRunnerOptions.githubChecksEnabled) {
await GitHub.updateGitHubCheck(
CloudRunner.githubCheckId,
CloudRunnerOptions.githubOwner,
CloudRunnerOptions.githubRepoName,
CloudRunner.buildParameters.gitPrivateToken,
`Cloud Runner (${CloudRunner.buildParameters.buildGuid})`,
CloudRunner.buildParameters.gitSha,
`Cloud Runner (${CloudRunner.buildParameters.buildGuid})`,
CloudRunner.buildParameters.buildGuid,
`success`,
);
}
return output; return output;
} catch (error) { } catch (error) {
if (CloudRunnerOptions.githubChecksEnabled) {
await GitHub.updateGitHubCheck(
CloudRunner.githubCheckId,
CloudRunnerOptions.githubOwner,
CloudRunnerOptions.githubRepoName,
CloudRunner.buildParameters.gitPrivateToken,
`Cloud Runner (${CloudRunner.buildParameters.buildGuid})`,
CloudRunner.buildParameters.gitSha,
`Cloud Runner (${CloudRunner.buildParameters.buildGuid})`,
CloudRunner.buildParameters.buildGuid,
error,
);
}
if (!CloudRunner.buildParameters.isCliMode) core.endGroup(); if (!CloudRunner.buildParameters.isCliMode) core.endGroup();
await CloudRunnerError.handleException(error, CloudRunner.buildParameters, CloudRunner.defaultSecrets); await CloudRunnerError.handleException(error, CloudRunner.buildParameters, CloudRunner.defaultSecrets);
throw error; throw error;

View File

@ -20,8 +20,8 @@ export class AsyncWorkflow {
`apt-get update > /dev/null `apt-get update > /dev/null
apt-get install -y curl tar tree npm git git-lfs jq git > /dev/null apt-get install -y curl tar tree npm git git-lfs jq git > /dev/null
mkdir /builder mkdir /builder
git clone -q -b ${CloudRunner.buildParameters.cloudRunnerBranch} /builder "builder" git clone -q -b ${CloudRunner.buildParameters.cloudRunnerBranch} ${CloudRunnerFolders.unityBuilderRepoUrl} /builder
node "builder/dist/index.js" -m async-workflow node /builder/dist/index.js -m async-workflow
`, `,
`/${CloudRunnerFolders.buildVolumeFolder}`, `/${CloudRunnerFolders.buildVolumeFolder}`,
`/${CloudRunnerFolders.buildVolumeFolder}/`, `/${CloudRunnerFolders.buildVolumeFolder}/`,

View File

@ -8,11 +8,8 @@ import path from 'path';
import CloudRunner from '../cloud-runner'; import CloudRunner from '../cloud-runner';
import CloudRunnerOptions from '../cloud-runner-options'; import CloudRunnerOptions from '../cloud-runner-options';
import { CloudRunnerCustomSteps } from '../services/cloud-runner-custom-steps'; import { CloudRunnerCustomSteps } from '../services/cloud-runner-custom-steps';
import GitHub from '../../github';
export class BuildAutomationWorkflow implements WorkflowInterface { export class BuildAutomationWorkflow implements WorkflowInterface {
static githubCheckId;
static readonly checkNamePrefix = `Cloud-Runner`;
async run(cloudRunnerStepState: CloudRunnerStepState) { async run(cloudRunnerStepState: CloudRunnerStepState) {
try { try {
return await BuildAutomationWorkflow.standardBuildAutomation(cloudRunnerStepState.image, cloudRunnerStepState); return await BuildAutomationWorkflow.standardBuildAutomation(cloudRunnerStepState.image, cloudRunnerStepState);
@ -24,17 +21,6 @@ export class BuildAutomationWorkflow implements WorkflowInterface {
private static async standardBuildAutomation(baseImage: any, cloudRunnerStepState: CloudRunnerStepState) { private static async standardBuildAutomation(baseImage: any, cloudRunnerStepState: CloudRunnerStepState) {
// TODO accept post and pre build steps as yaml files in the repo // TODO accept post and pre build steps as yaml files in the repo
try { try {
if (CloudRunnerOptions.githubChecksEnabled) {
BuildAutomationWorkflow.githubCheckId = await GitHub.createGitHubCheck(
CloudRunnerOptions.githubOwner,
CloudRunnerOptions.githubRepoName,
CloudRunner.buildParameters.gitPrivateToken,
`${BuildAutomationWorkflow.checkNamePrefix}-${CloudRunner.buildParameters.buildGuid}-${CloudRunner.buildParameters.targetPlatform}`,
CloudRunner.buildParameters.gitSha,
`${BuildAutomationWorkflow.checkNamePrefix}-${CloudRunner.buildParameters.buildGuid}-${CloudRunner.buildParameters.targetPlatform}`,
CloudRunner.buildParameters.buildGuid,
);
}
CloudRunnerLogger.log(`Cloud Runner is running standard build automation`); CloudRunnerLogger.log(`Cloud Runner is running standard build automation`);
let output = ''; let output = '';
@ -63,35 +49,9 @@ export class BuildAutomationWorkflow implements WorkflowInterface {
CloudRunnerLogger.logWithTime('Configurable post build step(s) time'); CloudRunnerLogger.logWithTime('Configurable post build step(s) time');
CloudRunnerLogger.log(`Cloud Runner finished running standard build automation`); CloudRunnerLogger.log(`Cloud Runner finished running standard build automation`);
if (CloudRunnerOptions.githubChecksEnabled) {
await GitHub.updateGitHubCheck(
BuildAutomationWorkflow.githubCheckId,
CloudRunnerOptions.githubOwner,
CloudRunnerOptions.githubRepoName,
CloudRunner.buildParameters.gitPrivateToken,
`${BuildAutomationWorkflow.checkNamePrefix}-${CloudRunner.buildParameters.buildGuid}-${CloudRunner.buildParameters.targetPlatform}`,
CloudRunner.buildParameters.gitSha,
`${BuildAutomationWorkflow.checkNamePrefix}-${CloudRunner.buildParameters.buildGuid}-${CloudRunner.buildParameters.targetPlatform}`,
CloudRunner.buildParameters.buildGuid,
'',
);
}
return output; return output;
} catch (error) { } catch (error) {
if (CloudRunnerOptions.githubChecksEnabled) {
await GitHub.updateGitHubCheck(
BuildAutomationWorkflow.githubCheckId,
CloudRunnerOptions.githubOwner,
CloudRunnerOptions.githubRepoName,
CloudRunner.buildParameters.gitPrivateToken,
`${BuildAutomationWorkflow.checkNamePrefix}-${CloudRunner.buildParameters.buildGuid}-${CloudRunner.buildParameters.targetPlatform}`,
CloudRunner.buildParameters.gitSha,
`${BuildAutomationWorkflow.checkNamePrefix}-${CloudRunner.buildParameters.buildGuid}-${CloudRunner.buildParameters.targetPlatform}`,
CloudRunner.buildParameters.buildGuid,
error,
);
}
throw error; throw error;
} }
} }