@@ -2,12 +2,17 @@ import * as core from "@actions/core";
22import * as exec from "@actions/exec" ;
33
44async function checkIfEndpointExists ( endpointName , resourceGroup , workspaceName ) {
5+ let errorOutput = "" ;
6+ let output = "" ;
7+
58 try {
6- let output = "" ;
79 const options = {
810 listeners : {
911 stdout : ( data ) => {
1012 output += data . toString ( ) ;
13+ } ,
14+ stderr : ( data ) => {
15+ errorOutput += data . toString ( ) ;
1116 }
1217 } ,
1318 silent : true
@@ -16,49 +21,68 @@ async function checkIfEndpointExists(endpointName, resourceGroup, workspaceName)
1621 // Check if the endpoint exists
1722 await exec . exec ( `az ml online-endpoint show --name ${ endpointName } --resource-group ${ resourceGroup } --workspace-name ${ workspaceName } ` , [ ] , options ) ;
1823
24+ console . log ( "✅ Endpoint already exists. Output:" , output ) ;
1925 return true ; // If the command succeeds, the endpoint exists
2026 } catch ( error ) {
2127 return false ; // If the command fails, the endpoint does not exist
2228 }
2329}
2430
2531async function checkIfResourceGroupExists ( resourceGroup ) {
32+ let errorOutput = "" ;
33+ let output = "" ;
34+
2635 try {
27- let output = "" ;
2836 const options = {
2937 listeners : {
3038 stdout : ( data ) => {
3139 output += data . toString ( ) ;
40+ } ,
41+ stderr : ( data ) => {
42+ errorOutput += data . toString ( ) ;
3243 }
3344 } ,
3445 silent : true
3546 } ;
47+ // Execute the Azure CLI command
48+ await exec . exec ( `az group show --name ${ resourceGroup } --resource-group ${ resourceGroup } ` , [ ] , options ) ;
3649
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 ;
4052 } 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
4257 }
4358}
4459
4560async function checkIfWorkspaceExists ( workspaceName , resourceGroup ) {
61+ let errorOutput = "" ;
62+ let output = "" ;
63+
4664 try {
47- let output = "" ;
4865 const options = {
4966 listeners : {
5067 stdout : ( data ) => {
5168 output += data . toString ( ) ;
69+ } ,
70+ stderr : ( data ) => {
71+ errorOutput += data . toString ( ) ;
5272 }
5373 } ,
5474 silent : true
5575 } ;
5676
5777 // Check if the workspace exists
5878 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 ;
6081 } 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 ;
6286 }
6387}
6488
@@ -84,8 +108,11 @@ try {
84108 console . log ( `🔹 Checking if resource group '${ resourceGroup } ' exists...` )
85109 ;
86110 const resourceGroupExists = await checkIfResourceGroupExists ( resourceGroup ) ;
111+
87112 if ( ! resourceGroupExists ) {
88113 throw new Error ( `Resource group '${ resourceGroup } ' does not exist.` ) ;
114+ } else {
115+ console . log ( `✅ Resource group '${ resourceGroup } ' exists.` ) ;
89116 }
90117
91118 // Check if the workspace exists
@@ -95,17 +122,19 @@ try {
95122
96123 if ( ! workspaceExists ) {
97124 throw new Error ( `Workspace '${ workspaceName } ' does not exist in resource group '${ resourceGroup } '.` ) ;
125+ } else {
126+ console . log ( `✅ Workspace '${ workspaceName } ' exists in resource group '${ resourceGroup } '.` ) ;
98127 }
99128
100129 console . log ( `🔹 Checking if endpoint '${ endpointName } ' exists...` ) ;
101- const exists = await endpointExists (
130+ const exists = await checkIfEndpointExists (
102131 endpointName , resourceGroup , workspaceName
103132 ) ;
104133
105134 if ( exists ) {
106135 console . log ( `✅ Endpoint '${ endpointName } ' already exists. Skipping creation.` ) ;
107136 } else {
108- console . log ( `🔹 Creating endpoint ' ${ endpointName } ' ...` ) ;
137+ console . log ( `🔹 Endpoint does not exist, creating it ...` )
109138 await exec . exec ( `az ml online-endpoint create --name ${ endpointName } --resource-group ${ resourceGroup } --workspace-name ${ workspaceName } ` ) ;
110139 console . log ( `✅ Successfully created endpoint: ${ endpointName } ` ) ;
111140 }
0 commit comments