Skip to main content

speccoder_core/
workflow.rs

1//! GitHub Actions workflow commands (`::error file=…,line=…::…`): their
2//! escaping and the limits a step has, shared by `speccoder`'s report
3//! annotations and `speccoder-verify`'s fallback when it cannot publish
4//! its check.
5
6/// Bytes a step summary may take (GitHub's cap is 1 MiB per step).
7pub const SUMMARY_BUDGET: usize = 1_000_000;
8
9/// Annotations of one kind GitHub shows per step.
10pub const ANNOTATIONS_PER_KIND: usize = 10;
11
12/// Escapes workflow-command data.
13#[must_use]
14pub fn data(s: &str) -> String {
15    s.replace('%', "%25")
16        .replace('\r', "%0D")
17        .replace('\n', "%0A")
18}
19
20/// Escapes a workflow-command property.
21#[must_use]
22pub fn property(s: &str) -> String {
23    data(s).replace(':', "%3A").replace(',', "%2C")
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    #[test]
31    fn data_and_properties_are_escaped() {
32        assert_eq!(data("50%\nnext"), "50%25%0Anext");
33        assert_eq!(property("a: b, c"), "a%3A b%2C c");
34    }
35}