-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
44 lines (38 loc) · 1.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const fs = require('fs');
const core = require('@actions/core');
const yaml = require('js-yaml');
const deepmerge = require('deepmerge');
/**
* Add support for updating environment variables with actions secrets
*
*/
try {
console.log(core.getInput('gae_config_path'));
const gaeConfigPath = core.getInput('gae_config_path') || './app.yaml';
console.log(gaeConfigPath);
const fileContents = fs.readFileSync(gaeConfigPath, 'utf8');
let data = yaml.safeLoad(fileContents);
// @todo Only run this if the user wants to
const secrets = core.getInput('gae_variables');
if (secrets) {
const secrets_buffer = Buffer.from(secrets, 'base64');
data = deepmerge(data, JSON.parse(secrets_buffer.toString()));
let yamlStr = yaml.safeDump(data);
fs.writeFileSync(gaeConfigPath, yamlStr, 'utf8');
}
} catch (error) {
core.setFailed(error.message);
}
try {
const service_account_key = core.getInput('service_account_key');
const buf = Buffer.from(service_account_key, 'base64');
fs.writeFile('./client-secret.json', buf.toString(), function (err) {
if (err) {
console.error(err);
} else {
console.log('write success.');
}
});
} catch (error) {
core.setFailed(error.message);
}