Skip to content

Commit b079a9f

Browse files
github-actions[bot]Filippo
and
Filippo
authored
Update Firefox icons from Acorn repo (#22526)
* Updated Icons from Acorn repo * Update acorn icons script with single source of thruth * Update sync acorn icons script to take into account ExtraSmall size * Add documentation for sync_acorns_icons.py as file header --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Filippo <fzazzeroni@mozilla.com>
1 parent 4f42ea9 commit b079a9f

File tree

2 files changed

+73
-30
lines changed

2 files changed

+73
-30
lines changed

latest_acorn_release.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"url": "https://api.github.com/repos/FirefoxUX/acorn-icons/releases/177905895",
3-
"assets_url": "https://api.github.com/repos/FirefoxUX/acorn-icons/releases/177905895/assets",
4-
"upload_url": "https://uploads.github.com/repos/FirefoxUX/acorn-icons/releases/177905895/assets{?name,label}",
5-
"html_url": "https://github.com/FirefoxUX/acorn-icons/releases/tag/v1.23.0",
6-
"id": 177905895,
2+
"url": "https://api.github.com/repos/FirefoxUX/acorn-icons/releases/178987114",
3+
"assets_url": "https://api.github.com/repos/FirefoxUX/acorn-icons/releases/178987114/assets",
4+
"upload_url": "https://uploads.github.com/repos/FirefoxUX/acorn-icons/releases/178987114/assets{?name,label}",
5+
"html_url": "https://github.com/FirefoxUX/acorn-icons/releases/tag/v1.24.0",
6+
"id": 178987114,
77
"author": {
88
"login": "cwzilla",
99
"id": 87655586,
@@ -24,16 +24,16 @@
2424
"type": "User",
2525
"site_admin": false
2626
},
27-
"node_id": "RE_kwDOI1CID84KmqDn",
28-
"tag_name": "v1.23.0",
27+
"node_id": "RE_kwDOI1CID84KqyBq",
28+
"tag_name": "v1.24.0",
2929
"target_commitish": "main",
30-
"name": "v1.23.0",
30+
"name": "v1.24.0",
3131
"draft": false,
3232
"prerelease": false,
33-
"created_at": "2024-10-01T23:07:12Z",
34-
"published_at": "2024-10-01T23:11:26Z",
33+
"created_at": "2024-10-08T20:56:01Z",
34+
"published_at": "2024-10-08T20:56:53Z",
3535
"assets": [],
36-
"tarball_url": "https://api.github.com/repos/FirefoxUX/acorn-icons/tarball/v1.23.0",
37-
"zipball_url": "https://api.github.com/repos/FirefoxUX/acorn-icons/zipball/v1.23.0",
38-
"body": "# Changelog\r\n## [1.23.0]\r\n### Added\r\n- SVG\r\n - folder-arrow-right-24.svg\r\n\r\n- XML\r\n - ic_folder_arrow_right_24.xml"
36+
"tarball_url": "https://api.github.com/repos/FirefoxUX/acorn-icons/tarball/v1.24.0",
37+
"zipball_url": "https://api.github.com/repos/FirefoxUX/acorn-icons/zipball/v1.24.0",
38+
"body": "# Changelog\r\n## [1.24.0]\r\n### Added\r\n\r\n- PDF\r\n - chevronDownExtraSmall.pdf\r\n - thumbsDownFillLarge.pdf\r\n - thumbsUpFillLarge.pdf\r\n\r\n- SVG\r\n - thumbs-down-fill-24.svg\r\n - thumbs-up-fill-24.svg\r\n\r\n- XML\r\n - ic_thumbs_down_fill_24.xml\r\n - ic_thumbs_up_fill_24.xml"
3939
}

sync_acorn_icons.py

+60-17
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,41 @@
44
import shutil
55
import subprocess
66

7+
"""
8+
This script automates the process of fetching, syncing, and organizing Acorn icons for the Firefox iOS project.
9+
It performs the following tasks:
10+
1. Fetches the latest release of the Acorn icons repository from GitHub.
11+
2. Saves the latest release information locally to detect if a new release needs to be synced.
12+
3. Downloads the icons from the latest release and synchronizes them with the project's asset folder.
13+
4. Sorts icons into categories based on their size (e.g., ExtraSmall, Small, Large, etc.).
14+
5. Generates the StandardImageIdentifiers.swift from BrowserKit's Common package.
15+
16+
Important:
17+
- If a new size needs to be added, modify the `TARGET_SIZES` list by adding the appropriate tuple item.
18+
The tuple is composed of:
19+
- The first item: the directory name where the Acorn icons for that size are stored (e.g., for the "ExtraSmall" category,
20+
the icons are stored in `mobile/8`).
21+
- The second item: the size category used in the file names and in the `StandardImageIdentifiers.swift` structures (e.g., "ExtraSmall").
22+
23+
Usage:
24+
- This script is designed to be run periodically by a Github action.
25+
- It will automatically detect and download new releases, update the asset folder, and regenerate the image identifiers.
26+
27+
If you want to test the script locally make sure to have all the required packages installed and remove the root json file `latest_acorn_release.json`.
28+
Then run `python3 sync_acorn_icons.py`. All the time the script is run the `latest_acorn_release.json` is created so if you see nothing in the console
29+
remove this file first.
30+
"""
31+
32+
# List the target sizes that now are supported from FXIOS
33+
# Only those sizes are synced for updates.
34+
TARGET_SIZES = [
35+
("8", "ExtraSmall"),
36+
("16", "Small"),
37+
("20", "Medium"),
38+
("24", "Large"),
39+
("30", "ExtraLarge")
40+
]
41+
742
def fetch_latest_release_from_acorn() -> dict|None:
843
owner = "FirefoxUX"
944
repo = "acorn-icons"
@@ -52,10 +87,10 @@ def download_icons_and_save_in_assets():
5287
if clone_response.returncode != 0:
5388
print(f"Couldn't clone acorn icon repository")
5489
exit()
55-
target_size_to_copy = [16, 20, 24, 30]
5690
asset_folder_path = "../firefox-ios/Client/Assets/Images.xcassets/"
5791
asset_folder_list = os.listdir(asset_folder_path)
58-
for size in target_size_to_copy:
92+
sizes_to_copy = map(lambda x: x[0], TARGET_SIZES)
93+
for size in sizes_to_copy:
5994
icons_dir_path = f"acorn-icons/icons/mobile/{size}/pdf"
6095
directory_tree = os.walk(icons_dir_path)
6196

@@ -78,22 +113,34 @@ def download_icons_and_save_in_assets():
78113
subprocess.run(["rm", "-rf", temp_dir_folder_name])
79114

80115
def sort_icons_by_size() -> dict:
81-
icons_by_size: dict[str, list[tuple[str]]] = {
82-
"Small": [],
83-
"Medium": [],
84-
# Extra Large should be before Large since next() will pick Large also for ExtraLarge case
85-
"ExtraLarge": [],
86-
"Large": []
87-
}
116+
'''
117+
Sort all the Acorns icons in firefox-ios/Client/Assets/Images.xcassets/ by their respective size
118+
119+
Returns:
120+
dict: A dictionary with the title sizes as key and as value the list of acorn folders with the respective size
121+
{
122+
"ExtraSmall": [],
123+
"Small": [],
124+
...
125+
}
126+
'''
127+
icons_by_size = {}
128+
for _, titleSize in TARGET_SIZES:
129+
icons_by_size[titleSize] = []
88130

89131
asset_folder_path = "firefox-ios/Client/Assets/Images.xcassets/"
90132
for folder in os.listdir(asset_folder_path):
91133
if folder.endswith(".imageset"):
92134
file_name = folder.split(".")[0]
93-
135+
94136
size_key = next((key for key in icons_by_size if key in file_name), None)
95137

96138
if size_key:
139+
# Check wether Extra not in the size_key while the file name has Extra size
140+
# this means the next method pulled the wrong size_key
141+
if "Extra" not in size_key and "Extra" in file_name:
142+
size_key = f"Extra{size_key}"
143+
97144
icon_name = file_name.replace(size_key, "")
98145
icons_by_size[size_key].append((icon_name, file_name))
99146

@@ -111,13 +158,9 @@ def generate_standard_image_identifiers_swift(sorted_icons: dict):
111158
/// Sing the song if you must.
112159
public struct StandardImageIdentifiers {
113160
"""
114-
115-
size_struct_map = {
116-
"Small": "16x16",
117-
"Medium": "20x20",
118-
"Large": "24x24",
119-
"ExtraLarge": "30x30"
120-
}
161+
size_struct_map = {}
162+
for image_size, image_size_title in TARGET_SIZES:
163+
size_struct_map[image_size_title] = f"{image_size}x{image_size}"
121164

122165
for size, struct_name in size_struct_map.items():
123166
if sorted_icons[size]:

0 commit comments

Comments
 (0)