You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b16d0e7
Browse filesBrowse the repository at this point in the historyBrowse files
feat(ci): fail the publish phase when the ordered alias is missing (#89)
- The publish phase of container-image-metadata now fails its job
unless the registry read-back finds the ordered release alias at the
built digest. A missing ordered tag fails there as well.
- With a bot token it attempts one Slack alert that cannot change the
outcome. Caller values in the message are escaped.
- Registry client output for an unconfirmed alias is logged where it
cannot issue workflow commands, and a failed history fetch falls
back to one full fetch.
Ordered release aliases require two invocations of the action. The first invocation computes the ordered tag before the image build. The second invocation publishes that tag after the build returns its digest.
34
+
Ordered release aliases require two invocations of the action. The first invocation computes the ordered tag before the image build (the generate phase). The second invocation, with `publish-ordered-release-tag: "true"`, writes that tag as an alias of the built digest and reads it back from the registry (the publish phase).
35
35
36
36
Ordered tag generation and publication need:
37
37
38
-
- A `push` or `workflow_dispatch` event on the repository's default branch. The ref must match the default branch exactly, letter case included. On any other event or ref, schedules included, generation and publication are skipped: `ordered-release-tag` is empty and no alias is published. The standard tags, labels and annotations are still produced.
39
-
- A checkout of the triggering revision (`GITHUB_SHA`) before the action. If another revision is checked out, no ordered tag is generated.
38
+
- A `push` or `workflow_dispatch` event on the repository's default branch. On any other event or ref, schedules included, both phases are skipped: `ordered-release-tag`is empty, no alias is published and neither phase fails. The standard tags, labels and annotations are still produced. The ref must also match the default branch exactly, letter case included: a ref that differs from it only in letter case passes the step conditions, so generation is skipped with a warning and the publish phase fails.
39
+
- A checkout of the triggering revision (`GITHUB_SHA`) before each invocation. If another revision is checked out, no ordered tag is generated.
40
40
- A runner whose `timeout` supports `--kill-after`, as GNU coreutils and uutils coreutils on Ubuntu GitHub-hosted runners do.
41
+
- `jq`and `curl` on `PATH` for the publish phase's alert, as on Ubuntu GitHub-hosted runners.
41
42
42
-
Today a failure in generation or publication does not fail the job. Generation logs a warning and leaves `ordered-release-tag` empty. Publication reports a warning or an error annotation. Read the second invocation's `ordered-release-result` output (`steps.alias.outputs.ordered-release-result` in the example) for the outcome: `present-at-expected-digest`, `absent`, `integrity-mismatch` or `unknown`. It is empty when publication did not run, for example because no ordered tag was generated. When an ordered tag is passed, invalid publication inputs do fail the job: an `images` value that is not exactly one repository in registry/name form, a malformed tag, a missing or malformed digest, or a tag that does not match the revision.
43
+
### What fails and what only warns
44
+
45
+
The generate phase never fails for the ordered tag, so the build it runs in finishes. When no tag can be made, it writes the warning `Skipping ordered release tag because <reason>` and leaves `ordered-release-tag` empty. On a shallow checkout it fetches the history treeless (`--filter=tree:0`). When that fetch fails, it writes a warning, removes the `remote.origin.promisor` and `remote.origin.partialclonefilter` settings the failed fetch left, and fetches the full history once without the filter. The tag is skipped only when that fetch fails too.
46
+
47
+
The publish phase fails unless the registry read-back finds the alias at the built digest. Its last step, `Check ordered release alias`, is the only step of the phase that fails. It writes the notice `Ordered image alias present` when the alias is confirmed, and otherwise the error `Ordered image alias not confirmed` with the result or reason, then fails. Every run of that step logs whether an alert token was supplied. When the runner's `timeout` lacks `--kill-after`, publication writes the error `Ordered image alias read-back unavailable` and the result is `unknown`.
48
+
49
+
Publish inputs are validated before anything is written. When validation fails, the phase writes the warning `Skipping ordered image alias publication because <reason>`, writes nothing to the registry, and the last step fails with that reason. Validation fails for a ref that is not exactly the default branch, an `images` value that is not exactly one repository in registry/name form, a malformed tag, a missing or malformed digest, or a tag whose six-character suffix is not the start of `GITHUB_SHA`. The action does not read the commit from the image: it compares the suffix with the `GITHUB_SHA` of the publishing run, so publish in the same workflow run as the build. An empty ordered tag skips publication the same way and is reported as `tag-unavailable`.
50
+
51
+
The commit metadata and `Docker meta` steps run in both invocations and fail their step on error. When one of them fails, the job is already failed and the last step does not run, so no alert is sent. Nothing runs after a cancelled step either.
52
+
53
+
### Attempts
54
+
55
+
An attempt starts with a probe: it reads the alias up to twice and, only when neither read succeeds, reads the built digest. When the alias was not read and the built digest was, the probe calls it `absent`, and only then does the attempt write the alias and read it back the same way. `absent` is an inference from two failed reads, not a confirmed absence: the write goes ahead whatever the registry holds under that tag, so an existing alias that could not be read may be overwritten. What is guaranteed is that a mismatch the action observes, at either attempt's probe or read-back, ends the phase as `integrity-mismatch` with no further write. A probe that can read neither ends the attempt `unknown` without writing. A read-back that can read neither after the write also ends the attempt `unknown`, so an `unknown` attempt may have written.
56
+
57
+
When the first attempt ends `absent` or `unknown`, the phase waits five seconds and makes a second attempt, which probes again before it writes. The second attempt's result is the phase's result, and the log names the attempt that gave it. When the phase ends without a confirmed alias, the log also carries the registry client's output and exit status from the last failed read and the last write, inside a block that cannot issue workflow commands. A read whose client exited 0 with output that is not a digest is labelled an output-format failure. An exit status of 124 or 137 means the time limit stopped the client.
58
+
59
+
Two things are visible to a caller: the `ordered-release-result` output of the publish invocation (`steps.alias.outputs.ordered-release-result` in the example), and the result the last step reports in its annotation and alert. They differ when the output is empty, and when a cancellation keeps the last step from running; the table rows with a non-empty output assume the last step runs. The output is set only by the publication script, and it is empty in four cases:
60
+
- Outside the event and ref gate, the publish phase's own steps (validation, publication and the last step) do not run, so the publish phase cannot fail. The commit metadata and `Docker meta` steps still run, as in every invocation.
61
+
- When validation skips publication (no ordered tag, or a failed check), the last step reports `tag-unavailable` or the reason and fails.
62
+
- When the publication script fails before it sets the output, the last step reports `unknown` and fails. A caller that branches on the output cannot tell this case from a validation skip by the output alone; the last step's annotation names the result it reported.
63
+
- When an earlier step of the publish invocation fails, publication and the last step do not run and no alert is sent. When the job is cancelled before or during publication, the last step does not run and no alert is sent; a cancellation during publication may leave the alias written.
64
+
65
+
A cancellation keeps a last step that has not started from starting, whatever the output already holds. A last step that was already running when the cancellation arrived may have written its error annotation, which it writes before the post, and may have started its post, which may still reach Slack. Nothing already done is undone: an alias that publication wrote stays written.
66
+
67
+
| `ordered-release-result` output | Result the last step reports | What the publish phase did | Last step | Message |
68
+
|---|---|---|---|---|
69
+
| `present-at-expected-digest` | `present-at-expected-digest` | Found the alias at the built digest, already there or written and read back. | Passes. | None. |
70
+
| `absent` | `absent` | In the last attempt, the read-back after the write could not read the alias while the built digest could be read. | Fails. | Kargo creates no Freight for this build, so deploys stay on the previous build. Re-running the failed job retries. |
71
+
| `unknown` | `unknown` | In the last attempt, the probe or the read-back after a write could read neither the alias nor the built digest; or no `timeout` with `--kill-after` was found. | Fails. | The alias could not be verified at the expected digest, so whether Kargo creates Freight for this build is uncertain. Re-running the failed job retries. |
72
+
| `integrity-mismatch` | `integrity-mismatch` | Found the alias at another digest in a probe or a read-back and ended the phase with no further write. | Fails. | The same consequence as `unknown`. A re-run cannot clear it. |
73
+
| empty | `tag-unavailable` or the validation reason | Validation skipped publication; nothing was written. | Fails. | Kargo creates no Freight for this build, so deploys stay on the previous build. Re-run all jobs: the failed job alone reuses the build's empty value. |
74
+
| empty | `unknown` | The publication script failed before setting the output; it may have written before it failed. | Fails. | The same as `unknown` above. |
75
+
| empty | None: the last step does not run. | Outside the gate, validation, publication and the last step did not run; after an earlier failed step, publication did not run; after a cancellation before or during publication, publication may have written the alias. | Does not run. | None. |
76
+
77
+
### Alert
78
+
79
+
When the last step is about to fail and `alert-slack-bot-token` is set, the action attempts one post with Slack's `chat.postMessage` to `alert-slack-channel` (default `C0B11J29GP9`). The bot must be a member of that channel. The message names the repository, the image repository, the ordered tag or `none`, the result or validation reason, the short commit and the run link, followed by the two sentences in the table above. The alert escapes `&`, `<` and `>` in the supplied image repository and ordered tag, which prevents angle-bracket mentions and labelled links. Slack can still format the rest of those values, such as asterisks, underscores, tildes and backticks, and can still link a bare URL.
80
+
81
+
An attempted post is not always an accepted one. The log says `Alert sent to Slack` only when Slack's reply is exactly one JSON object whose `ok` is the boolean `true`. Otherwise the step writes the warning `Ordered image alias alert not sent`, in these cases:
82
+
- the message could not be built;
83
+
- curl failed or passed its 10-second limit;
84
+
- the reply was anything else, in which case the warning names Slack's error code, such as `not_in_channel`, when there is one.
85
+
86
+
None of these changes the outcome: the step still fails for the alias. Without a token nothing is posted and the step still fails.
87
+
88
+
### Time budget
89
+
90
+
The figures below are totals of the timed operations, not a limit on the phase. The action has no phase timer, and other commands add a little. Set each job's `timeout-minutes` above them.
91
+
92
+
- Generate phase: the history fetches total at most 440 seconds, 120 seconds for the treeless fetch and 300 for the full fetch that follows when it fails, each with a 10-second kill grace (130 + 310).
93
+
- Publish phase: the registry operations and the alert total at most 465 seconds. An attempt makes up to six 20-second registry reads and one 35-second write, each with a 10-second kill grace (6 × 30 + 45 = 225 seconds). Two attempts, the 5-second pause between them and the alert's 10 seconds make 2 × 225 + 5 + 10.
94
+
95
+
### What a caller must do
96
+
97
+
- Pass `alert-slack-bot-token` to the publish invocation, from a secret, to get the Slack alert. It is optional: without it the phase still fails and writes its error annotation, with no Slack message, for callers that alert another way.
98
+
- Call the publish phase once per job. A failed call fails its job, and under the default step condition that skips every later step of the job, so a second publish call in the same job would never run when the first fails: its alias would not be written and no message would name its image repository. Do not put two publish calls in one job. For several image repositories, use one job per repository or a matrix over `images`; each call that reaches its last step and fails then sends its own message, when a token is passed, naming its own image repository.
99
+
- Where other jobs depend on the job that publishes the alias, put the publish invocation in its own job with `continue-on-error: true` at job level, so a missing alias fails that job without blocking its dependents. A step-level `continue-on-error` reports the step as succeeded and hides the failure, so it is not the way. Take `tags`, `labels` and `annotations` from the first invocation.
When nothing depends on the build job, the publish invocation can stay in it as a last step after `Build and push`, with the same inputs taken from `steps.meta` and `steps.image`.
0 commit comments