File 3391-gh-Purge-the-uploaded-logs-of-any-suite-without-fail.patch of Package erlang
From 65246c5a1803947608b067a6f49723dd8da3080f Mon Sep 17 00:00:00 2001
From: Lukas Larsson <lukas@erlang.org>
Date: Fri, 3 Jun 2022 10:24:04 +0200
Subject: [PATCH] gh: Purge the uploaded logs of any suite without failed tests
---
.github/scripts/sync-github-prs.es | 35 ++++++++++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/.github/scripts/sync-github-prs.es b/.github/scripts/sync-github-prs.es
index bc033c3efe..b241847713 100755
--- a/.github/scripts/sync-github-prs.es
+++ b/.github/scripts/sync-github-prs.es
@@ -62,7 +62,9 @@ handle_pr(_Repo, Target,
string:equal(HeadSha, Sha) andalso string:equal(Status, <<"completed">>)
end, maps:get(<<"workflow_runs">>, Runs)) of
{value, Run} ->
- Ident = integer_to_list(maps:get(<<"id">>,Run)),
+ Ident = integer_to_list(
+ erlang:phash2(
+ {maps:get(<<"id">>,Run), ?MODULE:module_info(md5)})),
io:format("Checking for ~ts~n", [filename:join(PRDir, Ident)]),
case file:read_file_info(filename:join(PRDir, Ident)) of
{error, enoent} ->
@@ -91,7 +93,9 @@ handle_pr(_Repo, Target,
end, Artifacts),
CTLogsIndex = filename:join([PRDir,"ct_logs","index.html"]),
case file:read_file_info(CTLogsIndex) of
- {ok, _} -> ok;
+ {ok, _} ->
+ CTSuiteFiles = filename:join([PRDir,"ct_logs","ct_run*","*.logs","run.*","suite.log"]),
+ lists:foreach(fun purge_suite/1, filelib:wildcard(CTSuiteFiles));
_ ->
ok = filelib:ensure_dir(CTLogsIndex),
ok = file:write_file(CTLogsIndex, ["No test logs found for ", Sha])
@@ -109,6 +113,33 @@ handle_pr(_Repo, Target,
ok
end.
+%% We truncate the logs of all testcases of any suite that did not have any failures
+purge_suite(SuiteFilePath) ->
+ {ok, SuiteFile} = file:read_file(SuiteFilePath),
+ SuiteDir = filename:dirname(SuiteFilePath),
+ Placeholder = "<html><body>github truncated successful testcase</body></html>",
+ case re:run(SuiteFile,"^=failed\s*\([0-9]+\)$",[multiline,{capture,all_but_first,binary}]) of
+ {match,[<<"0">>]} ->
+ io:format("Purging logs from: ~ts~n",[SuiteDir]),
+ ok = file:del_dir_r(filename:join(SuiteDir,"log_private")),
+ lists:foreach(
+ fun(File) ->
+ case filename:basename(File) of
+ "suite" ++ _ ->
+ ok;
+ "unexpected_io" ++_ ->
+ ok;
+ "cover.html" ->
+ ok;
+ _Else ->
+ file:write_file(File,Placeholder)
+ end
+ end, filelib:wildcard(filename:join(SuiteDir,"*.html")));
+ _FailedTestcases ->
+ io:format("Purging logs from: ~ts~n",[SuiteDir]),
+ ok
+ end.
+
ghapi(CMD) ->
decode(cmd(CMD)).
--
2.35.3