hammerkit 2.1.0-next.4 → 2.1.0-next.6

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.
@@ -37,8 +37,9 @@ function buildEnvironmentVariables(envs, environment, context) {
37
37
  }
38
38
  else if (value.includes('${')) {
39
39
  const interpolated = interpolate(value, envs, environment, context, fromProcess);
40
- if (interpolated.missing) {
41
- replacements.push({ key, name: interpolated.missing, available: false, value: null });
40
+ if (interpolated.missing.length > 0) {
41
+ const [name] = interpolated.missing;
42
+ replacements.push({ key, name, available: false, value: null, missing: interpolated.missing });
42
43
  }
43
44
  else {
44
45
  variables[key] = interpolated.value;
@@ -53,13 +54,15 @@ function buildEnvironmentVariables(envs, environment, context) {
53
54
  exports.buildEnvironmentVariables = buildEnvironmentVariables;
54
55
  // Each `${NAME}` comes from the process environment or a .env file, else from a
55
56
  // literal value of the same build file / task `envs`, else from its
56
- // `:-default`. A reference without any of them is missing.
57
+ // `:-default`. A reference without any of them is missing; each is listed once.
57
58
  function interpolate(value, envs, environment, context, fromProcess) {
58
- let missing = null;
59
+ const missing = [];
59
60
  const result = value.replace(INTERPOLATION, (match, name, fallback) => {
60
61
  const resolved = resolveReference(name, environment, context, fromProcess) ?? getLiteral(envs, name) ?? fallback ?? null;
61
62
  if (resolved === null) {
62
- missing = missing ?? name;
63
+ if (!missing.includes(name)) {
64
+ missing.push(name);
65
+ }
63
66
  return match;
64
67
  }
65
68
  return resolved;
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isRunSourceEnv = exports.RUN_SOURCE_ENVS = void 0;
4
4
  // The variables a server sets for the process of a run, from what the run is from (see
5
5
  // src/server/run-source-environment.ts). Nothing else sets them: the operator's `runs.env`
6
- // can't name them, and a run that isn't from that source has none of them.
6
+ // can't name them, and a run that isn't from that source has none of them. `validate` reads
7
+ // this list too, so an env that reads one of them isn't a variable set nowhere.
7
8
  exports.RUN_SOURCE_ENVS = [
8
9
  'HAMMERKIT_RUN_REPO',
9
10
  'HAMMERKIT_RUN_REF',
@@ -2,13 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isDependencyOutput = void 0;
4
4
  const path_1 = require("path");
5
- // Whether a path is, or is inside, a folder a dependency of the task generates. The task sees
6
- // what the dependency made there: a src at such a path stays a src of the task (its id and its
7
- // cache key are as they were), but isn't bound or mounted over the output, as docker would bind
8
- // the host's folder (empty where the dependency ran in a container) and a pod would mount the
9
- // same path twice. A `build` whose context a dependency writes reads it so.
5
+ // Whether a path is a file a dependency of the task generates, or is, or is inside, a folder
6
+ // one generates. The task sees what the dependency made there: a src at such a path stays a
7
+ // src of the task (its id and its cache key are as they were), but isn't bound or mounted over
8
+ // the output, as docker would bind the host's folder (empty where the dependency ran in a
9
+ // container) and a pod would mount the same path twice. A `build` whose context a dependency
10
+ // writes reads it so, and a deploy that lists the digest file of its image in its src.
10
11
  function isDependencyOutput(task, path) {
11
- return task.generates.some((generate) => generate.inherited && !generate.isFile && (generate.path === path || isInside(generate.path, path)));
12
+ return task.generates.some((generate) => generate.inherited && (generate.path === path || (!generate.isFile && isInside(generate.path, path))));
12
13
  }
13
14
  exports.isDependencyOutput = isDependencyOutput;
14
15
  function isInside(folder, path) {
@@ -5,6 +5,8 @@ const read_build_file_1 = require("../parser/read-build-file");
5
5
  const plan_work_tasks_1 = require("./utils/plan-work-tasks");
6
6
  const unreferenced_build_file_envs_1 = require("./unreferenced-build-file-envs");
7
7
  const normalize_path_1 = require("./utils/normalize-path");
8
+ const dependency_outputs_1 = require("./utils/dependency-outputs");
9
+ const run_source_envs_1 = require("../environment/run-source-envs");
8
10
  async function* validate(workTree, context) {
9
11
  const cycleItems = [];
10
12
  for (const item of (0, plan_work_tasks_1.iterateWorkServices)(workTree)) {
@@ -76,6 +78,10 @@ async function* validate(workTree, context) {
76
78
  }
77
79
  }
78
80
  for (const src of task.src) {
81
+ // a dependency writes it when it runs: the digest of an image a deploy lists in its src
82
+ if ((0, dependency_outputs_1.isDependencyOutput)(task, src.absolutePath)) {
83
+ continue;
84
+ }
79
85
  if (!(await context.file.exists(src.absolutePath))) {
80
86
  yield {
81
87
  type: 'warn',
@@ -106,13 +112,22 @@ async function* validate(workTree, context) {
106
112
  }
107
113
  exports.validate = validate;
108
114
  // An env that reads a variable set nowhere, such as an input of an included file run on its
109
- // own: the task fails when it starts, and until then `$NAME` stays in what it templates
115
+ // own: the task fails when it starts, and until then `$NAME` stays in what it templates. Each
116
+ // variable a value reads counts, `${A}-${B}` both. The variables of what a run is from
117
+ // (`$HAMMERKIT_RUN_REF`) are not of them: a server sets them when it runs the task
118
+ // (RUN_SOURCE_ENVS).
110
119
  function* warnUnsetEnvs(envs, item) {
111
120
  for (const replacement of envs.replacements) {
112
- if (!replacement.available) {
121
+ if (replacement.available) {
122
+ continue;
123
+ }
124
+ for (const name of replacement.missing ?? [replacement.name]) {
125
+ if ((0, run_source_envs_1.isRunSourceEnv)(name)) {
126
+ continue;
127
+ }
113
128
  yield {
114
129
  type: 'warn',
115
- message: `env ${replacement.key} reads $${replacement.name}, which neither the environment nor a .env file sets: ` +
130
+ message: `env ${replacement.key} reads $${name}, which neither the environment nor a .env file sets: ` +
116
131
  `it can't start, and $${replacement.key} stays as it is written in its build file`,
117
132
  item,
118
133
  };
@@ -9,7 +9,7 @@ const COMMIT = /^[0-9a-f]{40}([0-9a-f]{24})?$/i;
9
9
  // repository, and the branch or tag and the commit it was pinned to, or the repository and the
10
10
  // sandbox. None of them is a credential, so a task that reads them still takes arguments and
11
11
  // keeps its network (see PLAIN_SERVER_ENVS). A sandbox has no commit: its files may hold
12
- // changes. A run from an upload has none of them.
12
+ // changes. A run from an upload has none of them. Each is a name of RUN_SOURCE_ENVS.
13
13
  function runSourceEnvironment(source) {
14
14
  if (source.type === 'ref') {
15
15
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hammerkit",
3
3
  "description": "Containerized build tool with incremental caching that runs the same build file locally, in Docker and on Kubernetes.",
4
- "version": "2.1.0-next.4",
4
+ "version": "2.1.0-next.6",
5
5
  "keywords": [
6
6
  "build",
7
7
  "build-tool",