From e580beeabe7add76d0ed54afaf17f6bdbfaa38d0 Mon Sep 17 00:00:00 2001 From: Frostebite Date: Thu, 30 Mar 2023 22:34:17 +0100 Subject: [PATCH] fixes --- .github/pull_request_template.md | 4 +- .../workflows/cloud-runner-ci-pipeline.yml | 4 ++ dist/index.js | Bin 19458211 -> 19458671 bytes dist/index.js.map | Bin 13756742 -> 13757282 bytes src/model/cloud-runner/cloud-runner.ts | 20 ++++--- .../k8s/kubernetes-job-spec-factory.ts | 2 - src/model/cloud-runner/remote-client/index.ts | 2 +- .../tests/cloud-runner-github-checks.test.ts | 49 ++++++++++++++++++ .../cloud-runner/workflows/async-workflow.ts | 5 ++ src/model/github.ts | 3 +- 10 files changed, 77 insertions(+), 12 deletions(-) create mode 100644 src/model/cloud-runner/tests/cloud-runner-github-checks.test.ts diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index d7aa5408..ca6ca6d0 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -8,7 +8,7 @@ - [x] Read the contribution [guide](https://github.com/game-ci/unity-builder/blob/main/CONTRIBUTING.md) and accept the [code](https://github.com/game-ci/unity-builder/blob/main/CODE_OF_CONDUCT.md) of conduct -- [ ] Docs (If new inputs or outputs have been added or changes to behavior that should be documented. Please make - a PR in the [documentation repo](https://github.com/game-ci/documentation)) +- [ ] Docs (If new inputs or outputs have been added or changes to behavior that should be documented. Please make a PR + in the [documentation repo](https://github.com/game-ci/documentation)) - [ ] Readme (updated or not needed) - [ ] Tests (added, updated or not needed) diff --git a/.github/workflows/cloud-runner-ci-pipeline.yml b/.github/workflows/cloud-runner-ci-pipeline.yml index 4704defa..3cb390df 100644 --- a/.github/workflows/cloud-runner-ci-pipeline.yml +++ b/.github/workflows/cloud-runner-ci-pipeline.yml @@ -37,6 +37,9 @@ jobs: name: Smoke Tests if: github.event.event_type != 'pull_request_target' runs-on: ubuntu-latest + env: + GIT_PRIVATE_TOKEN: ${{ secrets.GIT_PRIVATE_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} strategy: fail-fast: false matrix: @@ -111,6 +114,7 @@ jobs: - 'cloud-runner-environment' #- 'cloud-runner-hooks' - 'cloud-runner-s3-steps' + - 'cloud-runner-github-checks' #- 'cloud-runner-local-persistence' #- 'cloud-runner-locking-core' #- 'cloud-runner-locking-get-locked' diff --git a/dist/index.js b/dist/index.js index 5c682c647f270f5751f9143e24541bc646de7646..8b9d51d5321fd50b13739be7fd0de018fb43e2e6 100644 GIT binary patch delta 1678 zcmZwHc~n$Y9KiAOhBpJlF8l5PfzqjK*o#Q*_^ZnzV-#zD@d(XK;JBG}Mb`F`> zhwHj)wMm~?8Jy&4u5oC!<(fnDxT~C6eZI%pP-AnnI2vm;;aC$JDF)Selh~eS3>&WN z_Zoz6)Tk=cggHk|HEQ)vw^bkOiZf+dIyx+=ay3~j+GL0lW8;cRKd7hcvqhCyVvdgx z`|}Ltec7t8Z8eyNkBSkaKDH%DA8as*-Px)s?!>=P+akL5Dp6v3vs={@^c>x$XX=af zw7hCplUCcLSv^fot*xNZ;cT$vS?u=QK+Ey(e*-p$+uiDFsX0EQuhL6IyG_Z`!~18d zoq?T!x}_&Y_w}hueFI+KfD*F7TQ%2^+bw4J3}xQlU4|i(Xx?W?@vik5vJQk47FQHi z=FhJvD=8?oi#Z#66U31TznBxP`>cvt?6D~RqIjEMuy7Tq{z3oklLuzE3rBlcjBu@s z4ilEmi2=f5RbuqR8LD7ksCRtAZ`r(fIa%n`iaZOf4tHBqb(O1SVO@i()!kj1t-=Ts z{1E^%0uh8@gdh}Q2*)HuAQDlCMhs#Rhj=6)5lKi!3MRvXRHPvtQ;>m7OvN;0AsZ** zWSjykPQ`Sbh8&!ZGcW^Z;w+qvnK%czI2U<159i|oT!?(k!bK>+Y!sph#kd$HxCED? z6lJhs4(6g96{y5zsKVvA0$1WHT#b3S2J>Nu0}D`%8q}f=*PQF^Dx-iy=IOhw%s=#bbCJPvA*Bg{Sch)?q!K#d8?O25iLh z@Ztq*!i(69m+&%1Fp4p}f>-exUdI-^fvtEGZ($s7V*=ao4z}Z6?7(|?A3N~@KEy}( z7`yNZKE-GF9J{dxK74___!9f@6~4wd_!i&cd+f&n9K;Vegv0m|KjCNmf?x3)j^KCv zfj{vV{>DEzihoy>W-C3AG06DIs4_+wlZ?MifQ(rtP$ozwSSCa!R3=O&TxOC?giNGN yluWctj7+RdoJ_n-f=r@Jl1#Epip*pgi%hCanoPRP6qyW}Oqr?5D9?maIdTl1uvP^C delta 1389 zcmXBUXI#ty7{Kw*{kuEvE=nRgDU}kDy+<}#ku6kqR`$*a*~-!1x)a$l!Ur_JyP9H1xs+nq=4?@uziaeKZ%6CY1f!y}Bw7R2jcuJxmQ1VX z|KX+8tfrcbMoXxzmO3EVY_wRDd@Q?d)zsvbidIdHQjF>{U!7B0Z;M?~V}i|k7RIU< z&uFx10jgOamt(W%*fiyK8vLXB4GM~i9M)IO@zI*qh-Y!GsuH63B}JPY?cQNZjd=U! zEM=8m4bM_S?X9wv#;@(M=N;m@#=8e9l3c?MA zP#EqoqX;}u6rS)xF?hoVz9Y+XwpdlKeF`A$$LeLD&(E=^e3ZZC?HV8vov_pGzKu2^!XLLb0zL)i*Xo_35dl+Ou}SL zK^&%H8m1#2GcXggFdK6)7xOS52}r~OSg;U_kOUQru>?!849j7K4J(k0l~{!oti~Fw z#X79V25iJ8q+&C+U@Nv^J9Z!qJFyG9VaFcq#XjuE0USg+GH?ioaRf(^iDNj96F7-e zIE^zni*q=S3%H0&xQr{fifg!z8@P#E$ii*h!ClUg8yA z;|<>89o{1cAMg>M@EKq572oh3KkyU3@Ed>dceZ<=WtKV-h`%I`akgfxF!Gq diff --git a/dist/index.js.map b/dist/index.js.map index bac9601797709bd929a0678bfeb31c265da53439..f2125742f1c7292c143e917962a7939b71bf7ae5 100644 GIT binary patch delta 1339 zcmajbT~JhI9LMoNa4}w7cDG&J!=Bxx)sUzat<2~}TO&Y9H$f?_)&s2VD(vE(vk`u>|}=c^QVH`o|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%j$NogC8|)3-PnV@sDWS~ z_M;XD@ILBr5cO!l2lx<&a2Q8$6d$1xP52m};24^594%!#hy4duGXz-x diff --git a/src/model/cloud-runner/cloud-runner.ts b/src/model/cloud-runner/cloud-runner.ts index fa570a74..c028255a 100644 --- a/src/model/cloud-runner/cloud-runner.ts +++ b/src/model/cloud-runner/cloud-runner.ts @@ -114,11 +114,7 @@ class CloudRunner { CloudRunner.lockedWorkspace = ``; } } - const content = { ...CloudRunner.buildParameters }; - content.gitPrivateToken = ``; - content.unitySerial = ``; - const jsonContent = JSON.stringify(content, undefined, 4); - await GitHub.updateGitHubCheck(jsonContent, CloudRunner.buildParameters.buildGuid); + await CloudRunner.updateStatusWithBuildParameters(); const output = await new WorkflowCompositionRoot().run( new CloudRunnerStepParameters( baseImage, @@ -135,7 +131,9 @@ class CloudRunner { ); CloudRunnerLogger.log(`Cleanup complete`); if (!CloudRunner.buildParameters.isCliMode) core.endGroup(); - await GitHub.updateGitHubCheck(CloudRunner.buildParameters.buildGuid, `success`, `success`, `completed`); + if ((buildParameters.asyncWorkflow && this.isCloudRunnerEnvironment) || !buildParameters.asyncWorkflow) { + await GitHub.updateGitHubCheck(CloudRunner.buildParameters.buildGuid, `success`, `success`, `completed`); + } if (BuildParameters.shouldUseRetainedWorkspaceMode(buildParameters)) { const workspace = CloudRunner.lockedWorkspace || ``; @@ -176,5 +174,15 @@ class CloudRunner { throw error; } } + + private static async updateStatusWithBuildParameters() { + const content = { ...CloudRunner.buildParameters }; + content.gitPrivateToken = ``; + content.unitySerial = ``; + content.unityEmail = ``; + content.unityPassword = ``; + const jsonContent = JSON.stringify(content, undefined, 4); + await GitHub.updateGitHubCheck(jsonContent, CloudRunner.buildParameters.buildGuid); + } } export default CloudRunner; diff --git a/src/model/cloud-runner/providers/k8s/kubernetes-job-spec-factory.ts b/src/model/cloud-runner/providers/k8s/kubernetes-job-spec-factory.ts index 52b928f9..fbeed68d 100644 --- a/src/model/cloud-runner/providers/k8s/kubernetes-job-spec-factory.ts +++ b/src/model/cloud-runner/providers/k8s/kubernetes-job-spec-factory.ts @@ -92,8 +92,6 @@ class KubernetesJobSpecFactory { preStop: { exec: { command: [ - 'bin/bash', - '-c', `cd /data/builder/action/steps; chmod +x /return_license.sh; /return_license.sh;`, diff --git a/src/model/cloud-runner/remote-client/index.ts b/src/model/cloud-runner/remote-client/index.ts index 520b3614..5791c35e 100644 --- a/src/model/cloud-runner/remote-client/index.ts +++ b/src/model/cloud-runner/remote-client/index.ts @@ -20,6 +20,7 @@ export class RemoteClient { if (!(await RemoteClient.handleRetainedWorkspace())) { await RemoteClient.bootstrapRepository(); } + await RemoteClient.replaceLargePackageReferencesWithSharedReferences(); await RemoteClient.runCustomHookFiles(`before-build`); } static async runCustomHookFiles(hookLifecycle: string) { @@ -47,7 +48,6 @@ export class RemoteClient { `mkdir -p ${CloudRunnerFolders.ToLinuxFolder(CloudRunnerFolders.cacheFolderForCacheKeyFull)}`, ); await RemoteClient.cloneRepoWithoutLFSFiles(); - await RemoteClient.replaceLargePackageReferencesWithSharedReferences(); await RemoteClient.sizeOfFolder( 'repo before lfs cache pull', CloudRunnerFolders.ToLinuxFolder(CloudRunnerFolders.repoPathAbsolute), diff --git a/src/model/cloud-runner/tests/cloud-runner-github-checks.test.ts b/src/model/cloud-runner/tests/cloud-runner-github-checks.test.ts new file mode 100644 index 00000000..652533f5 --- /dev/null +++ b/src/model/cloud-runner/tests/cloud-runner-github-checks.test.ts @@ -0,0 +1,49 @@ +import { BuildParameters } from '../..'; +import CloudRunner from '../cloud-runner'; +import UnityVersioning from '../../unity-versioning'; +import { Cli } from '../../cli/cli'; +import CloudRunnerOptions from '../options/cloud-runner-options'; +import setups from './cloud-runner-suite.test'; +import { OptionValues } from 'commander'; +import GitHub from '../../github'; + +async function CreateParameters(overrides: OptionValues | undefined) { + if (overrides) Cli.options = overrides; + + return BuildParameters.create(); +} +describe('Cloud Runner Github Checks', () => { + setups(); + it('Responds', () => {}); + + if (CloudRunnerOptions.cloudRunnerDebug && CloudRunnerOptions.providerStrategy === `local-docker`) { + it('Check Handling Direct', async () => { + // Setup parameters + const buildParameter = await CreateParameters({ + versioning: 'None', + projectPath: 'test-project', + unityVersion: UnityVersioning.read('test-project'), + asyncCloudRunner: `true`, + githubChecks: `true`, + }); + await CloudRunner.setup(buildParameter); + CloudRunner.buildParameters.githubCheckId = await GitHub.createGitHubCheck(`t`); + await GitHub.updateGitHubCheck(`t`, `t2`); + }, 1_000_000_000); + it('Check Handling Via Async Workflow', async () => { + // Setup parameters + const buildParameter = await CreateParameters({ + versioning: 'None', + projectPath: 'test-project', + unityVersion: UnityVersioning.read('test-project'), + asyncCloudRunner: `true`, + githubChecks: `true`, + }); + GitHub.asyncWorkflows = true; + await CloudRunner.setup(buildParameter); + CloudRunner.buildParameters.githubCheckId = await GitHub.createGitHubCheck(`t`); + await GitHub.updateGitHubCheck(`t`, `t2`); + GitHub.asyncWorkflows = false; + }, 1_000_000_000); + } +}); diff --git a/src/model/cloud-runner/workflows/async-workflow.ts b/src/model/cloud-runner/workflows/async-workflow.ts index 1d864b29..432b59cb 100644 --- a/src/model/cloud-runner/workflows/async-workflow.ts +++ b/src/model/cloud-runner/workflows/async-workflow.ts @@ -41,6 +41,11 @@ node /builder/dist/index.js -m async-workflow`, [ ...secrets, ...[ + { + ParameterKey: `GITHUB_TOKEN`, + EnvironmentVariable: `GITHUB_TOKEN`, + ParameterValue: process.env.GITHUB_TOKEN || ``, + }, { ParameterKey: `AWS_ACCESS_KEY_ID`, EnvironmentVariable: `AWS_ACCESS_KEY_ID`, diff --git a/src/model/github.ts b/src/model/github.ts index fe9795c1..82fdc3ad 100644 --- a/src/model/github.ts +++ b/src/model/github.ts @@ -11,6 +11,7 @@ class GitHub { private static startedDate: string; private static endedDate: string; static result: string = ``; + static asyncWorkflows: boolean; private static get octokitDefaultToken() { return new Octokit({ auth: process.env.GITHUB_TOKEN, @@ -127,7 +128,7 @@ class GitHub { data.conclusion = result; } - await (CloudRunner.isCloudRunnerAsyncEnvironment + await (CloudRunner.isCloudRunnerAsyncEnvironment || GitHub.asyncWorkflows ? GitHub.runUpdateAsyncChecksWorkflow(data, `update`) : GitHub.updateGitHubCheckRequest(data)); }