Skip to content

Commit df22c5d

Browse files
committed
fix(perf): print the regression annotation on stdout
GitHub Actions reads workflow commands only from stdout, but the `::warning` line was printed while `*out*` was bound to `*err*`, so a flagged regression never produced an annotation. Print it on stdout and pass the GitHub Actions check in, so a test can assert the stream. Reported by Pullfrog on #2061.
1 parent 582ba34 commit df22c5d

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎apps/ccusage/scripts/compare-pr-performance_test.clj‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@
129129
(is (.contains (:text (overall-verdict [(result :unchanged :unchanged)] 0.1)) "no significant change"))
130130
(is (not (:regression? (overall-verdict [(result :improvement :unchanged)] 0.1))))))
131131

132+
(deftest github-warning-goes-to-stdout
133+
(let [err (java.io.StringWriter.)
134+
regression {:regression? true :text "**Verdict: ⚠️ possible regression** in `daily`"}
135+
out (binding [*err* err] (with-out-str (github-warning! regression true)))]
136+
(is (= "::warning title=ccusage performance::Verdict: ⚠️ possible regression in `daily`\n" out))
137+
(is (= "" (str err))))
138+
(is (= "" (with-out-str (github-warning! {:regression? true :text "x"} false))))
139+
(is (= "" (with-out-str (github-warning! {:text "x"} true)))))
140+
132141
(let [{:keys [fail error]} (apply run-tests ['compare-pr-performance-test])]
133142
(when (pos? (+ fail error))
134143
(System/exit 1)))

‎apps/ccusage/scripts/compare_pr_performance/main.clj‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
:base (variant-summary rounds "base") :head (variant-summary rounds "PR")
88
:comparison (compare-variants rounds "base" "PR" (:threshold options))}))
99

10-
(defn github-warning! [verdict]
11-
(when (and (:regression? verdict) (System/getenv "GITHUB_ACTIONS"))
10+
(defn github-warning!
11+
"GitHub reads workflow commands only from stdout, so the annotation must not
12+
go to stderr with the progress log."
13+
[verdict github-actions?]
14+
(when (and (:regression? verdict) github-actions?)
1215
(println (str "::warning title=ccusage performance::" (str/replace (:text verdict) "**" "")))))
1316

1417
(defn -main [& argv]
@@ -28,5 +31,5 @@
2831
report (render-report context results {:base (optional-file-size (:bin (first variants)))
2932
:head (optional-file-size (:bin (second variants)))})]
3033
(write-output! (:output options) report)
31-
(binding [*out* *err*] (github-warning! (overall-verdict results (:threshold options)))))
34+
(github-warning! (overall-verdict results (:threshold options)) (some? (System/getenv "GITHUB_ACTIONS"))))
3235
(finally (fs/delete-tree empty-home)))))))

0 commit comments

Comments
 (0)