-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
49 lines (38 loc) · 1.42 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
45
46
47
48
49
const core = require('@actions/core');
const execSync = require('child_process').execSync;
const fs = require('fs');
const path = require('path');
async function run() {
try {
const serviceAccountFile = `/tmp/${(new Date()).getTime()}.json`; // Create temp json
const projectName = core.getInput('project-id');
const isDebug = core.getInput('debug');
const projectPath = path.join(process.cwd(), core.getInput('path'))
core.startGroup('Processing service account');
console.log('Copy service account');
fs.writeFileSync(serviceAccountFile, core.getInput('service-account'));
console.log('Activate service account');
execSync(`gcloud auth activate-service-account --key-file ${serviceAccountFile}`, { stdio: 'inherit' });
core.endGroup();
core.startGroup('Set Google Clound project');
execSync(`gcloud config set project ${projectName}`, {stdio: 'inherit'});
core.endGroup();
execSync(`cd ${projectPath}`, {stdio: 'inherit'});
if (isDebug) {
core.startGroup('Project info');
execSync(`gcloud info`, {stdio: 'inherit'});
core.endGroup();
} else {
core.startGroup('Depoy project');
execSync(`gcloud app deploy`, {stdio: 'inherit'});
core.endGroup();
}
core.startGroup('Remove service account');
fs.unlinkSync(serviceAccountFile);
core.endGroup();
}
catch (error) {
core.setFailed(error.message);
}
}
run();