From 99033c0e053b51390a32b29cdd3c524eb4c93f80 Mon Sep 17 00:00:00 2001
From: 2bndy5 <2bndy5@gmail.com>
Date: Mon, 18 Apr 2022 03:44:30 -0700
Subject: [PATCH 1/7] output sompilation time for each sketch

---
 compilesketches/compilesketches.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/compilesketches/compilesketches.py b/compilesketches/compilesketches.py
index 1be7b97c..cb7d1e02 100644
--- a/compilesketches/compilesketches.py
+++ b/compilesketches/compilesketches.py
@@ -1,4 +1,5 @@
 import atexit
+import time
 import contextlib
 import enum
 import json
@@ -893,13 +894,22 @@ def compile_sketch(self, sketch_path, clean_build_cache):
         if clean_build_cache:
             for cache_path in pathlib.Path("/tmp").glob(pattern="arduino*"):
                 shutil.rmtree(path=cache_path)
-
+        start_time = time.monotonic()
         compilation_data = self.run_arduino_cli_command(
             command=compilation_command, enable_output=self.RunCommandOutput.NONE, exit_on_failure=False)
+        diff_time = time.monotonic() - start_time
+        time_summary = ""
+        if diff_time > 60:
+            if diff_time > 360:
+                time_summary += f"{int(diff_time / 360)} hours "
+            time_summary += f"{int(diff_time / 60) % 60} minutes "
+        time_summary += f"{int(diff_time) % 60} seconds."
+
         # Group compilation output to make the log easy to read
         # https://github.com/actions/toolkit/blob/master/docs/commands.md#group-and-ungroup-log-lines
         print("::group::Compiling sketch:", path_relative_to_workspace(path=sketch_path))
         print(compilation_data.stdout)
+        print("Compilation time elapsed", time_summary)
         print("::endgroup::")
 
         class CompilationResult:

From 804a8524a0cc7534c1f450736dcd14cfc360753f Mon Sep 17 00:00:00 2001
From: 2bndy5 <2bndy5@gmail.com>
Date: Mon, 18 Apr 2022 03:44:30 -0700
Subject: [PATCH 2/7] output compilation time for each sketch

---
 compilesketches/compilesketches.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/compilesketches/compilesketches.py b/compilesketches/compilesketches.py
index 1be7b97c..cb7d1e02 100644
--- a/compilesketches/compilesketches.py
+++ b/compilesketches/compilesketches.py
@@ -1,4 +1,5 @@
 import atexit
+import time
 import contextlib
 import enum
 import json
@@ -893,13 +894,22 @@ def compile_sketch(self, sketch_path, clean_build_cache):
         if clean_build_cache:
             for cache_path in pathlib.Path("/tmp").glob(pattern="arduino*"):
                 shutil.rmtree(path=cache_path)
-
+        start_time = time.monotonic()
         compilation_data = self.run_arduino_cli_command(
             command=compilation_command, enable_output=self.RunCommandOutput.NONE, exit_on_failure=False)
+        diff_time = time.monotonic() - start_time
+        time_summary = ""
+        if diff_time > 60:
+            if diff_time > 360:
+                time_summary += f"{int(diff_time / 360)} hours "
+            time_summary += f"{int(diff_time / 60) % 60} minutes "
+        time_summary += f"{int(diff_time) % 60} seconds."
+
         # Group compilation output to make the log easy to read
         # https://github.com/actions/toolkit/blob/master/docs/commands.md#group-and-ungroup-log-lines
         print("::group::Compiling sketch:", path_relative_to_workspace(path=sketch_path))
         print(compilation_data.stdout)
+        print("Compilation time elapsed", time_summary)
         print("::endgroup::")
 
         class CompilationResult:

From bbcb464c06eb28e0089d06258cecd897612d5098 Mon Sep 17 00:00:00 2001
From: 2bndy5 <2bndy5@gmail.com>
Date: Mon, 18 Apr 2022 05:53:14 -0700
Subject: [PATCH 3/7] adjust expected output in pytest

---
 compilesketches/tests/test_compilesketches.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/compilesketches/tests/test_compilesketches.py b/compilesketches/tests/test_compilesketches.py
index 8074f2f2..6186a38e 100644
--- a/compilesketches/tests/test_compilesketches.py
+++ b/compilesketches/tests/test_compilesketches.py
@@ -1435,6 +1435,7 @@ class CompilationData:
     expected_stdout = (
         "::group::Compiling sketch: " + str(compilesketches.path_relative_to_workspace(path=sketch_path)) + "\n"
         + str(stdout) + "\n"
+        + "Compilation time elapsed 0 seconds.\n"
         + "::endgroup::"
     )
     if not expected_success:

From 07d3be687e85c78c2ce241f1d4f66800279e5620 Mon Sep 17 00:00:00 2001
From: 2bndy5 <2bndy5@gmail.com>
Date: Mon, 18 Apr 2022 07:18:37 -0700
Subject: [PATCH 4/7] move out of log group; change units of time

elapsed time is only output if compilation did not fail.
---
 compilesketches/compilesketches.py            | 15 ++++++++-------
 compilesketches/tests/test_compilesketches.py |  3 ++-
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/compilesketches/compilesketches.py b/compilesketches/compilesketches.py
index cb7d1e02..3622d43e 100644
--- a/compilesketches/compilesketches.py
+++ b/compilesketches/compilesketches.py
@@ -898,18 +898,11 @@ def compile_sketch(self, sketch_path, clean_build_cache):
         compilation_data = self.run_arduino_cli_command(
             command=compilation_command, enable_output=self.RunCommandOutput.NONE, exit_on_failure=False)
         diff_time = time.monotonic() - start_time
-        time_summary = ""
-        if diff_time > 60:
-            if diff_time > 360:
-                time_summary += f"{int(diff_time / 360)} hours "
-            time_summary += f"{int(diff_time / 60) % 60} minutes "
-        time_summary += f"{int(diff_time) % 60} seconds."
 
         # Group compilation output to make the log easy to read
         # https://github.com/actions/toolkit/blob/master/docs/commands.md#group-and-ungroup-log-lines
         print("::group::Compiling sketch:", path_relative_to_workspace(path=sketch_path))
         print(compilation_data.stdout)
-        print("Compilation time elapsed", time_summary)
         print("::endgroup::")
 
         class CompilationResult:
@@ -919,6 +912,14 @@ class CompilationResult:
 
         if not CompilationResult.success:
             print("::error::Compilation failed")
+        else:
+            time_summary = ""
+            if diff_time > 60:
+                if diff_time > 360:
+                    time_summary += f"{int(diff_time / 360)} h "
+                time_summary += f"{int(diff_time / 60) % 60} m "
+            time_summary += f"{int(diff_time) % 60} s"
+            print("Compilation time elapsed", time_summary)
 
         return CompilationResult()
 
diff --git a/compilesketches/tests/test_compilesketches.py b/compilesketches/tests/test_compilesketches.py
index 6186a38e..e5b409b8 100644
--- a/compilesketches/tests/test_compilesketches.py
+++ b/compilesketches/tests/test_compilesketches.py
@@ -1435,11 +1435,12 @@ class CompilationData:
     expected_stdout = (
         "::group::Compiling sketch: " + str(compilesketches.path_relative_to_workspace(path=sketch_path)) + "\n"
         + str(stdout) + "\n"
-        + "Compilation time elapsed 0 seconds.\n"
         + "::endgroup::"
     )
     if not expected_success:
         expected_stdout += "\n::error::Compilation failed"
+    else:
+        expected_stdout += "\nCompilation time elapsed 0s"
     assert capsys.readouterr().out.strip() == expected_stdout
 
     assert compilation_result.sketch == sketch_path

From 9754d0db03bbe2a2ac3fa8eadc262e086a9e8f7a Mon Sep 17 00:00:00 2001
From: 2bndy5 <2bndy5@gmail.com>
Date: Mon, 18 Apr 2022 07:21:12 -0700
Subject: [PATCH 5/7] remove whitespace in time output

---
 compilesketches/compilesketches.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/compilesketches/compilesketches.py b/compilesketches/compilesketches.py
index 3622d43e..09fbd31b 100644
--- a/compilesketches/compilesketches.py
+++ b/compilesketches/compilesketches.py
@@ -916,9 +916,9 @@ class CompilationResult:
             time_summary = ""
             if diff_time > 60:
                 if diff_time > 360:
-                    time_summary += f"{int(diff_time / 360)} h "
-                time_summary += f"{int(diff_time / 60) % 60} m "
-            time_summary += f"{int(diff_time) % 60} s"
+                    time_summary += f"{int(diff_time / 360)}h "
+                time_summary += f"{int(diff_time / 60) % 60}m "
+            time_summary += f"{int(diff_time) % 60}s"
             print("Compilation time elapsed", time_summary)
 
         return CompilationResult()

From a157da368cd5c60d05c9c749e858aa3369c0d414 Mon Sep 17 00:00:00 2001
From: Brendan <2bndy5@gmail.com>
Date: Mon, 18 Apr 2022 14:13:21 -0700
Subject: [PATCH 6/7] add a colon

Co-authored-by: per1234 <accounts@perglass.com>
---
 compilesketches/compilesketches.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compilesketches/compilesketches.py b/compilesketches/compilesketches.py
index 09fbd31b..a9ec4049 100644
--- a/compilesketches/compilesketches.py
+++ b/compilesketches/compilesketches.py
@@ -919,7 +919,7 @@ class CompilationResult:
                     time_summary += f"{int(diff_time / 360)}h "
                 time_summary += f"{int(diff_time / 60) % 60}m "
             time_summary += f"{int(diff_time) % 60}s"
-            print("Compilation time elapsed", time_summary)
+            print("Compilation time elapsed:", time_summary)
 
         return CompilationResult()
 

From 820d9df342dd63bd7cada88a19fa59b6e85e87db Mon Sep 17 00:00:00 2001
From: Brendan <2bndy5@gmail.com>
Date: Mon, 18 Apr 2022 14:32:51 -0700
Subject: [PATCH 7/7] update test expected output

---
 compilesketches/tests/test_compilesketches.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compilesketches/tests/test_compilesketches.py b/compilesketches/tests/test_compilesketches.py
index e5b409b8..60b713da 100644
--- a/compilesketches/tests/test_compilesketches.py
+++ b/compilesketches/tests/test_compilesketches.py
@@ -1440,7 +1440,7 @@ class CompilationData:
     if not expected_success:
         expected_stdout += "\n::error::Compilation failed"
     else:
-        expected_stdout += "\nCompilation time elapsed 0s"
+        expected_stdout += "\nCompilation time elapsed: 0s"
     assert capsys.readouterr().out.strip() == expected_stdout
 
     assert compilation_result.sketch == sketch_path