diff --git a/README.md b/README.md index 6532f662f..438f861f8 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ TODO: Fill this ## Quirks ### Artifacts -Artifacts works right now, as along as you don't overwirte git tracked files and as long as you don't use dependencies tag. +Artifacts works right now, as along as you don't overwrite tracked files and as long as you don't use dependencies tag. # Development ## Scripts @@ -75,6 +75,7 @@ Artifacts works right now, as along as you don't overwirte git tracked files and $ npm run build-linux $ npm run build-win $ npm run build-macos + $ npm run build-all # TODO @@ -82,17 +83,15 @@ Artifacts works right now, as along as you don't overwirte git tracked files and - include:local isn't recursive ## Features -- Execute single job `gitlab-local-pipeline ts-lint` - Verbosity on .gitlab-ci.local.yml overrides and appends. ## Unsupported tags, will be implemented in order - needs (directed acyclic graph) - rules +- when:always - when:on_failure - when:delayed - start_in (Used only with when:delayed) -- when:always -- when:never - include:file - include:template - include:remote diff --git a/package.json b/package.json index ed951ef60..9daac4493 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "lint": "tslint --project .", "lint-fix": "tslint --fix --project .", "ncu": "ncu --semverLevel major -e 2", - "test-yml-spec": "node -r source-map-support/register dist/index.js -m manual_job_invoked_from_cli --cwd tests/test-yml-spec" + "test-yml-spec": "node -r source-map-support/register dist/index.js manual manual_job_invoked_from_cli --cwd tests/test-yml-spec", + "test-exec-never-job": "node -r source-map-support/register dist/index.js exec never_job --cwd tests/test-yml-spec" }, "bin": "dist/index.js", "dependencies": { diff --git a/src/index.ts b/src/index.ts index 2ad4b49bb..47f0710df 100644 --- a/src/index.ts +++ b/src/index.ts @@ -49,6 +49,14 @@ const cwd = argv.cwd || process.cwd(); const m: any = argv.m; const manualArgs: string[] = [].concat(m || []); +const firstArg = argv._[0] ?? "pipeline"; + +if (firstArg === "manual") { + for (let i = 1; i < argv._.length; i += 1) { + manualArgs.push(argv._[i]); + } +} + const parser = new Parser(cwd, logger); const runJobs = async () => { @@ -67,9 +75,15 @@ const runJobs = async () => { console.log(`=> ${c.yellow(`${stageName}`)} > ${c.blueBright(`${jobNames}`)} ${c.magentaBright("starting")}...`); for (const job of jobs) { if (job.isManual() && !manualArgs.includes(job.name)) { - console.log(`${c.blueBright(`${job.name}`)} skipped. Manual job`); + console.log(`${c.blueBright(`${job.name}`)} skipped. when:manual`); continue; } + + if (job.isNever()) { + console.log(`${c.blueBright(`${job.name}`)} skipped. when:never`); + continue; + } + const jobPromise = job.start(); promises.push(jobPromise); } @@ -86,9 +100,38 @@ const runJobs = async () => { } }; +const runExecJobs = async () => { + const promises: Array> = []; + for (let i = 1; i < argv._.length; i += 1) { + const jobName = argv._[i]; + const job = parser.getJobs().get(argv._[i]); + if (!job) { + console.error(`${c.blueBright(`${jobName}`)} ${c.red(" could not be found")}`); + process.exit(1); + } + + const jobPromise = job.start(); + promises.push(jobPromise); + } + + try { + await Promise.all(promises); + console.log(""); + } catch (e) { + if (e !== "") { + console.error(e); + } + process.exit(1); + } +}; + process.on("uncaughtException", (err) => { // Handle the error safely console.log(err); }); -runJobs().catch(); +if (["pipeline", "manual"].includes(firstArg)) { + runJobs().catch(); +} else if (firstArg === "exec") { + runExecJobs().catch(); +} diff --git a/src/job.ts b/src/job.ts index 8839389f1..97f6bf566 100644 --- a/src/job.ts +++ b/src/job.ts @@ -70,6 +70,10 @@ export class Job { return this.when === "manual"; } + public isNever(): boolean { + return this.when === "never"; + } + public async start(): Promise { this.running = true; diff --git a/tests/test-yml-spec/.gitlab-ci.local.yml b/tests/test-yml-spec/.gitlab-ci.local.yml index 932b9b617..d4255e8fa 100644 --- a/tests/test-yml-spec/.gitlab-ci.local.yml +++ b/tests/test-yml-spec/.gitlab-ci.local.yml @@ -7,3 +7,9 @@ project_context: local_only_job: stage: build script: echo "I only get run locally '${LOCAL_ONLY}'" + +never_job: + when: never + stage: startup + script: + - echo "I'm when:never i could have only been called by 'gitlab-local-pipeline exec never_job'" diff --git a/tests/test-yml-spec/.gitlab-ci.yml b/tests/test-yml-spec/.gitlab-ci.yml index 5f8bc40b2..07863f3b2 100644 --- a/tests/test-yml-spec/.gitlab-ci.yml +++ b/tests/test-yml-spec/.gitlab-ci.yml @@ -76,4 +76,4 @@ manual_job_invoked_from_cli: when: manual stage: last script: - - echo "I was invoked manually, because 'gitlab-local-pipeline manual_job_invoked_from_cli' was called" + - echo "I was invoked manually, because 'gitlab-local-pipeline manual manual_job_invoked_from_cli' was called"