Skip to content

Commit ed49abb

Browse files
committed
Implemented exec and manual "command" arguments
1 parent 05c23cc commit ed49abb

File tree

6 files changed

+61
-8
lines changed

6 files changed

+61
-8
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ TODO: Fill this
6161

6262
## Quirks
6363
### Artifacts
64-
Artifacts works right now, as along as you don't overwirte git tracked files and as long as you don't use dependencies tag.
64+
Artifacts works right now, as along as you don't overwrite tracked files and as long as you don't use dependencies tag.
6565

6666
# Development
6767
## Scripts
@@ -75,24 +75,23 @@ Artifacts works right now, as along as you don't overwirte git tracked files and
7575
$ npm run build-linux
7676
$ npm run build-win
7777
$ npm run build-macos
78+
$ npm run build-all
7879

7980
# TODO
8081

8182
## Known Bugs
8283
- include:local isn't recursive
8384

8485
## Features
85-
- Execute single job `gitlab-local-pipeline ts-lint`
8686
- Verbosity on .gitlab-ci.local.yml overrides and appends.
8787

8888
## Unsupported tags, will be implemented in order
8989
- needs (directed acyclic graph)
9090
- rules
91+
- when:always
9192
- when:on_failure
9293
- when:delayed
9394
- start_in (Used only with when:delayed)
94-
- when:always
95-
- when:never
9695
- include:file
9796
- include:template
9897
- include:remote

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"lint": "tslint --project .",
1212
"lint-fix": "tslint --fix --project .",
1313
"ncu": "ncu --semverLevel major -e 2",
14-
"test-yml-spec": "node -r source-map-support/register dist/index.js -m manual_job_invoked_from_cli --cwd tests/test-yml-spec"
14+
"test-yml-spec": "node -r source-map-support/register dist/index.js manual manual_job_invoked_from_cli --cwd tests/test-yml-spec",
15+
"test-exec-never-job": "node -r source-map-support/register dist/index.js exec never_job --cwd tests/test-yml-spec"
1516
},
1617
"bin": "dist/index.js",
1718
"dependencies": {

src/index.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ const cwd = argv.cwd || process.cwd();
4949
const m: any = argv.m;
5050
const manualArgs: string[] = [].concat(m || []);
5151

52+
const firstArg = argv._[0] ?? "pipeline";
53+
54+
if (firstArg === "manual") {
55+
for (let i = 1; i < argv._.length; i += 1) {
56+
manualArgs.push(argv._[i]);
57+
}
58+
}
59+
5260
const parser = new Parser(cwd, logger);
5361

5462
const runJobs = async () => {
@@ -67,9 +75,15 @@ const runJobs = async () => {
6775
console.log(`=> ${c.yellow(`${stageName}`)} > ${c.blueBright(`${jobNames}`)} ${c.magentaBright("starting")}...`);
6876
for (const job of jobs) {
6977
if (job.isManual() && !manualArgs.includes(job.name)) {
70-
console.log(`${c.blueBright(`${job.name}`)} skipped. Manual job`);
78+
console.log(`${c.blueBright(`${job.name}`)} skipped. when:manual`);
7179
continue;
7280
}
81+
82+
if (job.isNever()) {
83+
console.log(`${c.blueBright(`${job.name}`)} skipped. when:never`);
84+
continue;
85+
}
86+
7387
const jobPromise = job.start();
7488
promises.push(jobPromise);
7589
}
@@ -86,9 +100,38 @@ const runJobs = async () => {
86100
}
87101
};
88102

103+
const runExecJobs = async () => {
104+
const promises: Array<Promise<any>> = [];
105+
for (let i = 1; i < argv._.length; i += 1) {
106+
const jobName = argv._[i];
107+
const job = parser.getJobs().get(argv._[i]);
108+
if (!job) {
109+
console.error(`${c.blueBright(`${jobName}`)} ${c.red(" could not be found")}`);
110+
process.exit(1);
111+
}
112+
113+
const jobPromise = job.start();
114+
promises.push(jobPromise);
115+
}
116+
117+
try {
118+
await Promise.all(promises);
119+
console.log("");
120+
} catch (e) {
121+
if (e !== "") {
122+
console.error(e);
123+
}
124+
process.exit(1);
125+
}
126+
};
127+
89128
process.on("uncaughtException", (err) => {
90129
// Handle the error safely
91130
console.log(err);
92131
});
93132

94-
runJobs().catch();
133+
if (["pipeline", "manual"].includes(firstArg)) {
134+
runJobs().catch();
135+
} else if (firstArg === "exec") {
136+
runExecJobs().catch();
137+
}

src/job.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export class Job {
7070
return this.when === "manual";
7171
}
7272

73+
public isNever(): boolean {
74+
return this.when === "never";
75+
}
76+
7377
public async start(): Promise<void> {
7478
this.running = true;
7579

tests/test-yml-spec/.gitlab-ci.local.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ project_context:
77
local_only_job:
88
stage: build
99
script: echo "I only get run locally '${LOCAL_ONLY}'"
10+
11+
never_job:
12+
when: never
13+
stage: startup
14+
script:
15+
- echo "I'm when:never i could have only been called by 'gitlab-local-pipeline exec never_job'"

tests/test-yml-spec/.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ manual_job_invoked_from_cli:
7676
when: manual
7777
stage: last
7878
script:
79-
- echo "I was invoked manually, because 'gitlab-local-pipeline manual_job_invoked_from_cli' was called"
79+
- echo "I was invoked manually, because 'gitlab-local-pipeline manual manual_job_invoked_from_cli' was called"

0 commit comments

Comments
 (0)