Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/+summary-write-status.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Return a failed status when a run summary cannot be written.
4 changes: 2 additions & 2 deletions docs/examples/summary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ expect_line ' "kind": "status",'

run 'mkdir -p site/logs/20261117_100000/summary.json
eb-pipeline run --site site.toml --list example.list --target zen4 --build-type production --log-stamp 20261117_100000; echo "exit $?"'
expect_line 'exit 0'
expect_line 'WARN [summary] zen4: no summary written: cannot read $WORK/site/logs/20261117_100000/summary.json: Is a directory (os error 21)'
expect_line 'exit 1'
expect_line 'ERROR [main] -: cannot write run summary: cannot read $WORK/site/logs/20261117_100000/summary.json: Is a directory (os error 21)'

cp site.toml notify.toml
printf '\n[notify]\nwebhook_env = "SUMMARY_WEBHOOK"\nwhen = "problems"\n' >>notify.toml
Expand Down
4 changes: 2 additions & 2 deletions docs/orgmode/howto/follow-runs.org
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ With no lines left after classification, =stack oom= is not started.
|------------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------|
| =INFO [status] -: no runs under LOG_ROOT= | No run has written under the =log_root= of the site file: none has run yet, or the runs use another site file. | Give =status= the site file that the runs use. |
| =RUN no summary.json: the run is still going, or ended before writing one= | The run has not ended, or it stopped before it wrote its summary. | Wait for the run to end, or read the logs in its run directory. |
| =WARN [summary] TARGET: no summary written: PATH: ERROR= | The run could not write its summary. | Fix what =ERROR= names, such as the permissions or the free space of the log root. |
| =ERROR [main] -: cannot write run summary: PATH: ERROR= | The run could not write its summary. | Fix what =ERROR= names, such as the permissions or the free space of the log root. |
| =WARN [notify] TARGET: SUMMARY_WEBHOOK is unset or empty; nothing sent= | The variable that =webhook_env= names is not set where eb-pipeline runs. | Set it there, as step 4 says. |
| =WARN [notify] TARGET: the URL in SUMMARY_WEBHOOK must start with http:// or https://; nothing sent= | The variable holds something other than a URL with its scheme. | Put the URL of the webhook in it, with =https://= or =http://=. |
| =WARN [notify] TARGET: POST of summary.json to URL failed: curl exited 7: ERROR= | Nothing took the connection at the host and port of the URL. | Check the URL, and that the service of the webhook, or the listener of step 5, runs. |
| =WARN [notify] TARGET: POST of summary.json to URL failed: curl exited 22: curl: (22) The requested URL returned error: 500= | The webhook answered with an HTTP error. | Read what its service logged for the POST. |

A summary that is not written or not sent leaves the exit status of the run as it was.
A summary that cannot be written fails the run. A summary that is not sent leaves the exit status of the run as it was.

** Related

Expand Down
5 changes: 3 additions & 2 deletions docs/orgmode/reference/exit-status.org
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ An error that ends a command is written to stderr as =ERROR [main] -: MESSAGE=.
- =run=: =eb-stack stack sbom= could not be started, exited with a status other than 0, or wrote no =sbom.cdx.json=, after a clean build.
- =run=: =eb-keep-logs rotate= exited with a status other than 0 and 75.
- =run=: a log file, a log directory, the list of selected lines or the result file could not be written.
- =run= or =watch=: the run summary could not be written.
- =plan=: the shard plan given to =--shard-plan= could not be read, or the plan could not be written to =--out=.
- =plan= or =run=: =[attest]= is enabled and =rfc9162-sidecar= could not be started or exited with a status other than 0.
- =verify=: the inclusion proof does not meet its checkpoint, or the blob file does not match the proof.
Expand All @@ -52,7 +53,7 @@ An error that ends a command is written to stderr as =ERROR [main] -: MESSAGE=.
- =audit=: =--out-dir= or its working directory could not be created, an =eb-stack= subcommand exited non-zero or its log could not be read, a rebuild list could not be copied, or =--strict= saw one or more backport items.

A failed =eb-keep-logs failed= after a failed line leaves the status as it is, with a =WARN= line.
So does a run summary that cannot be written, or sent to the webhook of =[notify]=, as [[file:run-summary.org][The run summary]] says, and a record of =[watch]= that fails, as [[file:watch.org][The watch state and plan]] says.
So does a summary that cannot be sent to the webhook of =[notify]=, as [[file:run-summary.org][The run summary]] says, and a record of =[watch]= that fails, as [[file:watch.org][The watch state and plan]] says.

*** 2

Expand Down Expand Up @@ -112,7 +113,7 @@ An attestation helper killed by a signal reports and returns =128 + signal=.
** When several apply

A signal ends a run with 130 or 143, and a usage error with 2, whatever else happened before.
This holds for a result file or a metrics file that cannot be written after the signal: the run reports the error and still exits 130 or 143.
This holds for a result file, a metrics file or a run summary that cannot be written after the signal: the run reports the error and still exits 130 or 143.
Otherwise the first of these that applies is the status of the run:

1. a line or a phase failed: 1;
Expand Down
10 changes: 5 additions & 5 deletions docs/orgmode/reference/run-summary.org
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ zen4
Each run takes the lock =.summary.lock= of the run directory, reads =summary.json=, replaces the entry of its own target and keeps the others, and writes both files anew through a rename, so that a reader never sees half of one.
A later run of the same target with the same stamp replaces that target's entry.
A =summary.json= with another =schema_version= is replaced, whatever else it holds.
One that does not parse is kept, and the run warns that no summary was written, so one target cannot erase the other target entries that may still be recoverable.
A file whose =kind= is not =summary=, or that lacks a =kind= or an integer =schema_version=, is kept as well: it may be another artifact of the tool, such as a result, a plan or a status document, and the warning names the =kind= it found.
One that does not parse is kept, and the run fails without replacing it, so one target cannot erase the other target entries that may still be recoverable.
A file whose =kind= is not =summary=, or that lacks a =kind= or an integer =schema_version=, is kept as well: it may be another artifact of the tool, such as a result, a plan or a status document, and the error names the =kind= it found.
The =kind= is read before the =schema_version=, and both before the other keys, so that a file of another kind is never mistaken for a summary of another version.

A summary that cannot be written is a warning, and the run exits as it would have without it.
A summary that cannot be written fails the run.
Here a directory is in the way of =summary.json=:

#+begin_src bash
Expand All @@ -73,8 +73,8 @@ eb-pipeline run --site site.toml --list example.list --target zen4 --build-type
#+begin_example
INFO [licences] zen4: not configured
...
WARN [summary] zen4: no summary written: cannot read $WORK/site/logs/20261117_100000/summary.json: Is a directory (os error 21)
exit 0
ERROR [main] -: cannot write run summary: cannot read $WORK/site/logs/20261117_100000/summary.json: Is a directory (os error 21)
exit 1
#+end_example

** summary.json
Expand Down
41 changes: 26 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,16 +1117,18 @@ fn cmd_plan_or_run(c: &Common, m: Mode) -> Result<i32, Fail> {
if let Some(before) = &before {
watch::record_run(&planner, &lines, &res, before);
}
write_summary_with_pending_signal(
let mut output_errors = Vec::new();
if let Err(f) = write_summary_with_pending_signal(
&s,
&mut res,
"run",
result,
None,
&planner.offline_wrapper,
);
) {
output_errors.push(f.msg);
}
let value = to_sorted(&res);
let mut output_errors = Vec::new();
if let Some(p) = result {
if let Err(f) = write_json(&value, Some(p)) {
output_errors.push(f.msg);
Expand Down Expand Up @@ -1168,22 +1170,23 @@ fn write_summary_with_pending_signal(
result: Option<&Path>,
watch: Option<serde_json::Value>,
offline_wrapper: &[String],
) {
) -> Result<(), Fail> {
apply_pending_signal(&mut res.exit_code, &mut res.interrupted_by);
write_summary(s, res, command, result, watch, offline_wrapper);
let written = write_summary(s, res, command, result, watch, offline_wrapper);
apply_pending_signal(&mut res.exit_code, &mut res.interrupted_by);
written
}

/// Merge a target's run into its run directory's summary; a problem is a
/// warning and leaves the run's exit code as it is.
/// Merge a target's run into its run directory's summary. A problem writing
/// the summary fails the command.
fn write_summary(
s: &schema::Site,
res: &RunResult,
command: &str,
result: Option<&Path>,
watch: Option<serde_json::Value>,
offline_wrapper: &[String],
) {
) -> Result<(), Fail> {
let dir = summary::run_dir(res);
let entry = summary::entry(res, command, result, watch);
match summary::record(&s.site.name, entry, &dir) {
Expand All @@ -1206,13 +1209,12 @@ fn write_summary(
&dir.join(summary::JSON),
offline_wrapper,
);
Ok(())
}
Err(e) => log(
"WARN",
"summary",
&res.target,
&format!("no summary written: {e}"),
),
Err(e) => Err(Fail::new(
exit::FAILED,
format!("cannot write run summary: {e}"),
)),
}
}

Expand Down Expand Up @@ -1652,7 +1654,16 @@ fn cmd_watch(w: &WatchArgs) -> Result<i32, Fail> {
),
}
}
write_summary_with_pending_signal(&s, &mut res, "watch", w.result, Some(to_sorted(&doc)), &[]);
if let Err(f) = write_summary_with_pending_signal(
&s,
&mut res,
"watch",
w.result,
Some(to_sorted(&doc)),
&[],
) {
return Err(signal_outranks(res.exit_code, f));
}
if let Some(p) = w.result {
write_json(&to_sorted(&res), Some(p)).map_err(|f| signal_outranks(res.exit_code, f))?;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/offline_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ fn a_bundle_manifest_is_not_taken_for_a_run_summary() {

let again = run(&f, &[]);
let stderr = String::from_utf8_lossy(&again.stderr);
assert_eq!(again.status.code(), Some(0), "{stderr}");
assert_eq!(again.status.code(), Some(1), "{stderr}");
assert!(
stderr.contains("no summary written: ") && stderr.contains(why),
stderr.contains("cannot write run summary: ") && stderr.contains(why),
"{stderr}"
);
assert_eq!(std::fs::read_to_string(&summary).unwrap(), manifest);
Expand Down
24 changes: 12 additions & 12 deletions tests/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ fn a_corrupt_summary_is_not_replaced_by_one_target() {
std::fs::write(&path, corrupt).unwrap();

let repeated = run(&t, "cpu", STAMP, LIST, &[]);
assert_eq!(code(&repeated), 0, "{}", stderr(&repeated));
assert_eq!(code(&repeated), 1, "{}", stderr(&repeated));
assert_eq!(std::fs::read(&path).unwrap(), corrupt);
assert!(
stderr(&repeated).contains("no summary written: cannot parse"),
stderr(&repeated).contains("cannot write run summary: cannot parse"),
"{}",
stderr(&repeated)
);
Expand All @@ -166,7 +166,7 @@ fn a_summary_with_another_kind_is_not_merged() {

let gpu = run(&t, "gpu", STAMP, LIST, &[]);

assert_eq!(code(&gpu), 0, "{}", stderr(&gpu));
assert_eq!(code(&gpu), 1, "{}", stderr(&gpu));
assert_eq!(std::fs::read_to_string(&path).unwrap(), foreign);
assert!(
stderr(&gpu).contains("kind `result` is not `summary`"),
Expand Down Expand Up @@ -283,19 +283,19 @@ fn status_of_runs(t: &T) -> String {
}

/// `record` and `status` on `text` as `summary.json`: both refuse it with
/// `why`, and the run leaves the file as it was.
/// `why`, the run fails, and the file is left as it was.
fn assert_refused_and_kept(text: &str, why: &str) {
let (t, path) = with_summary_file(text);

let o = run(&t, "gpu", STAMP, LIST, &[]);
assert_eq!(code(&o), 0, "{}", stderr(&o));
assert_eq!(code(&o), 1, "{}", stderr(&o));
assert_eq!(std::fs::read_to_string(&path).unwrap(), text);
let err = stderr(&o);
let warning = err
let error = err
.lines()
.find(|l| l.starts_with("WARN [summary] gpu: no summary written: "))
.unwrap_or_else(|| panic!("no summary warning in {err}"));
assert!(warning.contains(why), "{warning}");
.find(|l| l.starts_with("ERROR [main] -: cannot write run summary: "))
.unwrap_or_else(|| panic!("no summary error in {err}"));
assert!(error.contains(why), "{error}");

let shown = status_of_runs(&t);
assert!(
Expand Down Expand Up @@ -407,13 +407,13 @@ fn a_dry_run_writes_no_summary() {
}

#[test]
fn a_summary_that_cannot_be_written_leaves_the_exit_code() {
fn a_summary_destination_directory_fails_the_run() {
let t = setup("");
std::fs::create_dir_all(t.run_dir(STAMP).join("summary.json")).unwrap();
let o = run(&t, "cpu", STAMP, LIST, &[]);
assert_eq!(code(&o), 0, "{}", stderr(&o));
assert_eq!(code(&o), 1, "{}", stderr(&o));
assert!(
stderr(&o).contains("WARN [summary] cpu: no summary written: "),
stderr(&o).contains("ERROR [main] -: cannot write run summary: "),
"{}",
stderr(&o)
);
Expand Down
Loading