From 93c7af6c910f7a0ff3aaface20dcc86cd40162cc Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Mon, 24 Oct 2022 21:23:14 +0200 Subject: [PATCH] feat(precheck): now includes a precheck for more generic runner execution --- ts/00_commitinfo_data.ts | 2 +- ts/mod_precheck/index.ts | 24 ++++++++++++++++++++++++ ts/mod_precheck/plugins.ts | 1 + ts/npmci.classes.npmcicli.ts | 9 +++++---- ts/npmci.classes.npmciconfig.ts | 4 ++++ 5 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 ts/mod_precheck/index.ts create mode 100644 ts/mod_precheck/plugins.ts diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 9f486ea..64f66f3 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@shipzone/npmci', - version: '4.0.11', + version: '4.1.0', description: 'node and docker in gitlab ci on steroids' } diff --git a/ts/mod_precheck/index.ts b/ts/mod_precheck/index.ts new file mode 100644 index 0000000..61ae8f8 --- /dev/null +++ b/ts/mod_precheck/index.ts @@ -0,0 +1,24 @@ +import * as plugins from './plugins.js'; +import * as paths from '../npmci.paths.js'; +import { logger } from '../npmci.logging.js'; +import { Npmci } from '../npmci.classes.npmci.js'; + +export const handleCli = async (npmciRefArg: Npmci, argvArg: any) => { + logger.log('info', 'checking execution context'); + const presentRunnerTags = process.env.CI_RUNNER_TAGS.split(',').map((stringArg) => + stringArg.trim() + ); + let allDesiredGitlabRunnerTagsPresent = true; + for (const desiredRunnerTag of npmciRefArg.npmciConfig.getConfig().gitlabRunnerTags) { + if (!presentRunnerTags.includes(desiredRunnerTag)) { + allDesiredGitlabRunnerTagsPresent = false; + logger.log( + 'error', + `Desired runnerRag ${desiredRunnerTag} is missing in current execution context.` + ); + } + } + if (!allDesiredGitlabRunnerTagsPresent) { + process.exit(1); + } +}; diff --git a/ts/mod_precheck/plugins.ts b/ts/mod_precheck/plugins.ts new file mode 100644 index 0000000..6314d05 --- /dev/null +++ b/ts/mod_precheck/plugins.ts @@ -0,0 +1 @@ +export * from '../npmci.plugins.js'; \ No newline at end of file diff --git a/ts/npmci.classes.npmcicli.ts b/ts/npmci.classes.npmcicli.ts index 1bec1c0..9b85a59 100644 --- a/ts/npmci.classes.npmcicli.ts +++ b/ts/npmci.classes.npmcicli.ts @@ -79,15 +79,16 @@ export class NpmciCli { } ); + this.smartcli.addCommand('precheck').subscribe(async (argvArg) => { + const modPrecheck = await import('./mod_precheck/index.js'); + await modPrecheck.handleCli(this.npmciRef, argvArg); + }) + // trigger this.smartcli.addCommand('ssh').subscribe( async (argvArg) => { const modSsh = await import('./mod_ssh/index.js'); await modSsh.handleCli(argvArg); - }, - (err) => { - console.log(err); - process.exit(1); } ); diff --git a/ts/npmci.classes.npmciconfig.ts b/ts/npmci.classes.npmciconfig.ts index ec20338..d28a5c1 100644 --- a/ts/npmci.classes.npmciconfig.ts +++ b/ts/npmci.classes.npmciconfig.ts @@ -20,6 +20,9 @@ export interface INpmciOptions { dockerRegistryRepoMap: { [key: string]: string }; dockerBuildargEnvMap: { [key: string]: string }; + // gitlab + gitlabRunnerTags: string[]; + // urls urlCloudly: string; } @@ -57,6 +60,7 @@ export class NpmciConfig { dockerRegistryRepoMap: {}, npmAccessLevel: 'private', npmRegistryUrl: 'registry.npmjs.org', + gitlabRunnerTags: [], dockerBuildargEnvMap: {}, urlCloudly: this.npmciQenv.getEnvVarOnDemand('NPMCI_URL_CLOUDLY'), };