hammerkit 1.17.0 → 1.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js
CHANGED
|
@@ -16,6 +16,7 @@ const reset_work_tree_1 = require("./executer/reset-work-tree");
|
|
|
16
16
|
const execute_work_tree_1 = require("./executer/execute-work-tree");
|
|
17
17
|
const package_1 = require("./docker/package");
|
|
18
18
|
const explain_1 = require("./cache/explain");
|
|
19
|
+
const describe_task_1 = require("./planner/describe-task");
|
|
19
20
|
const work_graph_serializer_1 = require("./planner/work-graph-serializer");
|
|
20
21
|
const dry_run_1 = require("./executer/dry-run");
|
|
21
22
|
const cache_sync_1 = require("./cache/cache-sync");
|
|
@@ -127,6 +128,9 @@ class Cli {
|
|
|
127
128
|
}
|
|
128
129
|
// Read-only cache prediction for every task in scope: executes no command,
|
|
129
130
|
// starts no container/service, performs no cache push/pull.
|
|
131
|
+
explainDefinition() {
|
|
132
|
+
return [...(0, plan_work_tasks_1.iterateWorkTasks)(this.workTree)].map((task) => (0, describe_task_1.describeTask)(task, this.environment.cwd));
|
|
133
|
+
}
|
|
130
134
|
async explain(options) {
|
|
131
135
|
return (0, explain_1.explainWorkTree)(this.workTree, options?.cacheDefault ?? 'checksum', this.environment);
|
|
132
136
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.describeTask = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const work_task_1 = require("./work-task");
|
|
6
|
+
const toPosix = (value) => (path_1.sep === path_1.posix.sep ? value : value.split(path_1.sep).join(path_1.posix.sep));
|
|
7
|
+
function describeTask(item, cwd) {
|
|
8
|
+
const task = item.data;
|
|
9
|
+
const remote = task.scope.remote;
|
|
10
|
+
return {
|
|
11
|
+
name: item.name,
|
|
12
|
+
type: (0, work_task_1.isContainerWorkTask)(task) ? 'container' : 'local',
|
|
13
|
+
description: task.description || null,
|
|
14
|
+
source: {
|
|
15
|
+
file: toPosix(remote ? (0, path_1.relative)(remote.root, task.scope.fileName) : (0, path_1.relative)(cwd, task.scope.fileName)),
|
|
16
|
+
includedAs: task.scope.namePrefix,
|
|
17
|
+
git: remote?.git ?? null,
|
|
18
|
+
ref: remote?.ref ?? null,
|
|
19
|
+
commit: remote?.commit ?? null,
|
|
20
|
+
},
|
|
21
|
+
image: (0, work_task_1.isContainerWorkTask)(task) ? task.image : null,
|
|
22
|
+
shell: task.shell,
|
|
23
|
+
cmds: task.cmds.map((cmd) => cmd.cmd),
|
|
24
|
+
src: task.src.map((src) => src.source),
|
|
25
|
+
generates: task.generates.map((generate) => (0, path_1.relative)(task.cwd, generate.path)),
|
|
26
|
+
deps: item.deps.map((dep) => dep.name),
|
|
27
|
+
needs: item.needs.map((need) => need.name),
|
|
28
|
+
mounts: (0, work_task_1.isContainerWorkTask)(task) ? task.mounts.map((mount) => mount.mount) : [],
|
|
29
|
+
envs: Object.entries(task.envs.variables).map(([name, value]) => ({
|
|
30
|
+
name,
|
|
31
|
+
value,
|
|
32
|
+
origin: task.envOrigins[name] ?? 'task',
|
|
33
|
+
})),
|
|
34
|
+
envReferences: task.envs.replacements.map((replacement) => ({
|
|
35
|
+
name: replacement.key,
|
|
36
|
+
from: replacement.name,
|
|
37
|
+
available: replacement.available,
|
|
38
|
+
})),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
exports.describeTask = describeTask;
|
|
42
|
+
//# sourceMappingURL=describe-task.js.map
|
|
@@ -56,6 +56,7 @@ function parseTask(cwd, task, environment, context) {
|
|
|
56
56
|
const envs = (0, replace_env_variables_1.buildEnvironmentVariables)(task.envs, environment, context);
|
|
57
57
|
const baseWorkNode = {
|
|
58
58
|
envs,
|
|
59
|
+
envOrigins: getEnvOrigins(task),
|
|
59
60
|
description: (0, template_value_1.templateValue)(task.schema.description || '', envs).trim(),
|
|
60
61
|
name: task.relativeName,
|
|
61
62
|
cwd,
|
|
@@ -92,4 +93,22 @@ function parseTask(cwd, task, environment, context) {
|
|
|
92
93
|
};
|
|
93
94
|
}
|
|
94
95
|
}
|
|
96
|
+
function getEnvOrigins(task) {
|
|
97
|
+
const origins = {};
|
|
98
|
+
for (const key of Object.keys(task.envs)) {
|
|
99
|
+
if (key in (task.schema.envs ?? {})) {
|
|
100
|
+
origins[key] = 'task';
|
|
101
|
+
}
|
|
102
|
+
else if (key in (task.scope.inputs ?? {}) && key in (task.scope.schema.envs ?? {})) {
|
|
103
|
+
origins[key] = 'input';
|
|
104
|
+
}
|
|
105
|
+
else if (key in (task.scope.schema.envs ?? {})) {
|
|
106
|
+
origins[key] = 'build-file';
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
origins[key] = 'extend';
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return origins;
|
|
113
|
+
}
|
|
95
114
|
//# sourceMappingURL=append-work-task.js.map
|
package/dist/program.js
CHANGED
|
@@ -32,6 +32,51 @@ async function createCli(fileName, environment, workScope) {
|
|
|
32
32
|
return (0, cli_1.getCli)(workTree, environment);
|
|
33
33
|
}
|
|
34
34
|
exports.createCli = createCli;
|
|
35
|
+
const ENV_ORIGINS = {
|
|
36
|
+
task: () => 'task',
|
|
37
|
+
input: (includedAs) => `input of include ${includedAs}`,
|
|
38
|
+
'build-file': () => 'build file',
|
|
39
|
+
extend: () => 'extended task',
|
|
40
|
+
};
|
|
41
|
+
function printTaskDefinition(environment, definition) {
|
|
42
|
+
environment.stdout.write(`• ${definition.name}\n`);
|
|
43
|
+
const source = definition.source;
|
|
44
|
+
if (source.git) {
|
|
45
|
+
(0, log_1.printProperty)(environment, 'defined in', `${source.file} of ${source.git} at ${source.ref ?? 'HEAD'} (commit ${(source.commit ?? '').slice(0, 12)})`);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
(0, log_1.printProperty)(environment, 'defined in', source.file);
|
|
49
|
+
}
|
|
50
|
+
if (source.includedAs) {
|
|
51
|
+
(0, log_1.printProperty)(environment, 'included as', source.includedAs);
|
|
52
|
+
}
|
|
53
|
+
if (definition.description) {
|
|
54
|
+
(0, log_1.printProperty)(environment, 'description', definition.description);
|
|
55
|
+
}
|
|
56
|
+
if (definition.image) {
|
|
57
|
+
(0, log_1.printProperty)(environment, 'image', definition.image);
|
|
58
|
+
}
|
|
59
|
+
for (const [name, values] of [
|
|
60
|
+
['deps', definition.deps],
|
|
61
|
+
['needs', definition.needs],
|
|
62
|
+
['src', definition.src],
|
|
63
|
+
['generates', definition.generates],
|
|
64
|
+
['mounts', definition.mounts],
|
|
65
|
+
]) {
|
|
66
|
+
if (values.length > 0) {
|
|
67
|
+
(0, log_1.printProperty)(environment, name, values.join(', '));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
for (const cmd of definition.cmds) {
|
|
71
|
+
(0, log_1.printProperty)(environment, 'cmd', cmd);
|
|
72
|
+
}
|
|
73
|
+
for (const env of definition.envs) {
|
|
74
|
+
(0, log_1.printProperty)(environment, `env ${env.name}`, `${env.value} ${colors_1.default.grey(`(${ENV_ORIGINS[env.origin](source.includedAs)})`)}`);
|
|
75
|
+
}
|
|
76
|
+
for (const reference of definition.envReferences) {
|
|
77
|
+
(0, log_1.printProperty)(environment, `env ${reference.name}`, `from $${reference.from} ${colors_1.default.grey(reference.available ? '(set)' : '(not set)')}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
35
80
|
function parseWorkLabelScope(options) {
|
|
36
81
|
const scope = {
|
|
37
82
|
environmentName: null,
|
|
@@ -278,9 +323,22 @@ async function getProgram(environment, argv) {
|
|
|
278
323
|
.choices(['checksum', 'modify-date', 'none']))
|
|
279
324
|
.addOption(new commander_1.Option('--json', 'emit the explanation as JSON').default(false))
|
|
280
325
|
.addOption(new commander_1.Option('--check', 'exit with code 1 when any task would be a cache miss').default(false))
|
|
326
|
+
.addOption(new commander_1.Option('--definition', 'show the resolved definition of the tasks and where it came from instead').default(false))
|
|
281
327
|
.action(async (task, options) => {
|
|
282
328
|
try {
|
|
283
329
|
const cli = await createCli(fileName, environment, task ? { taskName: task, environmentName: options.env ?? null } : parseWorkLabelScope(options));
|
|
330
|
+
if (options.definition) {
|
|
331
|
+
const definitions = cli.explainDefinition();
|
|
332
|
+
if (options.json) {
|
|
333
|
+
environment.stdout.write(`${JSON.stringify(definitions, null, 2)}\n`);
|
|
334
|
+
}
|
|
335
|
+
else {
|
|
336
|
+
for (const definition of definitions) {
|
|
337
|
+
printTaskDefinition(environment, definition);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
284
342
|
const explanations = await cli.explain({ cacheDefault: options.cache });
|
|
285
343
|
const missed = explanations.filter((explanation) => explanation.status === 'miss');
|
|
286
344
|
if (options.json) {
|
|
@@ -33,6 +33,7 @@ async function appendBuildFile(cwd, ctx, environment, fileName, namePrefix, remo
|
|
|
33
33
|
schema: inputs ? applyInputs(result.data, inputs, namePrefix, fileName) : result.data,
|
|
34
34
|
namePrefix: relativeName,
|
|
35
35
|
remote,
|
|
36
|
+
inputs,
|
|
36
37
|
references: {},
|
|
37
38
|
};
|
|
38
39
|
ctx.files[key] = scope;
|
package/package.json
CHANGED