Skip to content

Commit 5bd8183

Browse files
committed
Add dist files
1 parent 8ee763e commit 5bd8183

File tree

2 files changed

+363
-0
lines changed

2 files changed

+363
-0
lines changed

dist/index.js

Lines changed: 360 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,360 @@
1+
/******/ var __webpack_modules__ = ({
2+
3+
/***/ 210:
4+
/***/ ((__webpack_module__, __unused_webpack___webpack_exports__, __nccwpck_require__) => {
5+
6+
__nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
7+
const core = require('@actions/core');
8+
const github = require('@actions/github');
9+
const fs = require('fs');
10+
const exec = require('@actions/exec');
11+
12+
13+
async function checkIfResourceGroupExists(resourceGroup) {
14+
/**
15+
* Check if the resource group exists.
16+
* @param {string} resourceGroup - The name of the resource group.
17+
* @return {boolean} - Returns true if the resource group exists, false otherwise.
18+
*/
19+
let errorOutput = "";
20+
let output = "";
21+
22+
try {
23+
const options = {
24+
listeners: {
25+
stdout: (data) => {
26+
output += data.toString();
27+
},
28+
stderr: (data) => {
29+
errorOutput += data.toString();
30+
}
31+
},
32+
silent: true
33+
};
34+
// Execute the Azure CLI command
35+
await exec.exec(`az group show --name ${resourceGroup} --resource-group ${resourceGroup}`, [], options);
36+
37+
console.log("✅ Resource Group Found. Output:", output);
38+
return true;
39+
} catch (error) {
40+
console.log(
41+
"❌ Resource Group Not Found or Error Occurred:", errorOutput || error.message
42+
);
43+
return false; // Return false if the workspace does not exist
44+
}
45+
}
46+
47+
async function checkIfWorkspaceExists(workspaceName, resourceGroup) {
48+
/**
49+
* Check if the workspace exists in the specified resource group.
50+
* @param {string} workspaceName - The name of the workspace.
51+
* @param {string} resourceGroup - The name of the resource group.
52+
* @return {boolean} - Returns true if the workspace exists, false otherwise.
53+
*/
54+
let errorOutput = "";
55+
let output = "";
56+
57+
try {
58+
const options = {
59+
listeners: {
60+
stdout: (data) => {
61+
output += data.toString();
62+
},
63+
stderr: (data) => {
64+
errorOutput += data.toString();
65+
}
66+
},
67+
silent: true
68+
};
69+
70+
// Check if the workspace exists
71+
await exec.exec(`az ml workspace show --name ${workspaceName} --resource-group ${resourceGroup}`, [], options);
72+
console.log("✅ Resource Group Found. Output:", output);
73+
return true;
74+
} catch (error) {
75+
console.log(
76+
"❌ Resource Group Not Found or Error Occurred:", errorOutput || error.message
77+
);
78+
return false;
79+
}
80+
}
81+
82+
async function checkIfModelInWorkspaceExists(
83+
modelName, modelVersion, workspaceName, resourceGroup
84+
) {
85+
/**
86+
* Check if the model exists in the specified workspace.
87+
* @param {string} modelName - The name of the model.
88+
* @param {string} modelVersion - The version of the model.
89+
* @param {string} workspaceName - The name of the workspace.
90+
* @param {string} resourceGroup - The name of the resource group.
91+
* @return {boolean} - Returns true if the model exists, false otherwise.
92+
*/
93+
94+
let errorOutput = "";
95+
let output = "";
96+
97+
try {
98+
const options = {
99+
listeners: {
100+
stdout: (data) => {
101+
output += data.toString();
102+
},
103+
stderr: (data) => {
104+
errorOutput += data.toString();
105+
}
106+
},
107+
silent: true
108+
};
109+
110+
// Check if model exists in registry
111+
await exec.exec(`az ml model show --name ${modelName} --version ${modelVersion} --workspace-name ${workspaceName} --resource-group ${resourceGroup}`, [], options);
112+
console.log("✅ Model Found. Output:", output);
113+
return true;
114+
} catch (error) {
115+
return false;
116+
}
117+
}
118+
119+
async function registerModelInWorkspace(
120+
modelName, modelVersion, modelPath, modelType, workspaceName, resourceGroup
121+
) {
122+
/**
123+
* Register the model in the specified workspace.
124+
* @param {string} modelName - The name of the model.
125+
* @param {string} modelVersion - The version of the model.
126+
* @param {string} modelPath - The path to the model file.
127+
* @param {string} modelType - The type of the model.
128+
* @param {string} workspaceName - The name of the workspace.
129+
* @param {string} resourceGroup - The name of the resource group.
130+
* @return {boolean} - Returns true if the model is registered, false otherwise.
131+
*/
132+
133+
let errorOutput = "";
134+
let output = "";
135+
136+
try {
137+
const options = {
138+
listeners: {
139+
stdout: (data) => {
140+
output += data.toString();
141+
},
142+
stderr: (data) => {
143+
errorOutput += data.toString();
144+
}
145+
},
146+
silent: true
147+
};
148+
console.log(modelPath)
149+
// Register the model in the workspace
150+
await exec.exec(`az ml model create --name ${modelName} --version ${modelVersion} --path ${modelPath} --workspace-name ${workspaceName} --resource-group ${resourceGroup} --type ${modelType}`, [], options);
151+
console.log("✅ Model Registered. Output:", output);
152+
return true;
153+
} catch (error) {
154+
console.log(
155+
"❌ Model Not Registered or Error Occurred:", errorOutput || error.message
156+
);
157+
return false;
158+
}
159+
}
160+
161+
162+
try {
163+
// Get the input parameters
164+
const resourceGroup = core.getInput('resource-group');
165+
const workspaceName = core.getInput('workspace-name');
166+
const modelName = core.getInput('model-name');
167+
const modelVersion = core.getInput('model-version');
168+
const modelPath = core.getInput('model-path');
169+
const modelType = core.getInput('model-type');
170+
171+
if(modelPath === undefined) {
172+
throw new Error("Model path is required.");
173+
}
174+
175+
if(modelName === undefined) {
176+
throw new Error("Model name is required.");
177+
}
178+
179+
if(modelVersion === undefined) {
180+
throw new Error("Model version is required.");
181+
}
182+
183+
if(workspaceName === undefined) {
184+
throw new Error("Workspace name is required.");
185+
}
186+
187+
if(resourceGroup === undefined) {
188+
throw new Error("Resource group is required.");
189+
}
190+
191+
// Check if the resource group exists
192+
console.log(`🔹 Checking if resource group '${resourceGroup}' exists...`)
193+
;
194+
let resourceGroupExists = await checkIfResourceGroupExists(resourceGroup);
195+
196+
if (!resourceGroupExists) {
197+
throw new Error(`Resource group '${resourceGroup}' does not exist.`);
198+
} else {
199+
console.log(`✅ Resource group '${resourceGroup}' exists.`);
200+
}
201+
202+
// Check if the workspace exists
203+
console.log(`🔹 Checking if workspace '${workspaceName}' exists in resource group '${workspaceName}'...`)
204+
;
205+
const workspaceExists = await checkIfWorkspaceExists(workspaceName, resourceGroup);
206+
207+
if (!workspaceExists) {
208+
throw new Error(`Workspace '${workspaceName}' does not exist in resource group '${resourceGroup}'.`);
209+
} else {
210+
console.log(`✅ Workspace '${workspaceName}' exists in resource group '${resourceGroup}'.`);
211+
}
212+
213+
// Check if model exists in workspace
214+
console.log(`🔹 Checking if model '${modelName}' exists in workspace '${workspaceName}'...`);
215+
216+
const modelInWorkspaceExists = await checkIfModelInWorkspaceExists(
217+
modelName, modelVersion, workspaceName, resourceGroup
218+
);
219+
220+
if (modelInWorkspaceExists) {
221+
console.log(`✅ Model '${modelName}' with version '${modelVersion}' already exists in workspace '${workspaceName}'.`);
222+
process.exit(0);
223+
}
224+
225+
// Register the model in the workspace
226+
console.log(`🔹 Registering model '${modelName}' with version '${modelVersion}' in workspace '${workspaceName}'...`);
227+
228+
const modelRegistered = await registerModelInWorkspace(
229+
modelName, modelVersion, modelPath, modelType, workspaceName, resourceGroup
230+
);
231+
232+
if (modelRegistered) {
233+
console.log(`✅ Model '${modelName}' with version '${modelVersion}' registered in workspace '${workspaceName}'.`);
234+
} else {
235+
throw new Error(`Model '${modelName}' with version '${modelVersion}' could not be registered in workspace '${workspaceName}'.`);
236+
}
237+
} catch (error) {
238+
console.log(error.message);
239+
core.setFailed(`❌ Action failed: ${error.message}`);
240+
}
241+
242+
__webpack_async_result__();
243+
} catch(e) { __webpack_async_result__(e); } }, 1);
244+
245+
/***/ })
246+
247+
/******/ });
248+
/************************************************************************/
249+
/******/ // The module cache
250+
/******/ var __webpack_module_cache__ = {};
251+
/******/
252+
/******/ // The require function
253+
/******/ function __nccwpck_require__(moduleId) {
254+
/******/ // Check if module is in cache
255+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
256+
/******/ if (cachedModule !== undefined) {
257+
/******/ return cachedModule.exports;
258+
/******/ }
259+
/******/ // Create a new module (and put it into the cache)
260+
/******/ var module = __webpack_module_cache__[moduleId] = {
261+
/******/ // no module.id needed
262+
/******/ // no module.loaded needed
263+
/******/ exports: {}
264+
/******/ };
265+
/******/
266+
/******/ // Execute the module function
267+
/******/ var threw = true;
268+
/******/ try {
269+
/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__);
270+
/******/ threw = false;
271+
/******/ } finally {
272+
/******/ if(threw) delete __webpack_module_cache__[moduleId];
273+
/******/ }
274+
/******/
275+
/******/ // Return the exports of the module
276+
/******/ return module.exports;
277+
/******/ }
278+
/******/
279+
/************************************************************************/
280+
/******/ /* webpack/runtime/async module */
281+
/******/ (() => {
282+
/******/ var webpackQueues = typeof Symbol === "function" ? Symbol("webpack queues") : "__webpack_queues__";
283+
/******/ var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "__webpack_exports__";
284+
/******/ var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__";
285+
/******/ var resolveQueue = (queue) => {
286+
/******/ if(queue && queue.d < 1) {
287+
/******/ queue.d = 1;
288+
/******/ queue.forEach((fn) => (fn.r--));
289+
/******/ queue.forEach((fn) => (fn.r-- ? fn.r++ : fn()));
290+
/******/ }
291+
/******/ }
292+
/******/ var wrapDeps = (deps) => (deps.map((dep) => {
293+
/******/ if(dep !== null && typeof dep === "object") {
294+
/******/ if(dep[webpackQueues]) return dep;
295+
/******/ if(dep.then) {
296+
/******/ var queue = [];
297+
/******/ queue.d = 0;
298+
/******/ dep.then((r) => {
299+
/******/ obj[webpackExports] = r;
300+
/******/ resolveQueue(queue);
301+
/******/ }, (e) => {
302+
/******/ obj[webpackError] = e;
303+
/******/ resolveQueue(queue);
304+
/******/ });
305+
/******/ var obj = {};
306+
/******/ obj[webpackQueues] = (fn) => (fn(queue));
307+
/******/ return obj;
308+
/******/ }
309+
/******/ }
310+
/******/ var ret = {};
311+
/******/ ret[webpackQueues] = x => {};
312+
/******/ ret[webpackExports] = dep;
313+
/******/ return ret;
314+
/******/ }));
315+
/******/ __nccwpck_require__.a = (module, body, hasAwait) => {
316+
/******/ var queue;
317+
/******/ hasAwait && ((queue = []).d = -1);
318+
/******/ var depQueues = new Set();
319+
/******/ var exports = module.exports;
320+
/******/ var currentDeps;
321+
/******/ var outerResolve;
322+
/******/ var reject;
323+
/******/ var promise = new Promise((resolve, rej) => {
324+
/******/ reject = rej;
325+
/******/ outerResolve = resolve;
326+
/******/ });
327+
/******/ promise[webpackExports] = exports;
328+
/******/ promise[webpackQueues] = (fn) => (queue && fn(queue), depQueues.forEach(fn), promise["catch"](x => {}));
329+
/******/ module.exports = promise;
330+
/******/ body((deps) => {
331+
/******/ currentDeps = wrapDeps(deps);
332+
/******/ var fn;
333+
/******/ var getResult = () => (currentDeps.map((d) => {
334+
/******/ if(d[webpackError]) throw d[webpackError];
335+
/******/ return d[webpackExports];
336+
/******/ }))
337+
/******/ var promise = new Promise((resolve) => {
338+
/******/ fn = () => (resolve(getResult));
339+
/******/ fn.r = 0;
340+
/******/ var fnQueue = (q) => (q !== queue && !depQueues.has(q) && (depQueues.add(q), q && !q.d && (fn.r++, q.push(fn))));
341+
/******/ currentDeps.map((dep) => (dep[webpackQueues](fnQueue)));
342+
/******/ });
343+
/******/ return fn.r ? promise : getResult();
344+
/******/ }, (err) => ((err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue)));
345+
/******/ queue && queue.d < 0 && (queue.d = 0);
346+
/******/ };
347+
/******/ })();
348+
/******/
349+
/******/ /* webpack/runtime/compat */
350+
/******/
351+
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/";
352+
/******/
353+
/************************************************************************/
354+
/******/
355+
/******/ // startup
356+
/******/ // Load entry module and return exports
357+
/******/ // This entry module used 'module' so it can't be inlined
358+
/******/ var __webpack_exports__ = __nccwpck_require__(210);
359+
/******/ __webpack_exports__ = await __webpack_exports__;
360+
/******/

dist/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}

0 commit comments

Comments
 (0)