pull/263/head
Frostebite 2021-05-02 03:10:43 +01:00
parent 47ea0142c5
commit fe9c64c839
3 changed files with 160 additions and 127 deletions

136
dist/index.js vendored
View File

@ -234,6 +234,14 @@ class AWS {
.replace('Standalone', '') .replace('Standalone', '')
.replace('standalone', '')}-${nanoid()}`; .replace('standalone', '')}-${nanoid()}`;
const branchName = (_a = process.env.GITHUB_REF) === null || _a === void 0 ? void 0 : _a.split('/').reverse()[0]; const branchName = (_a = process.env.GITHUB_REF) === null || _a === void 0 ? void 0 : _a.split('/').reverse()[0];
const token = buildParameters.githubToken;
const defaultSecretsArray = [
{
ParameterKey: 'GithubToken',
EnvironmentVariable: 'GITHUB_TOKEN',
ParameterValue: token,
},
];
core.info('Starting part 1/4 (clone from github and restore cache)'); core.info('Starting part 1/4 (clone from github and restore cache)');
yield this.run(buildUid, buildParameters.awsStackName, 'alpine/git', ['/bin/sh'], [ yield this.run(buildUid, buildParameters.awsStackName, 'alpine/git', ['/bin/sh'], [
'-c', '-c',
@ -293,13 +301,52 @@ class AWS {
name: 'GITHUB_SHA', name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA, value: process.env.GITHUB_SHA,
}, },
], [ ], defaultSecretsArray);
{
ParameterKey: 'GithubToken',
ParameterValue: buildParameters.githubToken,
},
]);
core.info('Starting part 2/4 (build unity project)'); core.info('Starting part 2/4 (build unity project)');
const buildSecrets = new Array();
buildSecrets.push(defaultSecretsArray);
if (process.env.UNITY_LICENSE)
buildSecrets.push({
ParameterKey: 'UnityLicense',
EnvironmentVariable: 'UNITY_LICENSE',
ParameterValue: process.env.UNITY_LICENSE,
});
if (process.env.UNITY_EMAIL)
buildSecrets.push({
ParameterKey: 'UnityEmail',
EnvironmentVariable: 'UNITY_EMAIL',
ParameterValue: process.env.UNITY_EMAIL,
});
if (process.env.UNITY_PASSWORD)
buildSecrets.push({
ParameterKey: 'UnityPassword',
EnvironmentVariable: 'UNITY_PASSWORD',
ParameterValue: process.env.UNITY_PASSWORD,
});
if (process.env.UNITY_SERIAL)
buildSecrets.push({
ParameterKey: 'UnitySerial',
EnvironmentVariable: 'UNITY_SERIAL',
ParameterValue: process.env.UNITY_SERIAL,
});
if (buildParameters.androidKeystoreBase64)
buildSecrets.push({
ParameterKey: 'AndroidKeystoreBase64',
EnvironmentVariable: 'ANDROID_KEYSTORE_BASE64',
ParameterValue: buildParameters.androidKeystoreBase64,
});
if (buildParameters.androidKeystorePass)
buildSecrets.push({
ParameterKey: 'AndroidKeystorePass',
EnvironmentVariable: 'ANDROID_KEYSTORE_PASS',
ParameterValue: buildParameters.androidKeystorePass,
});
if (buildParameters.androidKeyaliasPass)
buildSecrets.push({
ParameterKey: 'AndroidKeyAliasPass',
EnvironmentVariable: 'AWS_ACCESS_KEY_ALIAS_PASS',
ParameterValue: buildParameters.androidKeyaliasPass,
});
yield this.run(buildUid, buildParameters.awsStackName, baseImage.toString(), ['/bin/sh'], [ yield this.run(buildUid, buildParameters.awsStackName, baseImage.toString(), ['/bin/sh'], [
'-c', '-c',
` `
@ -363,40 +410,7 @@ class AWS {
name: 'ANDROID_KEYALIAS_NAME', name: 'ANDROID_KEYALIAS_NAME',
value: buildParameters.androidKeyaliasName, value: buildParameters.androidKeyaliasName,
}, },
], [ ], buildSecrets);
{
ParameterKey: 'GithubToken',
ParameterValue: buildParameters.githubToken,
},
{
ParameterKey: 'UnityLicense',
ParameterValue: process.env.UNITY_LICENSE ? process.env.UNITY_LICENSE : '0',
},
{
ParameterKey: 'UnityEmail',
ParameterValue: process.env.UNITY_EMAIL ? process.env.UNITY_EMAIL : '0',
},
{
ParameterKey: 'UnityPassword',
ParameterValue: process.env.UNITY_PASSWORD ? process.env.UNITY_PASSWORD : '0',
},
{
ParameterKey: 'UnitySerial',
ParameterValue: process.env.UNITY_SERIAL ? process.env.UNITY_SERIAL : '0',
},
{
ParameterKey: 'AndroidKeystoreBase64',
ParameterValue: buildParameters.androidKeystoreBase64 ? buildParameters.androidKeystoreBase64 : '0',
},
{
ParameterKey: 'AndroidKeystorePass',
ParameterValue: buildParameters.androidKeystorePass ? buildParameters.androidKeystorePass : '0',
},
{
ParameterKey: 'AndroidKeyAliasPass',
ParameterValue: buildParameters.androidKeyaliasPass ? buildParameters.androidKeyaliasPass : '0',
},
]);
core.info('Starting part 3/4 (zip unity build and Library for caching)'); core.info('Starting part 3/4 (zip unity build and Library for caching)');
// Cleanup // Cleanup
yield this.run(buildUid, buildParameters.awsStackName, 'alpine', ['/bin/sh'], [ yield this.run(buildUid, buildParameters.awsStackName, 'alpine', ['/bin/sh'], [
@ -416,12 +430,7 @@ class AWS {
name: 'GITHUB_SHA', name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA, value: process.env.GITHUB_SHA,
}, },
], [ ], defaultSecretsArray);
{
ParameterKey: 'GithubToken',
ParameterValue: buildParameters.githubToken,
},
]);
core.info('Starting part 4/4 (upload build to s3)'); core.info('Starting part 4/4 (upload build to s3)');
yield this.run(buildUid, buildParameters.awsStackName, 'amazon/aws-cli', ['/bin/sh'], [ yield this.run(buildUid, buildParameters.awsStackName, 'amazon/aws-cli', ['/bin/sh'], [
'-c', '-c',
@ -441,18 +450,17 @@ class AWS {
value: process.env.AWS_DEFAULT_REGION, value: process.env.AWS_DEFAULT_REGION,
}, },
], [ ], [
{
ParameterKey: 'GithubToken',
ParameterValue: buildParameters.githubToken,
},
{ {
ParameterKey: 'AWSAccessKeyID', ParameterKey: 'AWSAccessKeyID',
EnvironmentVariable: 'AWS_ACCESS_KEY_ID',
ParameterValue: process.env.AWS_ACCESS_KEY_ID, ParameterValue: process.env.AWS_ACCESS_KEY_ID,
}, },
{ {
ParameterKey: 'AWSSecretAccessKey', ParameterKey: 'AWSSecretAccessKey',
EnvironmentVariable: 'AWS_SECRET_ACCESS_KEY',
ParameterValue: process.env.AWS_SECRET_ACCESS_KEY, ParameterValue: process.env.AWS_SECRET_ACCESS_KEY,
}, },
...defaultSecretsArray,
]); ]);
} }
catch (error) { catch (error) {
@ -479,22 +487,22 @@ class AWS {
const taskDefStackName = `${stackName}-${buildUid}`; const taskDefStackName = `${stackName}-${buildUid}`;
let taskDefCloudFormation = fs.readFileSync(`${__dirname}/cloud-formations/task-def-formation.yml`, 'utf8'); let taskDefCloudFormation = fs.readFileSync(`${__dirname}/cloud-formations/task-def-formation.yml`, 'utf8');
for (const secret of secrets) { for (const secret of secrets) {
const p1string = 'p1 - input'; const insertionStringParameters = 'p1 - input';
const p2string = 'p2 - secret'; const insertionStringSecrets = 'p2 - secret';
const p3string = 'p3 - container def'; const insertionStringContainerSecrets = 'p3 - container def';
const indexp1 = taskDefCloudFormation.search(p1string) + p1string.length + '\n'.length; const indexp1 = taskDefCloudFormation.search(insertionStringParameters) + insertionStringParameters.length + '\n'.length;
const template1 = ` const parameterTemplate = `
${secret.ParameterKey}: ${secret.ParameterKey}:
Type: String Type: String
Default: '' Default: ''
`; `;
taskDefCloudFormation = [ taskDefCloudFormation = [
taskDefCloudFormation.slice(0, indexp1), taskDefCloudFormation.slice(0, indexp1),
template1, parameterTemplate,
taskDefCloudFormation.slice(indexp1), taskDefCloudFormation.slice(indexp1),
].join(''); ].join('');
const indexp2 = taskDefCloudFormation.search(p2string) + p2string.length + '\n'.length; const indexp2 = taskDefCloudFormation.search(insertionStringSecrets) + insertionStringSecrets.length + '\n'.length;
const template2 = ` const secretTemplate = `
${secret.ParameterKey}Secret: ${secret.ParameterKey}Secret:
Type: AWS::SecretsManager::Secret Type: AWS::SecretsManager::Secret
Properties: Properties:
@ -503,17 +511,19 @@ class AWS {
`; `;
taskDefCloudFormation = [ taskDefCloudFormation = [
taskDefCloudFormation.slice(0, indexp2), taskDefCloudFormation.slice(0, indexp2),
template2, secretTemplate,
taskDefCloudFormation.slice(indexp2), taskDefCloudFormation.slice(indexp2),
].join(''); ].join('');
const indexp3 = taskDefCloudFormation.search(p3string) + p3string.length + '\n'.length; const indexp3 = taskDefCloudFormation.search(insertionStringContainerSecrets) +
const template3 = ` insertionStringContainerSecrets.length +
- Name: '${secret.ParameterKey.toUpperCase()}' '\n'.length;
const containerDefinitionSecretTemplate = `
- Name: '${secret.EnvironmentVariable ? secret.EnvironmentVariable : secret.ParameterKey}'
ValueFrom: !Ref ${secret.ParameterKey}Secret ValueFrom: !Ref ${secret.ParameterKey}Secret
`; `;
taskDefCloudFormation = [ taskDefCloudFormation = [
taskDefCloudFormation.slice(0, indexp3), taskDefCloudFormation.slice(0, indexp3),
template3, containerDefinitionSecretTemplate,
taskDefCloudFormation.slice(indexp3), taskDefCloudFormation.slice(indexp3),
].join(''); ].join('');
} }

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -16,6 +16,14 @@ class AWS {
.replace('Standalone', '') .replace('Standalone', '')
.replace('standalone', '')}-${nanoid()}`; .replace('standalone', '')}-${nanoid()}`;
const branchName = process.env.GITHUB_REF?.split('/').reverse()[0]; const branchName = process.env.GITHUB_REF?.split('/').reverse()[0];
const token: string = buildParameters.githubToken;
const defaultSecretsArray = [
{
ParameterKey: 'GithubToken',
EnvironmentVariable: 'GITHUB_TOKEN',
ParameterValue: token,
},
];
core.info('Starting part 1/4 (clone from github and restore cache)'); core.info('Starting part 1/4 (clone from github and restore cache)');
await this.run( await this.run(
@ -85,15 +93,64 @@ class AWS {
value: process.env.GITHUB_SHA, value: process.env.GITHUB_SHA,
}, },
], ],
[ defaultSecretsArray,
{
ParameterKey: 'GithubToken',
ParameterValue: buildParameters.githubToken,
},
],
); );
core.info('Starting part 2/4 (build unity project)'); core.info('Starting part 2/4 (build unity project)');
const buildSecrets = new Array();
buildSecrets.push(defaultSecretsArray);
if (process.env.UNITY_LICENSE)
buildSecrets.push({
ParameterKey: 'UnityLicense',
EnvironmentVariable: 'UNITY_LICENSE',
ParameterValue: process.env.UNITY_LICENSE,
});
if (process.env.UNITY_EMAIL)
buildSecrets.push({
ParameterKey: 'UnityEmail',
EnvironmentVariable: 'UNITY_EMAIL',
ParameterValue: process.env.UNITY_EMAIL,
});
if (process.env.UNITY_PASSWORD)
buildSecrets.push({
ParameterKey: 'UnityPassword',
EnvironmentVariable: 'UNITY_PASSWORD',
ParameterValue: process.env.UNITY_PASSWORD,
});
if (process.env.UNITY_SERIAL)
buildSecrets.push({
ParameterKey: 'UnitySerial',
EnvironmentVariable: 'UNITY_SERIAL',
ParameterValue: process.env.UNITY_SERIAL,
});
if (buildParameters.androidKeystoreBase64)
buildSecrets.push({
ParameterKey: 'AndroidKeystoreBase64',
EnvironmentVariable: 'ANDROID_KEYSTORE_BASE64',
ParameterValue: buildParameters.androidKeystoreBase64,
});
if (buildParameters.androidKeystorePass)
buildSecrets.push({
ParameterKey: 'AndroidKeystorePass',
EnvironmentVariable: 'ANDROID_KEYSTORE_PASS',
ParameterValue: buildParameters.androidKeystorePass,
});
if (buildParameters.androidKeyaliasPass)
buildSecrets.push({
ParameterKey: 'AndroidKeyAliasPass',
EnvironmentVariable: 'AWS_ACCESS_KEY_ALIAS_PASS',
ParameterValue: buildParameters.androidKeyaliasPass,
});
await this.run( await this.run(
buildUid, buildUid,
buildParameters.awsStackName, buildParameters.awsStackName,
@ -166,40 +223,7 @@ class AWS {
value: buildParameters.androidKeyaliasName, value: buildParameters.androidKeyaliasName,
}, },
], ],
[ buildSecrets,
{
ParameterKey: 'GithubToken',
ParameterValue: buildParameters.githubToken,
},
{
ParameterKey: 'UnityLicense',
ParameterValue: process.env.UNITY_LICENSE ? process.env.UNITY_LICENSE : '0',
},
{
ParameterKey: 'UnityEmail',
ParameterValue: process.env.UNITY_EMAIL ? process.env.UNITY_EMAIL : '0',
},
{
ParameterKey: 'UnityPassword',
ParameterValue: process.env.UNITY_PASSWORD ? process.env.UNITY_PASSWORD : '0',
},
{
ParameterKey: 'UnitySerial',
ParameterValue: process.env.UNITY_SERIAL ? process.env.UNITY_SERIAL : '0',
},
{
ParameterKey: 'AndroidKeystoreBase64',
ParameterValue: buildParameters.androidKeystoreBase64 ? buildParameters.androidKeystoreBase64 : '0',
},
{
ParameterKey: 'AndroidKeystorePass',
ParameterValue: buildParameters.androidKeystorePass ? buildParameters.androidKeystorePass : '0',
},
{
ParameterKey: 'AndroidKeyAliasPass',
ParameterValue: buildParameters.androidKeyaliasPass ? buildParameters.androidKeyaliasPass : '0',
},
],
); );
core.info('Starting part 3/4 (zip unity build and Library for caching)'); core.info('Starting part 3/4 (zip unity build and Library for caching)');
// Cleanup // Cleanup
@ -229,12 +253,7 @@ class AWS {
value: process.env.GITHUB_SHA, value: process.env.GITHUB_SHA,
}, },
], ],
[ defaultSecretsArray,
{
ParameterKey: 'GithubToken',
ParameterValue: buildParameters.githubToken,
},
],
); );
core.info('Starting part 4/4 (upload build to s3)'); core.info('Starting part 4/4 (upload build to s3)');
@ -265,18 +284,17 @@ class AWS {
}, },
], ],
[ [
{
ParameterKey: 'GithubToken',
ParameterValue: buildParameters.githubToken,
},
{ {
ParameterKey: 'AWSAccessKeyID', ParameterKey: 'AWSAccessKeyID',
EnvironmentVariable: 'AWS_ACCESS_KEY_ID',
ParameterValue: process.env.AWS_ACCESS_KEY_ID, ParameterValue: process.env.AWS_ACCESS_KEY_ID,
}, },
{ {
ParameterKey: 'AWSSecretAccessKey', ParameterKey: 'AWSSecretAccessKey',
EnvironmentVariable: 'AWS_SECRET_ACCESS_KEY',
ParameterValue: process.env.AWS_SECRET_ACCESS_KEY, ParameterValue: process.env.AWS_SECRET_ACCESS_KEY,
}, },
...defaultSecretsArray,
], ],
); );
} catch (error) { } catch (error) {
@ -334,22 +352,24 @@ class AWS {
const taskDefStackName = `${stackName}-${buildUid}`; const taskDefStackName = `${stackName}-${buildUid}`;
let taskDefCloudFormation = fs.readFileSync(`${__dirname}/cloud-formations/task-def-formation.yml`, 'utf8'); let taskDefCloudFormation = fs.readFileSync(`${__dirname}/cloud-formations/task-def-formation.yml`, 'utf8');
for (const secret of secrets) { for (const secret of secrets) {
const p1string = 'p1 - input'; const insertionStringParameters = 'p1 - input';
const p2string = 'p2 - secret'; const insertionStringSecrets = 'p2 - secret';
const p3string = 'p3 - container def'; const insertionStringContainerSecrets = 'p3 - container def';
const indexp1 = taskDefCloudFormation.search(p1string) + p1string.length + '\n'.length; const indexp1 =
const template1 = ` taskDefCloudFormation.search(insertionStringParameters) + insertionStringParameters.length + '\n'.length;
const parameterTemplate = `
${secret.ParameterKey}: ${secret.ParameterKey}:
Type: String Type: String
Default: '' Default: ''
`; `;
taskDefCloudFormation = [ taskDefCloudFormation = [
taskDefCloudFormation.slice(0, indexp1), taskDefCloudFormation.slice(0, indexp1),
template1, parameterTemplate,
taskDefCloudFormation.slice(indexp1), taskDefCloudFormation.slice(indexp1),
].join(''); ].join('');
const indexp2 = taskDefCloudFormation.search(p2string) + p2string.length + '\n'.length; const indexp2 =
const template2 = ` taskDefCloudFormation.search(insertionStringSecrets) + insertionStringSecrets.length + '\n'.length;
const secretTemplate = `
${secret.ParameterKey}Secret: ${secret.ParameterKey}Secret:
Type: AWS::SecretsManager::Secret Type: AWS::SecretsManager::Secret
Properties: Properties:
@ -358,17 +378,20 @@ class AWS {
`; `;
taskDefCloudFormation = [ taskDefCloudFormation = [
taskDefCloudFormation.slice(0, indexp2), taskDefCloudFormation.slice(0, indexp2),
template2, secretTemplate,
taskDefCloudFormation.slice(indexp2), taskDefCloudFormation.slice(indexp2),
].join(''); ].join('');
const indexp3 = taskDefCloudFormation.search(p3string) + p3string.length + '\n'.length; const indexp3 =
const template3 = ` taskDefCloudFormation.search(insertionStringContainerSecrets) +
- Name: '${secret.ParameterKey.toUpperCase()}' insertionStringContainerSecrets.length +
'\n'.length;
const containerDefinitionSecretTemplate = `
- Name: '${secret.EnvironmentVariable ? secret.EnvironmentVariable : secret.ParameterKey}'
ValueFrom: !Ref ${secret.ParameterKey}Secret ValueFrom: !Ref ${secret.ParameterKey}Secret
`; `;
taskDefCloudFormation = [ taskDefCloudFormation = [
taskDefCloudFormation.slice(0, indexp3), taskDefCloudFormation.slice(0, indexp3),
template3, containerDefinitionSecretTemplate,
taskDefCloudFormation.slice(indexp3), taskDefCloudFormation.slice(indexp3),
].join(''); ].join('');
} }