]> OCCT Git - occt.git/commitdiff
Testing - Summary image diff keeping #326
authorPasukhin Dmitry <dpasukhi@opencascade.com>
Sat, 1 Feb 2025 19:57:50 +0000 (20:57 +0100)
committerGitHub <noreply@github.com>
Sat, 1 Feb 2025 19:57:50 +0000 (19:57 +0000)
Add script to clean unused test images and update workflow to include it

.github/actions/scripts/cleanup_test_images.py [new file with mode: 0644]
.github/workflows/build-and-test-multiplatform.yml

diff --git a/.github/actions/scripts/cleanup_test_images.py b/.github/actions/scripts/cleanup_test_images.py
new file mode 100644 (file)
index 0000000..c848401
--- /dev/null
@@ -0,0 +1,90 @@
+import os
+import re
+from bs4 import BeautifulSoup
+from pathlib import Path
+import glob
+
+import os.path
+
+def get_referenced_images(html_file):
+    # Get the directory containing the HTML file
+    html_dir = os.path.dirname(os.path.abspath(html_file))
+    
+    with open(html_file, 'r', encoding='utf-8') as f:
+        soup = BeautifulSoup(f.read(), 'html.parser')
+    
+    images = set()
+    
+    # Extract direct image references
+    for img in soup.find_all('img'):
+        if src := img.get('src'):
+            # Convert relative path to absolute
+            abs_path = os.path.normpath(os.path.join(html_dir, src))
+            images.add(abs_path)
+    
+    # Extract toggle references
+    for elem in soup.find_all(attrs={'onclick': True}):
+        onclick = elem['onclick']
+        paths = re.findall(r'diffimage_toggle\(this,"([^"]+)","([^"]+)"\)', onclick)
+        for src1, src2 in paths:
+            # Convert relative paths to absolute
+            abs_path1 = os.path.normpath(os.path.join(html_dir, src1))
+            abs_path2 = os.path.normpath(os.path.join(html_dir, src2))
+            images.add(abs_path1)
+            images.add(abs_path2)
+    
+    return images
+
+def cleanup_platform_images(results_dir, platform):
+    html_file = f"{results_dir}/current/{platform}/diff-*.html"
+    html_files = glob.glob(html_file)
+    
+    if not html_files:
+        print(f"No diff HTML found for {platform}")
+        return
+        
+    # Get referenced images from HTML
+    referenced = set()
+    for html in html_files:
+        images = get_referenced_images(html)
+        referenced.update(images)
+    
+    # Convert relative paths to absolute
+    base_dir = Path(results_dir)
+    current_dir = base_dir / "current" / platform
+    master_dir = base_dir / "master" / platform
+    
+    # Find all PNGs
+    png_files = set()
+    for directory in [current_dir, master_dir]:
+        for root, _, files in os.walk(directory):
+            for file in files:
+                if file.lower().endswith('.png'):
+                    png_files.add(Path(root) / file)
+
+    # Remove unreferenced PNGs
+    for png in png_files:
+        if str(png) not in referenced:
+            try:
+                png.unlink()
+            except OSError as e:
+                print(f"Error removing {png}: {e}")
+
+def main():
+    platforms = [
+        "windows-x64",
+        "windows-clang-x64", 
+        "macos-x64",
+        "macos-gcc-x64",
+        "linux-clang-x64",
+        "linux-gcc-x64"
+    ]
+    
+    results_dir = Path("./").resolve()
+    
+    for platform in platforms:
+        print(f"\nProcessing {platform}...")
+        cleanup_platform_images(results_dir, platform)
+
+if __name__ == "__main__":
+    main()
index 28f0f1fc7b19ee217f62663440669eaae9843ebc..4913bf13f49ecc54ab4ffb3fa0856515a24697fa 100644 (file)
@@ -1675,13 +1675,25 @@ jobs:
           done
           wait
 
+      - name: Install BeautifulSoup
+        run: pip install beautifulsoup4
+
+      - name: Clean unused test images
+        run: |
+          # copy to the install/bin/results directory
+          cp ${{ github.workspace }}/.github/actions/scripts/cleanup_test_images.py install/bin/results
+          cd install/bin/results
+          python cleanup_test_images.py
+
       - name: Upload comparison results
         uses: actions/upload-artifact@v4.4.3
         with:
           name: test-compare-results
+          retention-days: 15
           overwrite: true
           path: |
-            install/bin/results/current/**/diff-*.html
-            install/bin/results/current/**/diff-*.log
-            install/bin/results/current/**/summary.html
-            install/bin/results/current/**/tests.log
+            install/bin/results/**/diff-*.html
+            install/bin/results/**/diff-*.log
+            install/bin/results/**/summary.html
+            install/bin/results/**/tests.log
+            install/bin/results/**/*.png