@@ -2,12 +2,17 @@ import * as core from "@actions/core";
2
2
import * as exec from "@actions/exec" ;
3
3
4
4
async function checkIfEndpointExists ( endpointName , resourceGroup , workspaceName ) {
5
+ let errorOutput = "" ;
6
+ let output = "" ;
7
+
5
8
try {
6
- let output = "" ;
7
9
const options = {
8
10
listeners : {
9
11
stdout : ( data ) => {
10
12
output += data . toString ( ) ;
13
+ } ,
14
+ stderr : ( data ) => {
15
+ errorOutput += data . toString ( ) ;
11
16
}
12
17
} ,
13
18
silent : true
@@ -16,49 +21,68 @@ async function checkIfEndpointExists(endpointName, resourceGroup, workspaceName)
16
21
// Check if the endpoint exists
17
22
await exec . exec ( `az ml online-endpoint show --name ${ endpointName } --resource-group ${ resourceGroup } --workspace-name ${ workspaceName } ` , [ ] , options ) ;
18
23
24
+ console . log ( "✅ Endpoint already exists. Output:" , output ) ;
19
25
return true ; // If the command succeeds, the endpoint exists
20
26
} catch ( error ) {
21
27
return false ; // If the command fails, the endpoint does not exist
22
28
}
23
29
}
24
30
25
31
async function checkIfResourceGroupExists ( resourceGroup ) {
32
+ let errorOutput = "" ;
33
+ let output = "" ;
34
+
26
35
try {
27
- let output = "" ;
28
36
const options = {
29
37
listeners : {
30
38
stdout : ( data ) => {
31
39
output += data . toString ( ) ;
40
+ } ,
41
+ stderr : ( data ) => {
42
+ errorOutput += data . toString ( ) ;
32
43
}
33
44
} ,
34
45
silent : true
35
46
} ;
47
+ // Execute the Azure CLI command
48
+ await exec . exec ( `az group show --name ${ resourceGroup } --resource-group ${ resourceGroup } ` , [ ] , options ) ;
36
49
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
50
+ console . log ( "✅ Resource Group Found. Output:" , output ) ;
51
+ return true ;
40
52
} catch ( error ) {
41
- return false ; // If the command fails, the endpoint does not exist
53
+ console . log (
54
+ "❌ Resource Group Not Found or Error Occurred:" , errorOutput || error . message
55
+ ) ;
56
+ return false ; // Return false if the workspace does not exist
42
57
}
43
58
}
44
59
45
60
async function checkIfWorkspaceExists ( workspaceName , resourceGroup ) {
61
+ let errorOutput = "" ;
62
+ let output = "" ;
63
+
46
64
try {
47
- let output = "" ;
48
65
const options = {
49
66
listeners : {
50
67
stdout : ( data ) => {
51
68
output += data . toString ( ) ;
69
+ } ,
70
+ stderr : ( data ) => {
71
+ errorOutput += data . toString ( ) ;
52
72
}
53
73
} ,
54
74
silent : true
55
75
} ;
56
76
57
77
// Check if the workspace exists
58
78
await exec . exec ( `az ml workspace show --name ${ workspaceName } --resource-group ${ resourceGroup } ` , [ ] , options ) ;
59
- return true ; // If the command succeeds, the endpoint exists
79
+ console . log ( "✅ Resource Group Found. Output:" , output ) ;
80
+ return true ;
60
81
} catch ( error ) {
61
- return false ; // If the command fails, the endpoint does not exist
82
+ console . log (
83
+ "❌ Resource Group Not Found or Error Occurred:" , errorOutput || error . message
84
+ ) ;
85
+ return false ;
62
86
}
63
87
}
64
88
@@ -84,8 +108,11 @@ try {
84
108
console . log ( `🔹 Checking if resource group '${ resourceGroup } ' exists...` )
85
109
;
86
110
const resourceGroupExists = await checkIfResourceGroupExists ( resourceGroup ) ;
111
+
87
112
if ( ! resourceGroupExists ) {
88
113
throw new Error ( `Resource group '${ resourceGroup } ' does not exist.` ) ;
114
+ } else {
115
+ console . log ( `✅ Resource group '${ resourceGroup } ' exists.` ) ;
89
116
}
90
117
91
118
// Check if the workspace exists
@@ -95,17 +122,19 @@ try {
95
122
96
123
if ( ! workspaceExists ) {
97
124
throw new Error ( `Workspace '${ workspaceName } ' does not exist in resource group '${ resourceGroup } '.` ) ;
125
+ } else {
126
+ console . log ( `✅ Workspace '${ workspaceName } ' exists in resource group '${ resourceGroup } '.` ) ;
98
127
}
99
128
100
129
console . log ( `🔹 Checking if endpoint '${ endpointName } ' exists...` ) ;
101
- const exists = await endpointExists (
130
+ const exists = await checkIfEndpointExists (
102
131
endpointName , resourceGroup , workspaceName
103
132
) ;
104
133
105
134
if ( exists ) {
106
135
console . log ( `✅ Endpoint '${ endpointName } ' already exists. Skipping creation.` ) ;
107
136
} else {
108
- console . log ( `🔹 Creating endpoint ' ${ endpointName } ' ...` ) ;
137
+ console . log ( `🔹 Endpoint does not exist, creating it ...` )
109
138
await exec . exec ( `az ml online-endpoint create --name ${ endpointName } --resource-group ${ resourceGroup } --workspace-name ${ workspaceName } ` ) ;
110
139
console . log ( `✅ Successfully created endpoint: ${ endpointName } ` ) ;
111
140
}
0 commit comments