2022-02-01 02:31:20 +00:00
|
|
|
import { BuildParameters, ImageTag } from '..';
|
|
|
|
|
import CloudRunner from './cloud-runner';
|
|
|
|
|
import Input from '../input';
|
|
|
|
|
import { CloudRunnerStatics } from './cloud-runner-statics';
|
|
|
|
|
import { TaskParameterSerializer } from './services/task-parameter-serializer';
|
|
|
|
|
import UnityVersioning from '../unity-versioning';
|
2022-04-04 22:09:26 +00:00
|
|
|
import { CLI } from '../cli/cli';
|
2022-02-01 02:31:20 +00:00
|
|
|
|
2022-03-14 23:50:59 +00:00
|
|
|
function guid() {
|
|
|
|
|
return Math.trunc((1 + Math.random()) * 0x10000)
|
|
|
|
|
.toString(16)
|
|
|
|
|
.slice(1);
|
|
|
|
|
}
|
|
|
|
|
function guidGenerator() {
|
|
|
|
|
return `${guid() + guid()}-${guid()}-${guid()}-${guid()}-${guid()}${guid()}${guid()}`;
|
|
|
|
|
}
|
2022-02-01 02:31:20 +00:00
|
|
|
describe('Cloud Runner', () => {
|
|
|
|
|
it('responds', () => {});
|
|
|
|
|
});
|
|
|
|
|
describe('Cloud Runner', () => {
|
|
|
|
|
const testSecretName = 'testSecretName';
|
|
|
|
|
const testSecretValue = 'testSecretValue';
|
2022-04-05 02:58:57 +00:00
|
|
|
it('Local cloud runner returns commands', async () => {
|
|
|
|
|
// build parameters
|
|
|
|
|
CLI.options = {
|
|
|
|
|
versioning: 'None',
|
|
|
|
|
projectPath: 'test-project',
|
|
|
|
|
unityVersion: UnityVersioning.read('test-project'),
|
|
|
|
|
cloudRunnerCluster: 'local',
|
|
|
|
|
targetPlatform: 'StandaloneLinux64',
|
|
|
|
|
customJob: `
|
|
|
|
|
- name: 'step 1'
|
|
|
|
|
image: 'alpine'
|
|
|
|
|
commands: 'ls'
|
|
|
|
|
secrets:
|
|
|
|
|
- name: '${testSecretName}'
|
|
|
|
|
value: '${testSecretValue}'
|
|
|
|
|
`,
|
|
|
|
|
};
|
|
|
|
|
Input.githubInputEnabled = false;
|
|
|
|
|
// setup parameters
|
|
|
|
|
const buildParameter = await BuildParameters.create();
|
|
|
|
|
const baseImage = new ImageTag(buildParameter);
|
|
|
|
|
// run the job
|
|
|
|
|
await expect(CloudRunner.run(buildParameter, baseImage.toString())).resolves.not.toThrow();
|
|
|
|
|
Input.githubInputEnabled = true;
|
|
|
|
|
CLI.options = undefined;
|
|
|
|
|
}, 1000000);
|
|
|
|
|
it('Test cloud runner returns commands', async () => {
|
|
|
|
|
// build parameters
|
|
|
|
|
CLI.options = {
|
|
|
|
|
versioning: 'None',
|
|
|
|
|
projectPath: 'test-project',
|
|
|
|
|
unityVersion: UnityVersioning.read('test-project'),
|
|
|
|
|
cloudRunnerCluster: 'test',
|
|
|
|
|
targetPlatform: 'StandaloneLinux64',
|
|
|
|
|
};
|
|
|
|
|
Input.githubInputEnabled = false;
|
|
|
|
|
// setup parameters
|
|
|
|
|
const buildParameter = await BuildParameters.create();
|
|
|
|
|
const baseImage = new ImageTag(buildParameter);
|
|
|
|
|
// run the job
|
|
|
|
|
await expect(CloudRunner.run(buildParameter, baseImage.toString())).resolves.not.toThrow();
|
|
|
|
|
Input.githubInputEnabled = true;
|
|
|
|
|
CLI.options = undefined;
|
|
|
|
|
}, 1000000);
|
2022-02-01 02:31:20 +00:00
|
|
|
if (Input.cloudRunnerTests) {
|
|
|
|
|
it('All build parameters sent to cloud runner as env vars', async () => {
|
2022-03-14 22:56:09 +00:00
|
|
|
// build parameters
|
2022-04-04 22:09:26 +00:00
|
|
|
CLI.options = {
|
2022-02-01 02:31:20 +00:00
|
|
|
versioning: 'None',
|
|
|
|
|
projectPath: 'test-project',
|
|
|
|
|
unityVersion: UnityVersioning.read('test-project'),
|
2022-04-05 02:58:57 +00:00
|
|
|
targetPlatform: 'StandaloneLinux64',
|
2022-02-01 02:31:20 +00:00
|
|
|
customJob: `
|
|
|
|
|
- name: 'step 1'
|
|
|
|
|
image: 'alpine'
|
|
|
|
|
commands: 'printenv'
|
|
|
|
|
secrets:
|
|
|
|
|
- name: '${testSecretName}'
|
|
|
|
|
value: '${testSecretValue}'
|
|
|
|
|
`,
|
|
|
|
|
};
|
|
|
|
|
Input.githubInputEnabled = false;
|
2022-03-14 22:56:09 +00:00
|
|
|
// setup parameters
|
2022-02-01 02:31:20 +00:00
|
|
|
const buildParameter = await BuildParameters.create();
|
2022-04-03 00:46:45 +00:00
|
|
|
Input.githubInputEnabled = true;
|
2022-02-01 02:31:20 +00:00
|
|
|
const baseImage = new ImageTag(buildParameter);
|
2022-03-14 22:56:09 +00:00
|
|
|
// run the job
|
2022-02-01 02:31:20 +00:00
|
|
|
const file = await CloudRunner.run(buildParameter, baseImage.toString());
|
2022-03-14 22:56:09 +00:00
|
|
|
// assert results
|
2022-02-01 02:31:20 +00:00
|
|
|
expect(file).toContain(JSON.stringify(buildParameter));
|
|
|
|
|
expect(file).toContain(`${Input.ToEnvVarFormat(testSecretName)}=${testSecretValue}`);
|
|
|
|
|
const environmentVariables = TaskParameterSerializer.readBuildEnvironmentVariables();
|
|
|
|
|
const newLinePurgedFile = file
|
|
|
|
|
.replace(/\s+/g, '')
|
|
|
|
|
.replace(new RegExp(`\\[${CloudRunnerStatics.logPrefix}\\]`, 'g'), '');
|
|
|
|
|
for (const element of environmentVariables) {
|
|
|
|
|
if (element.value !== undefined && typeof element.value !== 'function') {
|
|
|
|
|
if (typeof element.value === `string`) {
|
|
|
|
|
element.value = element.value.replace(/\s+/g, '');
|
|
|
|
|
}
|
|
|
|
|
expect(newLinePurgedFile).toContain(`${element.name}=${element.value}`);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-05 02:58:57 +00:00
|
|
|
CLI.options = undefined;
|
2022-02-01 02:31:20 +00:00
|
|
|
}, 1000000);
|
2022-03-14 22:56:09 +00:00
|
|
|
it('Run one build it should not use cache, run subsequent build which should use cache', async () => {
|
2022-04-04 22:09:26 +00:00
|
|
|
CLI.options = {
|
2022-03-14 22:56:09 +00:00
|
|
|
versioning: 'None',
|
|
|
|
|
projectPath: 'test-project',
|
|
|
|
|
unityVersion: UnityVersioning.read('test-project'),
|
2022-04-05 02:58:57 +00:00
|
|
|
targetPlatform: 'StandaloneLinux64',
|
2022-03-14 23:50:59 +00:00
|
|
|
cacheKey: `test-case-${guidGenerator()}`,
|
2022-03-14 22:56:09 +00:00
|
|
|
};
|
|
|
|
|
Input.githubInputEnabled = false;
|
|
|
|
|
const buildParameter = await BuildParameters.create();
|
2022-04-05 02:58:57 +00:00
|
|
|
Input.githubInputEnabled = true;
|
2022-03-14 22:56:09 +00:00
|
|
|
const baseImage = new ImageTag(buildParameter);
|
|
|
|
|
const results = await CloudRunner.run(buildParameter, baseImage.toString());
|
2022-03-14 23:14:38 +00:00
|
|
|
const libraryString = 'Rebuilding Library because the asset database could not be found!';
|
|
|
|
|
expect(results).toContain(libraryString);
|
2022-03-14 22:56:09 +00:00
|
|
|
const results2 = await CloudRunner.run(buildParameter, baseImage.toString());
|
2022-03-14 23:14:38 +00:00
|
|
|
expect(results2).toEqual(expect.not.stringContaining(libraryString));
|
2022-04-05 02:58:57 +00:00
|
|
|
CLI.options = undefined;
|
2022-03-14 22:56:09 +00:00
|
|
|
}, 1000000);
|
2022-02-01 02:31:20 +00:00
|
|
|
}
|
|
|
|
|
});
|