2021-08-24 15:30:35 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import argparse
|
2023-12-09 17:50:54 +01:00
|
|
|
import os
|
|
|
|
from pathlib import Path
|
2021-08-24 15:30:35 +02:00
|
|
|
import sys
|
|
|
|
|
2023-12-09 17:50:54 +01:00
|
|
|
import requests
|
2021-08-24 15:30:35 +02:00
|
|
|
|
2023-12-09 17:50:54 +01:00
|
|
|
script_dir = Path(os.path.dirname(os.path.realpath(__file__)))
|
|
|
|
root_dir = script_dir / "../.."
|
2021-08-24 15:30:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("--pr-message", action="store_true")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2023-12-09 17:50:54 +01:00
|
|
|
# Download the latest warnings.txt
|
|
|
|
response = requests.get("https://papermar.io/reports/warnings.txt")
|
|
|
|
current_warnings = response.content.decode("utf-8").strip().split("\n")
|
2023-12-25 14:14:39 +01:00
|
|
|
current_warnings = [line for line in current_warnings if line]
|
2023-12-09 17:50:54 +01:00
|
|
|
|
|
|
|
# Write the current warnings to a file
|
|
|
|
with open(script_dir / "warnings.txt", "w") as f:
|
|
|
|
for line in current_warnings:
|
|
|
|
f.write(line + "\n")
|
|
|
|
|
|
|
|
# Get the new warnings from the build log
|
|
|
|
if not (root_dir / "build_log.txt").exists():
|
|
|
|
print("build_log.txt not found. Exiting.")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
with open(root_dir / "build_log.txt") as f:
|
|
|
|
new_warnings = [line for line in f.readlines() if "warning" in line]
|
|
|
|
|
|
|
|
# Write the new warnings to a file
|
|
|
|
with open(script_dir / "warnings_new.txt", "w") as f:
|
|
|
|
f.writelines(new_warnings)
|
|
|
|
|
|
|
|
num_current_warnings = len(current_warnings)
|
|
|
|
num_new_warnings = len(new_warnings)
|
|
|
|
if num_new_warnings > num_current_warnings:
|
2021-08-24 15:30:35 +02:00
|
|
|
stderr = False
|
|
|
|
if args.pr_message:
|
2023-12-09 17:50:54 +01:00
|
|
|
delta = num_new_warnings - num_current_warnings
|
2021-08-24 15:30:35 +02:00
|
|
|
|
|
|
|
if delta == 1:
|
|
|
|
print(f"⚠️ This PR introduces a warning:")
|
|
|
|
else:
|
|
|
|
print(f"⚠️ This PR introduces {delta} warnings:")
|
|
|
|
|
|
|
|
if delta > 100:
|
|
|
|
stderr = True
|
|
|
|
print("See log for details.")
|
|
|
|
else:
|
|
|
|
print()
|
|
|
|
print("There are more warnings now. Go fix them!")
|
2023-12-09 17:50:54 +01:00
|
|
|
print("\tCurrent warnings: " + str(num_current_warnings))
|
|
|
|
print("\tNew warnings: " + str(num_new_warnings))
|
2021-08-24 15:30:35 +02:00
|
|
|
print()
|
|
|
|
|
2023-12-09 17:50:54 +01:00
|
|
|
for newLine in new_warnings:
|
|
|
|
if "warning: previous declaration of" in newLine:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if newLine not in current_warnings:
|
|
|
|
if stderr:
|
|
|
|
print(newLine.strip(), file=sys.stderr)
|
|
|
|
else:
|
|
|
|
print("- " + newLine.strip())
|
|
|
|
elif num_new_warnings < num_current_warnings:
|
|
|
|
delta = num_current_warnings - num_new_warnings
|
2021-08-24 15:30:35 +02:00
|
|
|
|
|
|
|
if args.pr_message:
|
|
|
|
print(f"✅ This PR fixes {delta} warnings!")
|
|
|
|
else:
|
|
|
|
print(f"{delta} warnings fixed.")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|