Skip to content

Commit b3188ab

Browse files
authored
Reuse existing nsc if found. (#7)
* Reuse existing nsc if found.
1 parent 90b5aeb commit b3188ab

File tree

4 files changed

+373
-9
lines changed

4 files changed

+373
-9
lines changed

dist/main/index.js

Lines changed: 343 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6552,6 +6552,124 @@ function v4(options, buf, offset) {
65526552
module.exports = v4;
65536553

65546554

6555+
/***/ }),
6556+
6557+
/***/ 6143:
6558+
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
6559+
6560+
const { isexe, sync: isexeSync } = __nccwpck_require__(899)
6561+
const { join, delimiter, sep, posix } = __nccwpck_require__(1017)
6562+
6563+
const isWindows = process.platform === 'win32'
6564+
6565+
// used to check for slashed in commands passed in. always checks for the posix
6566+
// seperator on all platforms, and checks for the current separator when not on
6567+
// a posix platform. don't use the isWindows check for this since that is mocked
6568+
// in tests but we still need the code to actually work when called. that is also
6569+
// why it is ignored from coverage.
6570+
/* istanbul ignore next */
6571+
const rSlash = new RegExp(`[${posix.sep}${sep === posix.sep ? '' : sep}]`.replace(/(\\)/g, '\\$1'))
6572+
const rRel = new RegExp(`^\\.${rSlash.source}`)
6573+
6574+
const getNotFoundError = (cmd) =>
6575+
Object.assign(new Error(`not found: ${cmd}`), { code: 'ENOENT' })
6576+
6577+
const getPathInfo = (cmd, {
6578+
path: optPath = process.env.PATH,
6579+
pathExt: optPathExt = process.env.PATHEXT,
6580+
delimiter: optDelimiter = delimiter,
6581+
}) => {
6582+
// If it has a slash, then we don't bother searching the pathenv.
6583+
// just check the file itself, and that's it.
6584+
const pathEnv = cmd.match(rSlash) ? [''] : [
6585+
// windows always checks the cwd first
6586+
...(isWindows ? [process.cwd()] : []),
6587+
...(optPath || /* istanbul ignore next: very unusual */ '').split(optDelimiter),
6588+
]
6589+
6590+
if (isWindows) {
6591+
const pathExtExe = optPathExt ||
6592+
['.EXE', '.CMD', '.BAT', '.COM'].join(optDelimiter)
6593+
const pathExt = pathExtExe.split(optDelimiter).flatMap((item) => [item, item.toLowerCase()])
6594+
if (cmd.includes('.') && pathExt[0] !== '') {
6595+
pathExt.unshift('')
6596+
}
6597+
return { pathEnv, pathExt, pathExtExe }
6598+
}
6599+
6600+
return { pathEnv, pathExt: [''] }
6601+
}
6602+
6603+
const getPathPart = (raw, cmd) => {
6604+
const pathPart = /^".*"$/.test(raw) ? raw.slice(1, -1) : raw
6605+
const prefix = !pathPart && rRel.test(cmd) ? cmd.slice(0, 2) : ''
6606+
return prefix + join(pathPart, cmd)
6607+
}
6608+
6609+
const which = async (cmd, opt = {}) => {
6610+
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt)
6611+
const found = []
6612+
6613+
for (const envPart of pathEnv) {
6614+
const p = getPathPart(envPart, cmd)
6615+
6616+
for (const ext of pathExt) {
6617+
const withExt = p + ext
6618+
const is = await isexe(withExt, { pathExt: pathExtExe, ignoreErrors: true })
6619+
if (is) {
6620+
if (!opt.all) {
6621+
return withExt
6622+
}
6623+
found.push(withExt)
6624+
}
6625+
}
6626+
}
6627+
6628+
if (opt.all && found.length) {
6629+
return found
6630+
}
6631+
6632+
if (opt.nothrow) {
6633+
return null
6634+
}
6635+
6636+
throw getNotFoundError(cmd)
6637+
}
6638+
6639+
const whichSync = (cmd, opt = {}) => {
6640+
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt)
6641+
const found = []
6642+
6643+
for (const pathEnvPart of pathEnv) {
6644+
const p = getPathPart(pathEnvPart, cmd)
6645+
6646+
for (const ext of pathExt) {
6647+
const withExt = p + ext
6648+
const is = isexeSync(withExt, { pathExt: pathExtExe, ignoreErrors: true })
6649+
if (is) {
6650+
if (!opt.all) {
6651+
return withExt
6652+
}
6653+
found.push(withExt)
6654+
}
6655+
}
6656+
}
6657+
6658+
if (opt.all && found.length) {
6659+
return found
6660+
}
6661+
6662+
if (opt.nothrow) {
6663+
return null
6664+
}
6665+
6666+
throw getNotFoundError(cmd)
6667+
}
6668+
6669+
module.exports = which
6670+
which.sync = whichSync
6671+
6672+
65556673
/***/ }),
65566674

65576675
/***/ 9491:
@@ -6594,6 +6712,14 @@ module.exports = require("fs");
65946712

65956713
/***/ }),
65966714

6715+
/***/ 3292:
6716+
/***/ ((module) => {
6717+
6718+
"use strict";
6719+
module.exports = require("fs/promises");
6720+
6721+
/***/ }),
6722+
65976723
/***/ 3685:
65986724
/***/ ((module) => {
65996725

@@ -6672,6 +6798,212 @@ module.exports = require("tls");
66726798
"use strict";
66736799
module.exports = require("util");
66746800

6801+
/***/ }),
6802+
6803+
/***/ 899:
6804+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
6805+
6806+
"use strict";
6807+
6808+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6809+
if (k2 === undefined) k2 = k;
6810+
var desc = Object.getOwnPropertyDescriptor(m, k);
6811+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6812+
desc = { enumerable: true, get: function() { return m[k]; } };
6813+
}
6814+
Object.defineProperty(o, k2, desc);
6815+
}) : (function(o, m, k, k2) {
6816+
if (k2 === undefined) k2 = k;
6817+
o[k2] = m[k];
6818+
}));
6819+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
6820+
Object.defineProperty(o, "default", { enumerable: true, value: v });
6821+
}) : function(o, v) {
6822+
o["default"] = v;
6823+
});
6824+
var __importStar = (this && this.__importStar) || function (mod) {
6825+
if (mod && mod.__esModule) return mod;
6826+
var result = {};
6827+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
6828+
__setModuleDefault(result, mod);
6829+
return result;
6830+
};
6831+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
6832+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
6833+
};
6834+
Object.defineProperty(exports, "__esModule", ({ value: true }));
6835+
exports.sync = exports.isexe = exports.posix = exports.win32 = void 0;
6836+
const posix = __importStar(__nccwpck_require__(1401));
6837+
exports.posix = posix;
6838+
const win32 = __importStar(__nccwpck_require__(7079));
6839+
exports.win32 = win32;
6840+
__exportStar(__nccwpck_require__(2565), exports);
6841+
const platform = process.env._ISEXE_TEST_PLATFORM_ || process.platform;
6842+
const impl = platform === 'win32' ? win32 : posix;
6843+
/**
6844+
* Determine whether a path is executable on the current platform.
6845+
*/
6846+
exports.isexe = impl.isexe;
6847+
/**
6848+
* Synchronously determine whether a path is executable on the
6849+
* current platform.
6850+
*/
6851+
exports.sync = impl.sync;
6852+
//# sourceMappingURL=index.js.map
6853+
6854+
/***/ }),
6855+
6856+
/***/ 2565:
6857+
/***/ ((__unused_webpack_module, exports) => {
6858+
6859+
"use strict";
6860+
6861+
Object.defineProperty(exports, "__esModule", ({ value: true }));
6862+
//# sourceMappingURL=options.js.map
6863+
6864+
/***/ }),
6865+
6866+
/***/ 1401:
6867+
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
6868+
6869+
"use strict";
6870+
6871+
/**
6872+
* This is the Posix implementation of isexe, which uses the file
6873+
* mode and uid/gid values.
6874+
*
6875+
* @module
6876+
*/
6877+
Object.defineProperty(exports, "__esModule", ({ value: true }));
6878+
exports.sync = exports.isexe = void 0;
6879+
const fs_1 = __nccwpck_require__(7147);
6880+
const promises_1 = __nccwpck_require__(3292);
6881+
/**
6882+
* Determine whether a path is executable according to the mode and
6883+
* current (or specified) user and group IDs.
6884+
*/
6885+
const isexe = async (path, options = {}) => {
6886+
const { ignoreErrors = false } = options;
6887+
try {
6888+
return checkStat(await (0, promises_1.stat)(path), options);
6889+
}
6890+
catch (e) {
6891+
const er = e;
6892+
if (ignoreErrors || er.code === 'EACCES')
6893+
return false;
6894+
throw er;
6895+
}
6896+
};
6897+
exports.isexe = isexe;
6898+
/**
6899+
* Synchronously determine whether a path is executable according to
6900+
* the mode and current (or specified) user and group IDs.
6901+
*/
6902+
const sync = (path, options = {}) => {
6903+
const { ignoreErrors = false } = options;
6904+
try {
6905+
return checkStat((0, fs_1.statSync)(path), options);
6906+
}
6907+
catch (e) {
6908+
const er = e;
6909+
if (ignoreErrors || er.code === 'EACCES')
6910+
return false;
6911+
throw er;
6912+
}
6913+
};
6914+
exports.sync = sync;
6915+
const checkStat = (stat, options) => stat.isFile() && checkMode(stat, options);
6916+
const checkMode = (stat, options) => {
6917+
const myUid = options.uid ?? process.getuid?.();
6918+
const myGroups = options.groups ?? process.getgroups?.() ?? [];
6919+
const myGid = options.gid ?? process.getgid?.() ?? myGroups[0];
6920+
if (myUid === undefined || myGid === undefined) {
6921+
throw new Error('cannot get uid or gid');
6922+
}
6923+
const groups = new Set([myGid, ...myGroups]);
6924+
const mod = stat.mode;
6925+
const uid = stat.uid;
6926+
const gid = stat.gid;
6927+
const u = parseInt('100', 8);
6928+
const g = parseInt('010', 8);
6929+
const o = parseInt('001', 8);
6930+
const ug = u | g;
6931+
return !!(mod & o ||
6932+
(mod & g && groups.has(gid)) ||
6933+
(mod & u && uid === myUid) ||
6934+
(mod & ug && myUid === 0));
6935+
};
6936+
//# sourceMappingURL=posix.js.map
6937+
6938+
/***/ }),
6939+
6940+
/***/ 7079:
6941+
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
6942+
6943+
"use strict";
6944+
6945+
/**
6946+
* This is the Windows implementation of isexe, which uses the file
6947+
* extension and PATHEXT setting.
6948+
*
6949+
* @module
6950+
*/
6951+
Object.defineProperty(exports, "__esModule", ({ value: true }));
6952+
exports.sync = exports.isexe = void 0;
6953+
const fs_1 = __nccwpck_require__(7147);
6954+
const promises_1 = __nccwpck_require__(3292);
6955+
/**
6956+
* Determine whether a path is executable based on the file extension
6957+
* and PATHEXT environment variable (or specified pathExt option)
6958+
*/
6959+
const isexe = async (path, options = {}) => {
6960+
const { ignoreErrors = false } = options;
6961+
try {
6962+
return checkStat(await (0, promises_1.stat)(path), path, options);
6963+
}
6964+
catch (e) {
6965+
const er = e;
6966+
if (ignoreErrors || er.code === 'EACCES')
6967+
return false;
6968+
throw er;
6969+
}
6970+
};
6971+
exports.isexe = isexe;
6972+
/**
6973+
* Synchronously determine whether a path is executable based on the file
6974+
* extension and PATHEXT environment variable (or specified pathExt option)
6975+
*/
6976+
const sync = (path, options = {}) => {
6977+
const { ignoreErrors = false } = options;
6978+
try {
6979+
return checkStat((0, fs_1.statSync)(path), path, options);
6980+
}
6981+
catch (e) {
6982+
const er = e;
6983+
if (ignoreErrors || er.code === 'EACCES')
6984+
return false;
6985+
throw er;
6986+
}
6987+
};
6988+
exports.sync = sync;
6989+
const checkPathExt = (path, options) => {
6990+
const { pathExt = process.env.PATHEXT || '' } = options;
6991+
const peSplit = pathExt.split(';');
6992+
if (peSplit.indexOf('') !== -1) {
6993+
return true;
6994+
}
6995+
for (let i = 0; i < peSplit.length; i++) {
6996+
const p = peSplit[i].toLowerCase();
6997+
const ext = path.substring(path.length - p.length).toLowerCase();
6998+
if (p && ext === p) {
6999+
return true;
7000+
}
7001+
}
7002+
return false;
7003+
};
7004+
const checkStat = (stat, path, options) => stat.isFile() && checkPathExt(path, options);
7005+
//# sourceMappingURL=win32.js.map
7006+
66757007
/***/ })
66767008

66777009
/******/ });
@@ -6787,10 +7119,17 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
67877119
function run() {
67887120
return __awaiter(this, void 0, void 0, function* () {
67897121
try {
6790-
yield _actions_core__WEBPACK_IMPORTED_MODULE_0__.group(`Prepare access to Namespace`, () => __awaiter(this, void 0, void 0, function* () {
6791-
yield installNsc();
6792-
yield _actions_exec__WEBPACK_IMPORTED_MODULE_2__.exec("nsc version");
6793-
}));
7122+
const which = __nccwpck_require__(6143);
7123+
const resolvedOrNull = yield which("nsc", { nothrow: true });
7124+
if (resolvedOrNull == null) {
7125+
yield _actions_core__WEBPACK_IMPORTED_MODULE_0__.group(`Prepare access to Namespace`, () => __awaiter(this, void 0, void 0, function* () {
7126+
yield installNsc();
7127+
}));
7128+
}
7129+
else {
7130+
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`Namespace Cloud CLI found.`);
7131+
}
7132+
yield _actions_exec__WEBPACK_IMPORTED_MODULE_2__.exec("nsc version");
67947133
const registry = yield _actions_core__WEBPACK_IMPORTED_MODULE_0__.group(`Log into Namespace workspace`, () => __awaiter(this, void 0, void 0, function* () {
67957134
yield ensureNscloudToken();
67967135
return yield dockerLogin();

main.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ import * as path from "path";
66

77
async function run(): Promise<void> {
88
try {
9-
await core.group(`Prepare access to Namespace`, async () => {
10-
await installNsc();
11-
await exec.exec("nsc version");
12-
});
9+
const which = require("which");
10+
11+
const resolvedOrNull = await which("nsc", { nothrow: true });
12+
if (resolvedOrNull == null) {
13+
await core.group(`Prepare access to Namespace`, async () => {
14+
await installNsc();
15+
});
16+
} else {
17+
core.info(`Namespace Cloud CLI found.`);
18+
}
19+
await exec.exec("nsc version");
1320

1421
const registry = await core.group(`Log into Namespace workspace`, async () => {
1522
await ensureNscloudToken();

0 commit comments

Comments
 (0)