Skip to content

Commit

Permalink
Fix processing of archives with no parent directory
Browse files Browse the repository at this point in the history
The ZIP files created by GitHub Actions don't have any parent
directory, and just directly contain wpt_report.json, etc.

Previously, we were searching for filenames starting with "/", which
obviously doesn't match if there is no parent directory.
  • Loading branch information
gsnedders committed Oct 16, 2024
1 parent 19389e4 commit 716c11b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
Binary file added results-processor/artifact_test_github.zip
Binary file not shown.
Binary file added results-processor/artifact_test_numberless.zip
Binary file not shown.
14 changes: 8 additions & 6 deletions results-processor/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import fnmatch
import logging
import os
import re
import posixpath
import shutil
import sys
import tempfile
Expand Down Expand Up @@ -187,13 +188,14 @@ def _download_archive(self, archive_url):
return
with zipfile.ZipFile(artifact, mode='r') as z:
for f in z.infolist():
# ZipInfo.is_dir isn't available in Python 3.5.
if f.filename.endswith('/'):
if f.is_dir():
continue
path = z.extract(f, path=self._temp_dir)
if re.match(r'^.*/wpt_report.*\.json$', f.filename):
basename = posixpath.basename(f.filename)
if fnmatch.fnmatchcase(basename, 'wpt_report*.json'):
path = z.extract(f, path=self._temp_dir)
self.results.append(path)
if re.match(r'^.*/wpt_screenshot.*\.txt$', f.filename):
elif fnmatch.fnmatchcase(basename, 'wpt_screenshot*.txt'):
path = z.extract(f, path=self._temp_dir)
self.screenshots.append(path)

def download(self, results, screenshots, archives):
Expand Down
30 changes: 30 additions & 0 deletions results-processor/processor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,36 @@ def test_download_azure_errors(self):
p.download([], [], ['https://wpt.fyi/artifact.zip'])
self.assertEqual(len(p.results), 0)

def test_download_github(self):
with Processor() as p:
p._download_gcs = self.fake_download(None, None)
p._download_http = self.fake_download(
'https://wpt.fyi/artifact.zip',
'artifact_test_github.zip')

p.download([], [], ['https://wpt.fyi/artifact.zip'])
self.assertEqual(len(p.results), 1)
self.assertTrue(p.results[0].endswith(
'/wpt_report_2.json'))
self.assertEqual(len(p.screenshots), 1)
self.assertTrue(p.screenshots[0].endswith(
'/wpt_screenshot_2.txt'))

def test_download_numberless(self):
with Processor() as p:
p._download_gcs = self.fake_download(None, None)
p._download_http = self.fake_download(
'https://wpt.fyi/artifact.zip',
'artifact_test_numberless.zip')

p.download([], [], ['https://wpt.fyi/artifact.zip'])
self.assertEqual(len(p.results), 1)
self.assertTrue(p.results[0].endswith(
'/wpt_report.json'))
self.assertEqual(len(p.screenshots), 1)
self.assertTrue(p.screenshots[0].endswith(
'/wpt_screenshot.txt'))


class MockProcessorTest(unittest.TestCase):
@patch('processor.Processor')
Expand Down

0 comments on commit 716c11b

Please sign in to comment.