-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug 1636842 - part 2: Make check-screenshots script smarter about the number of screenshots #6689
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
locales: | ||
- af | ||
- an | ||
- anp | ||
- ar | ||
- ast | ||
- az | ||
- bg | ||
- bn | ||
- bo | ||
- br | ||
- bs | ||
- ca | ||
- co | ||
- cs | ||
- cy | ||
- da | ||
- de | ||
- dsb | ||
- el | ||
- en-CA | ||
- en-GB | ||
- en-US | ||
- eo | ||
- es-AR | ||
- es-CL | ||
- es-MX | ||
- es | ||
- eu | ||
- fa | ||
- fi | ||
- fr | ||
- ga-IE | ||
- gd | ||
- gl | ||
- gu-IN | ||
- he | ||
- hi-IN | ||
- hr | ||
- hsb | ||
- hu | ||
- hy-AM | ||
- ia | ||
- id | ||
- is | ||
- it | ||
- ja | ||
- jv | ||
- ka | ||
- kab | ||
- kk | ||
- km | ||
- kn | ||
- ko | ||
- lo | ||
- lt | ||
- lv | ||
- ml | ||
- mr | ||
- ms | ||
- my | ||
- nb-NO | ||
- ne-NP | ||
- nl | ||
- nn-NO | ||
- oc | ||
- or | ||
- pa-IN | ||
- pl | ||
- pt-BR | ||
- pt-PT | ||
- rm | ||
- ro | ||
- ru | ||
- ses | ||
- si | ||
- sk | ||
- sl | ||
- sq | ||
- su | ||
- sv-SE | ||
- ta | ||
- te | ||
- th | ||
- tl | ||
- tr | ||
- uk | ||
- ur | ||
- uz | ||
- vi | ||
- zgh | ||
- zh-CN | ||
- zh-TW | ||
locales-with-shorter-context-menu: ["hi-IN", "th", "zh-CN", "zh-TW"] # These locales have 1 less screenshot. | ||
usual-number-of-screenshots: 55 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,8 @@ PROJECT_DIR="$(get_abs_path $CURRENT_DIR/../../../..)" | |
|
||
|
||
if [ -d l10n-screenshots ]; then | ||
echo "The l10n-screenshots directory already exists. You decide." | ||
exit 1 | ||
echo "The l10n-screenshots directory already exists. You decide." | ||
exit 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: extra space? also above and some lines below There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I aligned every if statement to use 4-space-indents. The rest of the file seems to use this convention. I'm fine having everything aligned at 2 spaces too 🙂 |
||
fi | ||
|
||
if [ ! -d firefoxios-l10n ]; then | ||
|
@@ -25,13 +25,14 @@ fi | |
mkdir -p l10n-screenshots | ||
|
||
if [ "$1" = '--test-without-building' ]; then | ||
EXTRA_FAST_LANE_ARGS='--test_without_building' | ||
shift | ||
EXTRA_FAST_LANE_ARGS='--test_without_building' | ||
shift | ||
fi | ||
|
||
LOCALES=$* | ||
if [ $# -eq 0 ]; then | ||
LOCALES=$(cat "$PROJECT_DIR/l10n-screenshots-locales.txt") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not easy to parse a Yaml file in bash and I don't think we want to run all locales by default anymore. So I updated the script to force users to tell which locales they want to run. How does this sound to you @isabelrios? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good, that would only affect when running them locally, right? on CI, this is passed each time if I got this right There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right! |
||
echo "Please provide locales to test. Available locales live in 'l10n-screenshots-config.yml'. E.g.: $0 af an anp ar" | ||
exit 1 | ||
fi | ||
|
||
for lang in $LOCALES; do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
aiohttp-retry | ||
PyYAML | ||
taskcluster |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import logging | ||
import os | ||
import sys | ||
import yaml | ||
|
||
from zipfile import ZipFile | ||
|
||
|
@@ -21,12 +22,13 @@ def main(): | |
parser = argparse.ArgumentParser(description="Ensures a directory has all expected locales and screenshots.") | ||
|
||
parser.add_argument("--artifacts-directory", required=True, help="The directory containing the zip archives to look into") | ||
parser.add_argument("--screenshots-per-locale", type=int, required=True, help="Number of expected screenshots for each locale") | ||
parser.add_argument("--screenshots-configuration", type=argparse.FileType("r"), required=True, help="YAML file that contains the number of screenshots to expect as well as exceptions/") | ||
parser.add_argument("--locale", dest="locales", metavar="LOCALE", action="append", required=True, help="locale that must be present(can be repeated)") | ||
|
||
result = parser.parse_args() | ||
|
||
_check_files(result.artifacts_directory, result.locales, result.screenshots_per_locale) | ||
number_of_screenshots_per_locale = _parse_screenshots_configuration(result.screenshots_configuration) | ||
_check_files(result.artifacts_directory, result.locales, number_of_screenshots_per_locale) | ||
|
||
|
||
def _init_logging(): | ||
|
@@ -36,37 +38,56 @@ def _init_logging(): | |
) | ||
|
||
|
||
def _parse_screenshots_configuration(config_file): | ||
config = yaml.safe_load(config_file) | ||
|
||
number_of_screenshots_per_locale = {} | ||
for locale in config["locales"]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This loop is in charge of counting how many screenshots a locale has. As of now a locale can have either 55 or 54 pictures. We may have other kinds of locales that bump/reduce this number. Each new kind will have to be defined here. |
||
expected_screenshots = config["usual-number-of-screenshots"] | ||
if locale in config["locales-with-shorter-context-menu"]: | ||
expected_screenshots -= 1 | ||
|
||
number_of_screenshots_per_locale[locale] = expected_screenshots | ||
|
||
return number_of_screenshots_per_locale | ||
|
||
|
||
# This exit code was picked to avoid collision with famous exit codes (like 1 or 2). This way, | ||
# Taskcluster can spot if this script failed for a known reason and rerun this task if needed. | ||
_FAILURE_EXIT_CODE = 47 | ||
|
||
|
||
def _check_files(artifacts_directory, locales, expected_number_of_screenshots_per_locale): | ||
def _check_files(artifacts_directory, locales, number_of_screenshots_per_locale): | ||
errors = [] | ||
|
||
archives = set(glob.glob("{}/*.zip".format(artifacts_directory))) | ||
archives = _filter_out_derived_data_archive(archives) | ||
expected_archives = set("{}/{}.zip".format(artifacts_directory, locale) for locale in locales) | ||
expected_number_of_screenshots_per_archive = { | ||
"{}/{}.zip".format(artifacts_directory, locale): number_of_screenshots_per_locale[locale] | ||
for locale in locales | ||
} | ||
|
||
expected_archives = set(expected_number_of_screenshots_per_archive.keys()) | ||
if archives != expected_archives: | ||
errors.append( | ||
"The list of archives (zip files) does not match the expected one. Expected: {}. Got: {}.".format( | ||
expected_archives, archives | ||
) | ||
) | ||
|
||
log.info("Processing {} archives...".format(len(archives))) | ||
log.info("Processing {} archives...".format(len(expected_archives))) | ||
log.debug("Archives are expected to have these numbers of screenshots: {}".format(expected_number_of_screenshots_per_archive)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This way we know what the script expects. |
||
|
||
for archive in sorted(archives): # Sorted archives enables sorted error messages | ||
errors.extend(_check_single_archive(archive, expected_number_of_screenshots_per_locale)) | ||
for archive, expected_number_of_screenshots in expected_number_of_screenshots_per_archive.items(): | ||
errors.extend(_check_single_archive(archive, expected_number_of_screenshots)) | ||
|
||
if errors: | ||
error_list = "\n * ".join(errors) | ||
log.critical("Got {} error(s) while verifying screenshots: \n * {}".format(len(errors), error_list)) | ||
# TODO Uncomment the next line once screenshot tests are fixed on all locales. | ||
# sys.exit(_FAILURE_EXIT_CODE) | ||
|
||
log.info("No archive is missing and all of them contain the right number of screenshots") | ||
log.info("No archive is missing and all of them contain the right number of screenshots!") | ||
|
||
|
||
def _filter_out_derived_data_archive(archives): | ||
|
@@ -82,7 +103,7 @@ def _filter_out_derived_data_archive(archives): | |
return filtered_out_archives | ||
|
||
|
||
def _check_single_archive(archive, expected_number_of_screenshots_per_locale): | ||
def _check_single_archive(archive, expected_number_of_screenshots): | ||
errors = [] | ||
|
||
with ZipFile(archive) as zip_file: | ||
|
@@ -93,10 +114,10 @@ def _check_single_archive(archive, expected_number_of_screenshots_per_locale): | |
errors.append('Archive "{}" contains non-png files: {}'.format(archive, non_png_files)) | ||
|
||
actual_number_of_screenshots = len(png_files) | ||
if actual_number_of_screenshots != expected_number_of_screenshots_per_locale: | ||
if actual_number_of_screenshots != expected_number_of_screenshots: | ||
errors.append( | ||
'Archive "{}" does not contain the expected number of screenshots. Expected: {}. Got: {}'.format( | ||
archive, expected_number_of_screenshots_per_locale, actual_number_of_screenshots | ||
archive, expected_number_of_screenshots, actual_number_of_screenshots | ||
) | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think capturing edge cases by defining a list of locales that behave the same way is more maintainable. I thought of making a file that tells how many screenshots each single locale has, but that'll be cumbersome and prone to error to update.