Skip to content

Commit caeb963

Browse files
authored
Release v2.10.0
2 parents 9c6bfdb + 1671b94 commit caeb963

38 files changed

+607
-161
lines changed

.github/scripts/build_assets/filehandler.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -213,20 +213,20 @@ def get_added_modified_svgs(files_added_json_path: str,
213213
Get the svgs added and modified from the files_changed_json_path.
214214
:param: files_added_json_path, the path to the files_added.json created by the [email protected]
215215
:param: files_modified_json_path, the path to the files_modified.json created by the [email protected]
216-
:return: a list of the svg file paths that were added/modified in this pr as Path.
216+
:return: a list of the svg file paths that were added/modified in this pr as Path. It will only return icons in /icons path (see https://github.com/devicons/devicon/issues/505)
217217
"""
218218
files_added = get_json_file_content(files_added_json_path)
219219
files_modified = get_json_file_content(files_modified_json_path)
220220

221221
svgs = []
222222
for file in files_added:
223223
path = Path(file)
224-
if path.suffix.lower() == ".svg":
224+
if path.suffix.lower() == ".svg" and path.as_posix().lower().startswith('icons/'):
225225
svgs.append(path)
226226

227227
for file in files_modified:
228228
path = Path(file)
229-
if path.suffix.lower() == ".svg":
229+
if path.suffix.lower() == ".svg" and path.as_posix().lower().startswith('icons/'):
230230
svgs.append(path)
231231

232232
return svgs

.github/scripts/build_assets/util.py

-57
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
from typing import List
2-
import xml.etree.ElementTree as et
3-
from pathlib import Path
41
import os
5-
import json
62
import platform
73
import sys
84
import traceback
@@ -17,59 +13,6 @@ def exit_with_err(err: Exception):
1713
sys.exit(1)
1814

1915

20-
def check_svgs(svg_file_paths: List[Path]):
21-
"""
22-
Check the width, height, viewBox and style of each svgs passed in.
23-
The viewBox must be '0 0 128 128'.
24-
If the svg has a width and height attr, ensure it's '128px'.
25-
The style must not contain any 'fill' declarations.
26-
If any error is found, they will be thrown.
27-
:param: svg_file_paths, the file paths to the svg to check for.
28-
:return: None if there no errors. If there is, return a JSON.stringified
29-
list with the error messages in it.
30-
"""
31-
# batch err messages together so user can fix everything at once
32-
err_msgs = []
33-
for svg_path in svg_file_paths:
34-
tree = et.parse(svg_path)
35-
root = tree.getroot()
36-
namespace = "{http://www.w3.org/2000/svg}"
37-
err_msg = [f"{svg_path.name}:"]
38-
39-
if root.tag != f"{namespace}svg":
40-
err_msg.append(f"-root is '{root.tag}'. Root must be an 'svg' element")
41-
42-
if root.get("viewBox") != "0 0 128 128":
43-
err_msg.append("-'viewBox' is not '0 0 128 128' -> Set it or scale the file using https://www.iloveimg.com/resize-image/resize-svg")
44-
45-
acceptable_size = [None, "128px", "128"]
46-
if root.get("height") not in acceptable_size:
47-
err_msg.append("-'height' is present in svg element but is not '128' or '128px' -> Remove it or set it to '128' or '128px'")
48-
49-
if root.get("width") not in acceptable_size:
50-
err_msg.append("-'width' is present in svg element but is not '128' or '128px' -> Remove it or set it to '128' or '128px'")
51-
52-
if root.get("style") is not None and "enable-background" in root.get("style"):
53-
err_msg.append("-deprecated 'enable-background' in style attribute -> Remove it")
54-
55-
if root.get("x") is not None:
56-
err_msg.append("-unneccessary 'x' attribute in svg element -> Remove it")
57-
58-
if root.get("y") is not None:
59-
err_msg.append("-unneccessary 'y' attribute in svg element -> Remove it")
60-
61-
style = root.findtext(f".//{namespace}style")
62-
if style != None and "fill" in style:
63-
err_msg.append("-contains style declaration using 'fill' -> Replace classes with the 'fill' attribute instead")
64-
65-
if len(err_msg) > 1:
66-
err_msgs.append("\n".join(err_msg))
67-
68-
if len(err_msgs) > 0:
69-
return "\n\n".join(err_msgs)
70-
return 'None'
71-
72-
7316
def set_env_var(key: str, value: str, delimiter: str='~'):
7417
"""
7518
Set the GitHub env variable of 'key' to 'value' using

.github/scripts/check_svgs_on_pr.py

+69-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import sys
2-
import time
1+
from enum import Enum
2+
from typing import List
3+
import xml.etree.ElementTree as et
4+
from pathlib import Path
35

46

57
# pycharm complains that build_assets is an unresolved ref
@@ -8,6 +10,14 @@
810
from build_assets import util
911

1012

13+
class SVG_STATUS_CODE(Enum):
14+
"""
15+
The status codes to check for in post_check_svgs_comment.yml
16+
"""
17+
NO_SVG = 0 # action: do nothing
18+
SVG_OK = 1 # action: let user know their svgs are fine
19+
20+
1121
def main():
1222
"""
1323
Check the quality of the svgs.
@@ -23,14 +33,68 @@ def main():
2333

2434
if len(svgs) == 0:
2535
print("No SVGs to check, ending script.")
26-
return
36+
err_messages = SVG_STATUS_CODE.NO_SVG.value
37+
else:
38+
err_messages = check_svgs(svgs)
2739

28-
err_messages = util.check_svgs(svgs)
29-
filehandler.write_to_file("./svg_err_messages.txt", err_messages)
40+
filehandler.write_to_file("./svg_err_messages.txt", str(err_messages))
3041
print("Task completed.")
3142
except Exception as e:
3243
util.exit_with_err(e)
3344

3445

46+
def check_svgs(svg_file_paths: List[Path]):
47+
"""
48+
Check the width, height, viewBox and style of each svgs passed in.
49+
The viewBox must be '0 0 128 128'.
50+
If the svg has a width and height attr, ensure it's '128px'.
51+
The style must not contain any 'fill' declarations.
52+
If any error is found, they will be thrown.
53+
:param: svg_file_paths, the file paths to the svg to check for.
54+
:return: None if there no errors. If there is, return a JSON.stringified
55+
list with the error messages in it.
56+
"""
57+
# batch err messages together so user can fix everything at once
58+
err_msgs = []
59+
for svg_path in svg_file_paths:
60+
tree = et.parse(svg_path)
61+
root = tree.getroot()
62+
namespace = "{http://www.w3.org/2000/svg}"
63+
err_msg = [f"{svg_path}:"]
64+
65+
if root.tag != f"{namespace}svg":
66+
err_msg.append(f"-root is '{root.tag}'. Root must be an 'svg' element")
67+
68+
if root.get("viewBox") != "0 0 128 128":
69+
err_msg.append("-'viewBox' is not '0 0 128 128' -> Set it or scale the file using https://www.iloveimg.com/resize-image/resize-svg")
70+
71+
acceptable_size = [None, "128px", "128"]
72+
if root.get("height") not in acceptable_size:
73+
err_msg.append("-'height' is present in svg element but is not '128' or '128px' -> Remove it or set it to '128' or '128px'")
74+
75+
if root.get("width") not in acceptable_size:
76+
err_msg.append("-'width' is present in svg element but is not '128' or '128px' -> Remove it or set it to '128' or '128px'")
77+
78+
if root.get("style") is not None and "enable-background" in root.get("style"):
79+
err_msg.append("-deprecated 'enable-background' in style attribute -> Remove it")
80+
81+
if root.get("x") is not None:
82+
err_msg.append("-unneccessary 'x' attribute in svg element -> Remove it")
83+
84+
if root.get("y") is not None:
85+
err_msg.append("-unneccessary 'y' attribute in svg element -> Remove it")
86+
87+
style = root.findtext(f".//{namespace}style")
88+
if style != None and "fill" in style:
89+
err_msg.append("-contains style declaration using 'fill' -> Replace classes with the 'fill' attribute instead")
90+
91+
if len(err_msg) > 1:
92+
err_msgs.append("\n".join(err_msg))
93+
94+
if len(err_msgs) > 0:
95+
return "\n\n".join(err_msgs)
96+
return SVG_STATUS_CODE.SVG_OK.value
97+
98+
3599
if __name__ == "__main__":
36100
main()

.github/workflows/npm_publish.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
on:
2+
release:
3+
types: [released]
4+
jobs:
5+
publish:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
with:
10+
# "ref" specifies the branch to check out.
11+
# "github.event.release.target_commitish" is a global variable and specifies the branch the release targeted
12+
ref: ${{ github.event.release.target_commitish }}
13+
- name: Use Node.js 12
14+
uses: actions/setup-node@v1
15+
with:
16+
node-version: 12
17+
registry-url: https://registry.npmjs.org/ # Specifies the registry, this field is required!
18+
- run: npm ci
19+
- run: npm publish
20+
env:
21+
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTOMATION_TOKEN }}

.github/workflows/post_check_svgs_comment.yml

+8-9
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ on:
55
types:
66
- completed
77
jobs:
8-
post_screenshots_in_comment:
9-
name: Post the screenshot
8+
post_result_of_svg_check:
9+
name: Post the result of the Check SVG Action
1010
runs-on: ubuntu-18.04
1111
steps:
1212
- name: Check if the trigger run worked. If it failed, fail the current run.
13-
if: success() && github.event.workflow_run.conclusion != 'success'
13+
if: github.event.workflow_run.conclusion != 'success'
1414
uses: cutenode/[email protected]
1515

1616
- name: Download workflow artifact
1717
uses: dawidd6/[email protected]
18+
if: success()
1819
with:
1920
github_token: ${{ secrets.GITHUB_TOKEN }}
2021
workflow: peek_icons.yml
@@ -36,13 +37,11 @@ jobs:
3637

3738
- name: Comment on the PR about the result - Success
3839
uses: jungwinter/comment@v1 # let us comment on a specific PR
39-
if: success() && steps.err_message_reader.outputs.content == 'None'
40+
if: success() && steps.err_message_reader.outputs.content == '1'
4041
env:
4142
MESSAGE: |
4243
Hi!
43-
I'm Devicons' SVG-Checker Bot and I just checked all the SVGs in this branch.
44-
45-
Everything looks great. Good job!
44+
I'm Devicons' SVG-Checker Bot and everything looks great. Good job!
4645
4746
Have a nice day,
4847
SVG-Checker Bot :grin:
@@ -54,7 +53,7 @@ jobs:
5453

5554
- name: Comment on the PR about the result - SVG Error
5655
uses: jungwinter/comment@v1 # let us comment on a specific PR
57-
if: success() && steps.err_message_reader.outputs.content != 'None'
56+
if: success() && (steps.err_message_reader.outputs.content != '0' || steps.err_message_reader.outputs.content != '1')
5857
env:
5958
MESSAGE: |
6059
Hi!
@@ -82,7 +81,7 @@ jobs:
8281

8382
- name: Comment on the PR about the result - Failure
8483
uses: jungwinter/comment@v1 # let us comment on a specific PR
85-
if: failure() || cancelled()
84+
if: failure()
8685
env:
8786
MESSAGE: |
8887
Hi!

.github/workflows/post_peek_screenshot.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ jobs:
4747
if: success()
4848
env:
4949
OVERVIEW_IMG_MARKDOWN: ${{ fromJSON(steps.icons_overview_img_step.outputs.markdown_urls)[0] }}
50-
DETAILED_IMGS_MARKDOWN: ${{ join(fromJSON(steps.icons_detailed_img_step.outputs.markdown_urls), '\n') }}
50+
DETAILED_IMGS_MARKDOWN: ${{ join(fromJSON(steps.icons_detailed_img_step.outputs.markdown_urls), '') }}
5151
MESSAGE: |
5252
Hi there,
5353
5454
I'm Devicons' Peek Bot and I just peeked at the icons that you wanted to add using [icomoon.io](https://icomoon.io/app/#/select).
5555
Here is the result below:
5656
57-
![Peeked Icons (top left)]({0})
57+
{0}
5858
5959
Here are the zoomed-in screenshots of the added icons:
6060
{1}

CONTRIBUTING.md

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ First of all, thanks for taking the time to contribute! This project can only gr
8181
<li>Each <code>.svg</code> file contains one version of an icon in a <code>0 0 128 128</code> viewbox. You can use a service like <a href="https://www.iloveimg.com/resize-image/resize-svg">resize-image</a> for scaling the svg.</li>
8282
<li>The <code>svg</code> element does not need the <code>height</code> and <code>width</code> attributes. However, if you do use it, ensure their values are either <code>"128"</code> or <code>"128px"</code>. Ex: <code>height="128"</code></li>
8383
<li>Each <code>.svg</code> must use the <code>fill</code> attribute instead of using <code>classes</code> for colors. See <a href="https://github.com/devicons/devicon/issues/407">here</a> for more details.</li>
84+
<li>The naming convention for the svg file is the following: <code>(Icon name)-(original|plain|line)(-wordmark?).</code></li>
8485
</ul>
8586

8687
<hr>
@@ -259,4 +260,5 @@ As an example, let's assume you have created the svgs for Redhat and Amazon Web
259260
<li>Ensure code quality is up to standard</li>
260261
<li>Upload svgs to <a href="https://icomoon.io/app/#/select">icomoon.io</a> and take a screenshot to check that it looks good.
261262
<li>Comment on the PR so maintainers don't have to manually upload icon result.</li>
263+
<li>Publishing a new release to <a href="https://www.npmjs.com/package/devicon">npm</a>; See <a href="https://github.com/devicons/devicon/issues/288">#288</a></li>
262264
</ul>

0 commit comments

Comments
 (0)