(config: ProjectConfig)
| 1785 | |
| 1786 | # Calculate, print and write progress to progress.json |
| 1787 | def calculate_progress(config: ProjectConfig) -> None: |
| 1788 | config.validate() |
| 1789 | out_path = config.out_path() |
| 1790 | report_path = out_path / "report.json" |
| 1791 | if not report_path.is_file(): |
| 1792 | sys.exit(f"Report file {report_path} does not exist") |
| 1793 | |
| 1794 | report_data: Dict[str, Any] = {} |
| 1795 | with open(report_path, "r", encoding="utf-8") as f: |
| 1796 | report_data = json.load(f) |
| 1797 | |
| 1798 | # Convert string numbers (u64) to int |
| 1799 | def convert_numbers(data: Dict[str, Any]) -> None: |
| 1800 | for key, value in data.items(): |
| 1801 | if isinstance(value, str) and value.isdigit(): |
| 1802 | data[key] = int(value) |
| 1803 | |
| 1804 | convert_numbers(report_data["measures"]) |
| 1805 | for category in report_data.get("categories", []): |
| 1806 | convert_numbers(category["measures"]) |
| 1807 | |
| 1808 | # Output to GitHub Actions job summary, if available |
| 1809 | summary_path = os.getenv("GITHUB_STEP_SUMMARY") |
| 1810 | summary_file: Optional[IO[str]] = None |
| 1811 | if summary_path: |
| 1812 | summary_file = open(summary_path, "a", encoding="utf-8") |
| 1813 | summary_file.write("```\n") |
| 1814 | |
| 1815 | def progress_print(s: str) -> None: |
| 1816 | print(s) |
| 1817 | if summary_file: |
| 1818 | summary_file.write(s + "\n") |
| 1819 | |
| 1820 | # Print human-readable progress |
| 1821 | progress_print("Progress:") |
| 1822 | |
| 1823 | def print_category(name: str, measures: Dict[str, Any]) -> None: |
| 1824 | total_code = measures.get("total_code", 0) |
| 1825 | matched_code = measures.get("matched_code", 0) |
| 1826 | matched_code_percent = measures.get("matched_code_percent", 0) |
| 1827 | total_data = measures.get("total_data", 0) |
| 1828 | matched_data = measures.get("matched_data", 0) |
| 1829 | matched_data_percent = measures.get("matched_data_percent", 0) |
| 1830 | total_functions = measures.get("total_functions", 0) |
| 1831 | matched_functions = measures.get("matched_functions", 0) |
| 1832 | complete_code_percent = measures.get("complete_code_percent", 0) |
| 1833 | total_units = measures.get("total_units", 0) |
| 1834 | complete_units = measures.get("complete_units", 0) |
| 1835 | |
| 1836 | progress_print( |
| 1837 | f" {name}: {matched_code_percent:.2f}% matched, {complete_code_percent:.2f}% linked ({complete_units} / {total_units} files)" |
| 1838 | ) |
| 1839 | progress_print( |
| 1840 | f" Code: {matched_code} / {total_code} bytes ({matched_functions} / {total_functions} functions)" |
| 1841 | ) |
| 1842 | progress_print( |
| 1843 | f" Data: {matched_data} / {total_data} bytes ({matched_data_percent:.2f}%)" |
| 1844 | ) |
no test coverage detected