-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (47 loc) · 1.82 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
50
51
52
53
54
55
56
57
58
const core = require('@actions/core');
const exec = require('@actions/exec');
// Function to get inputs from the GitHub Action
function getInputs() {
return {
resource_type: core.getInput('resource_type'),
action: core.getInput('action'),
value: core.getInput('value')
};
}
// Function to format the command for creating a workspace
function getWorkspaceCreateCommand(inputs){
return `${inputs.resource_type} ${inputs.action} ${inputs.value}`;
}
// Function to format the command for listing workspaces
function getWorkspaceListCommand(inputs){
return `${inputs.resource_type} ${inputs.action}`;
}
// Function to get the formatted command based on the inputs
function getFormatedCommand() {
const inputs = getInputs();
if(inputs.resource_type === 'workspace' && inputs.action === 'create'){
return getWorkspaceCreateCommand(inputs);
}
if(inputs.resource_type === 'workspace' && inputs.action === 'list'){
return getWorkspaceListCommand(inputs);
}
}
// Main function to run the Docker command
async function run() {
try {
// Pull the Docker image
await exec.exec('docker pull ghcr.io/stevenbuglione/fabric-cli:release');
// Initialize command with Docker image and hardcoded environment variables
let command = `docker run --rm -e AZURE_TENANT_ID="${process.env.AZURE_TENANT_ID}" -e AZURE_CLIENT_ID="${process.env.AZURE_CLIENT_ID}" -e AZURE_CLIENT_SECRET="${process.env.AZURE_CLIENT_SECRET}" ghcr.io/stevenbuglione/fabric-cli:release`;
// Append inputs to command inline
command += ` ${getFormatedCommand()}`;
// Run the Docker image with the necessary arguments and environment variables
await exec.exec(command);
} catch (error) {
core.setFailed(error.message);
}
}
// Run the main function and log any errors
run().catch(error => {
console.error(error.message);
});