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 5c682c64..8b9d51d5 100644 Binary files a/dist/index.js and b/dist/index.js differ diff --git a/dist/index.js.map b/dist/index.js.map index bac96017..f2125742 100644 Binary files a/dist/index.js.map and b/dist/index.js.map differ 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)); }