Skip to content

Commit 644cb03

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

File tree

1 file changed

+58
-1
lines changed

1 file changed

+58
-1
lines changed

index.js

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as core from "@actions/core";
22
import * as exec from "@actions/exec";
33

4-
async function endpointExists(endpointName, resourceGroup, workspaceName) {
4+
async function checkIfEndpointExists(endpointName, resourceGroup, workspaceName) {
55
try {
66
let output = "";
77
const options = {
@@ -22,6 +22,46 @@ async function endpointExists(endpointName, resourceGroup, workspaceName) {
2222
}
2323
}
2424

25+
async function checkIfResourceGroupExists(resourceGroup) {
26+
try {
27+
let output = "";
28+
const options = {
29+
listeners: {
30+
stdout: (data) => {
31+
output += data.toString();
32+
}
33+
},
34+
silent: true
35+
};
36+
37+
// Check if the resource group exists
38+
await exec.exec(`az group show --name ${resourceGroup}`, [], options);
39+
return true; // If the command succeeds, the endpoint exists
40+
} catch (error) {
41+
return false; // If the command fails, the endpoint does not exist
42+
}
43+
}
44+
45+
async function checkIfWorkspaceExists(workspaceName, resourceGroup) {
46+
try {
47+
let output = "";
48+
const options = {
49+
listeners: {
50+
stdout: (data) => {
51+
output += data.toString();
52+
}
53+
},
54+
silent: true
55+
};
56+
57+
// Check if the workspace exists
58+
await exec.exec(`az ml workspace show --name ${workspaceName} --resource-group ${resourceGroup}`, [], options);
59+
return true; // If the command succeeds, the endpoint exists
60+
} catch (error) {
61+
return false; // If the command fails, the endpoint does not exist
62+
}
63+
}
64+
2565
try {
2666
const endpointName = core.getInput("endpoint_name");
2767
const resourceGroup = core.getInput("resource_group");
@@ -40,6 +80,23 @@ try {
4080
throw new Error("Workspace name is required");
4181
}
4282

83+
// Check if the resource group exists
84+
console.log(`🔹 Checking if resource group '${resourceGroup}' exists...`)
85+
;
86+
const resourceGroupExists = await checkIfResourceGroupExists(resourceGroup);
87+
if (!resourceGroupExists) {
88+
throw new Error(`Resource group '${resourceGroup}' does not exist.`);
89+
}
90+
91+
// Check if the workspace exists
92+
console.log(`🔹 Checking if workspace '${workspaceName}' exists in resource group '${resourceGroup}'...`)
93+
;
94+
const workspaceExists = await checkIfWorkspaceExists(workspaceName, resourceGroup);
95+
96+
if (!workspaceExists) {
97+
throw new Error(`Workspace '${workspaceName}' does not exist in resource group '${resourceGroup}'.`);
98+
}
99+
43100
console.log(`🔹 Checking if endpoint '${endpointName}' exists...`);
44101
const exists = await endpointExists(
45102
endpointName, resourceGroup, workspaceName

0 commit comments

Comments
 (0)