Skip to content

Commit e06108d

Browse files
committed
Add checks for resource group
1 parent 644cb03 commit e06108d

File tree

1 file changed

+59
-2
lines changed

1 file changed

+59
-2
lines changed

dist/index.js

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ __nccwpck_require__.r(__webpack_exports__);
1414

1515

1616

17-
async function endpointExists(endpointName, resourceGroup, workspaceName) {
17+
async function checkIfEndpointExists(endpointName, resourceGroup, workspaceName) {
1818
try {
1919
let output = "";
2020
const options = {
@@ -27,14 +27,54 @@ async function endpointExists(endpointName, resourceGroup, workspaceName) {
2727
};
2828

2929
// Check if the endpoint exists
30-
await _actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec(`az ml online-endpoint show --name ${endpointName} --resource-group ${resourceGroup} --workspace-name ${workspaceName}`, [], options);
30+
await exec.exec(`az ml online-endpoint show --name ${endpointName} --resource-group ${resourceGroup} --workspace-name ${workspaceName}`, [], options);
3131

3232
return true; // If the command succeeds, the endpoint exists
3333
} catch (error) {
3434
return false; // If the command fails, the endpoint does not exist
3535
}
3636
}
3737

38+
async function checkIfResourceGroupExists(resourceGroup) {
39+
try {
40+
let output = "";
41+
const options = {
42+
listeners: {
43+
stdout: (data) => {
44+
output += data.toString();
45+
}
46+
},
47+
silent: true
48+
};
49+
50+
// Check if the resource group exists
51+
await _actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec(`az group show --name ${resourceGroup}`, [], options);
52+
return true; // If the command succeeds, the endpoint exists
53+
} catch (error) {
54+
return false; // If the command fails, the endpoint does not exist
55+
}
56+
}
57+
58+
async function checkIfWorkspaceExists(workspaceName, resourceGroup) {
59+
try {
60+
let output = "";
61+
const options = {
62+
listeners: {
63+
stdout: (data) => {
64+
output += data.toString();
65+
}
66+
},
67+
silent: true
68+
};
69+
70+
// Check if the workspace exists
71+
await _actions_exec__WEBPACK_IMPORTED_MODULE_1__.exec(`az ml workspace show --name ${workspaceName} --resource-group ${resourceGroup}`, [], options);
72+
return true; // If the command succeeds, the endpoint exists
73+
} catch (error) {
74+
return false; // If the command fails, the endpoint does not exist
75+
}
76+
}
77+
3878
try {
3979
const endpointName = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput("endpoint_name");
4080
const resourceGroup = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput("resource_group");
@@ -53,6 +93,23 @@ try {
5393
throw new Error("Workspace name is required");
5494
}
5595

96+
// Check if the resource group exists
97+
console.log(`🔹 Checking if resource group '${resourceGroup}' exists...`)
98+
;
99+
const resourceGroupExists = await checkIfResourceGroupExists(resourceGroup);
100+
if (!resourceGroupExists) {
101+
throw new Error(`Resource group '${resourceGroup}' does not exist.`);
102+
}
103+
104+
// Check if the workspace exists
105+
console.log(`🔹 Checking if workspace '${workspaceName}' exists in resource group '${resourceGroup}'...`)
106+
;
107+
const workspaceExists = await checkIfWorkspaceExists(workspaceName, resourceGroup);
108+
109+
if (!workspaceExists) {
110+
throw new Error(`Workspace '${workspaceName}' does not exist in resource group '${resourceGroup}'.`);
111+
}
112+
56113
console.log(`🔹 Checking if endpoint '${endpointName}' exists...`);
57114
const exists = await endpointExists(
58115
endpointName, resourceGroup, workspaceName

0 commit comments

Comments
 (0)