-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
71 lines (55 loc) · 2.06 KB
/
index.js
File metadata and controls
71 lines (55 loc) · 2.06 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const Core = require('@actions/core');
// const GitHub = require('@actions/github');
const FS = require('fs');
const OS = require('os');
const Util = require('util');
const execSync = Util.promisify(require('child_process').execSync);
try {
if(process.platform !== 'linux') {
throw new Error('This action runs only on Linux currently');
}
const is_verbose = Core.getInput('verbose');
const oci_user = Core.getInput('user');
const oci_tenancy = Core.getInput('tenancy');
const oci_fingerprint = Core.getInput('fingerprint');
const oci_region = Core.getInput('region');
const oci_api_key = Core.getInput('api_key');
const dotoci_path = OS.homedir() + '/.oci';
if(is_verbose) {
console.log('Creating .oci at', dotoci_path);
}
FS.mkdirSync(dotoci_path, 0777);
const api_key_path = dotoci_path + '/api_key.pem';
if(is_verbose) {
console.log('Saving API key to', api_key_path);
}
FS.writeFileSync(api_key_path, oci_api_key);
let config_file = '[DEFAULT]\n';
config_file += `user=${oci_user}\n`;
config_file += `fingerprint=${oci_fingerprint}\n`;
config_file += `key_file=${api_key_path}\n`;
config_file += `tenancy=${oci_tenancy}\n`;
config_file += `region=${oci_region}\n`;
const config_file_path = dotoci_path + '/config';
if(is_verbose) {
console.log('Saving config file to', config_file_path);
}
FS.writeFileSync(config_file_path, config_file);
if(is_verbose) {
console.log('Downloading OCI install script');
}
// version 2.25.4
execSync(`wget https://raw.githubusercontent.com/oracle/oci-cli/ec0093aff18e040a35f440c34f45af07c6eb53c5/scripts/install/install.sh`);
const bin_path = '/usr/local/bin';
if(is_verbose) {
console.log('Installing OCI', bin_path);
}
execSync(`bash install.sh --accept-all-defaults --exec-dir ${bin_path}`);
if(is_verbose) {
console.log('Fixing permissions');
}
execSync(`oci setup repair-file-permissions --file ${config_file_path}`);
execSync(`oci setup repair-file-permissions --file ${api_key_path}`);
} catch (error) {
Core.setFailed(error.message);
}