Skip to content

Commit 8a5ff05

Browse files
committed
Various bug fixes and reference update
1 parent eb6884d commit 8a5ff05

8 files changed

Lines changed: 61 additions & 32 deletions

File tree

.github/scripts/build_assets/util.py renamed to .github/scripts/build_assets/arg_getters.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from argparse import ArgumentParser
22
from build_assets.PathResolverAction import PathResolverAction
33

4-
def get_commandline_args(peek_mode=False):
4+
def get_selenium_runner_args(peek_mode=False):
55
parser = ArgumentParser(description="Upload svgs to Icomoon to create icon files.")
66

77
parser.add_argument("--headless",
@@ -33,3 +33,12 @@ def get_commandline_args(peek_mode=False):
3333
help="The title of the PR that we are peeking at")
3434

3535
return parser.parse_args()
36+
37+
38+
def get_generate_markdown_args():
39+
parser = ArgumentParser(description="Generate markdown for the image urls passed in.")
40+
41+
parser.add_argument("img_urls",
42+
help="The urls of the images. Must be the string/JSON form of an array. Ex: '[1,2,3]'")
43+
44+
return parser.parse_args()

.github/scripts/build_assets/filehandler.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def rename_extracted_files(extract_path: str):
147147
print("Files renamed")
148148

149149

150-
def create_screenshot_folder(dir, screenshot_name: str="screenshots"):
150+
def create_screenshot_folder(dir, screenshot_name: str="screenshots/"):
151151
"""
152152
Create a screenshots folder in the dir.
153153
:param dir, the dir where we want to create the folder.
@@ -158,5 +158,11 @@ def create_screenshot_folder(dir, screenshot_name: str="screenshots"):
158158
folder = Path(dir).resolve()
159159
if not folder.is_dir():
160160
raise Exception(f"This is not a dir: {str(folder)}. \ndir must be a valid directory")
161-
folder.mkdir(screenshot_name, exist_ok=True)
162-
return str(folder)
161+
162+
screenshot_folder = Path(folder, screenshot_name)
163+
try:
164+
os.mkdir(screenshot_folder)
165+
except FileExistsError:
166+
print(f"{screenshot_folder} already exist. Script will do nothing.")
167+
finally:
168+
return str(screenshot_folder)

.github/scripts/generate_screenshot_markdown.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from typing import List
22

3+
from build_assets import arg_getters
4+
35

46
def generate_screenshot_markdown(img_urls: List[str]):
57
"""
@@ -12,5 +14,6 @@ def generate_screenshot_markdown(img_urls: List[str]):
1214

1315

1416
if __name__ == "__main__":
15-
markdown = generate_screenshot_markdown()
17+
args = arg_getters.get_generate_markdown_args()
18+
markdown = generate_screenshot_markdown(args.img_urls)
1619
print("\n\n".join(markdown)) # format it before printing

.github/scripts/icomoon_build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# pycharm complains that build_assets is an unresolved ref
55
# don't worry about it, the script still runs
66
from build_assets.SeleniumRunner import SeleniumRunner
7-
from build_assets import filehandler, util
7+
from build_assets import filehandler, arg_getters
88

99

1010
def main():
11-
args = util.get_commandline_args()
11+
args = arg_getters.get_selenium_runner_args()
1212
new_icons = filehandler.find_new_icons(args.devicon_json_path, args.icomoon_json_path)
1313
if len(new_icons) == 0:
1414
print("No files need to be uploaded. Ending script...")

.github/scripts/icomoon_peek.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
from os import sep
21
from typing import List
32
import re
43
from selenium.common.exceptions import TimeoutException
54

65
# pycharm complains that build_assets is an unresolved ref
76
# don't worry about it, the script still runs
87
from build_assets.SeleniumRunner import SeleniumRunner
9-
from build_assets import filehandler, util
8+
from build_assets import filehandler, arg_getters
109

1110

1211
def main():
13-
args = util.get_commandline_args(True)
12+
args = arg_getters.get_selenium_runner_args(True)
1413
new_icons = filehandler.find_new_icons(args.devicon_json_path, args.icomoon_json_path)
15-
if len(new_icons) == 0:
16-
print("No files need to be uploaded. Ending script...")
17-
return
1814

1915
# get only the icon object that has the name matching the pr title
2016
filtered_icons = find_object_added_in_this_pr(new_icons, args.pr_title)
@@ -23,11 +19,19 @@ def main():
2319
print("List of new icons:", *new_icons, sep = "\n")
2420
print("Icons being uploaded:", *filtered_icons, sep = "\n")
2521

22+
if len(new_icons) == 0:
23+
print("No files need to be uploaded. Ending script...")
24+
return
25+
26+
screenshot_folder = filehandler.create_screenshot_folder("./")
27+
if len(filtered_icons) == 0:
28+
print("No icons found matching the icon name in the PR's title. Fallback to uploading all new icons found.")
29+
screenshot_folder = ""
30+
2631
runner = None
2732
try:
2833
runner = SeleniumRunner(args.download_path, args.geckodriver_path, args.headless)
2934
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path)
30-
screenshot_folder = filehandler.create_screenshot_folder("./")
3135
runner.upload_svgs(svgs, screenshot_folder)
3236
print("Task completed.")
3337
except TimeoutException as e:

.github/workflows/build_icons.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ jobs:
2525
./devicon.json ./icons ./ --headless
2626
- name: Upload geckodriver.log for debugging purposes
2727
uses: actions/upload-artifact@v2
28-
if: ${{failure()}}
28+
if: failure()
2929
with:
3030
name: geckodriver-log
3131
path: ./geckodriver.log
3232
- name: Build devicon.min.css
33-
if: ${{ success() }}
33+
if: success()
3434
run: npm run build-css
3535
- name: Upload screenshot of the newly made icons
3636
id: imgur_step
37-
uses: devicons/public-upload-to-imgur@v1
38-
if: ${{success()}}
37+
uses: devicons/public-upload-to-imgur@v1.1.2
38+
if: success()
3939
with:
40-
img_path: ./new_icons.png
40+
path: ./new_icons.png
4141
client_id: ${{secrets.IMGUR_CLIENT_ID}}
4242
- name: Create Pull Request
43-
if: ${{ success() }}
43+
if: success()
4444
uses: peter-evans/create-pull-request@v3
4545
env:
4646
MESSAGE: |

.github/workflows/peek_icons.yml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,39 @@ jobs:
2323
- name: Run icomoon_peek.py
2424
env:
2525
PR_TITLE: ${{ github.event.pull_request.title }}
26+
shell: cmd
2627
run: >
2728
python ./.github/scripts/icomoon_peek.py
2829
./.github/scripts/build_assets/geckodriver-v0.27.0-win64/geckodriver.exe ./icomoon.json
29-
./devicon.json ./icons ./ --headless --pr_title $PR_TITLE
30+
./devicon.json ./icons ./ --headless --pr_title "%PR_TITLE%"
3031
- name: Upload geckodriver.log for debugging purposes
3132
uses: actions/upload-artifact@v2
32-
if: ${{failure()}}
33+
if: failure()
3334
with:
3435
name: geckodriver-log
3536
path: ./geckodriver.log
3637
- name: Upload screenshot of the newly made icons
3738
id: new_icons_overview_step
38-
uses: devicons/public-upload-to-imgur@v1.1
39-
if: ${{success()}}
39+
uses: devicons/public-upload-to-imgur@main
40+
if: success()
4041
with:
41-
img_path: ./screenshots/new_icons.png
42+
path: ./screenshots/new_icons.png
4243
client_id: ${{secrets.IMGUR_CLIENT_ID}}
4344
- name: Upload zoomed in screenshot of the newly made icons
4445
id: new_icons_detailed_step
45-
uses: devicons/public-upload-to-imgur@v1.1
46-
if: ${{success()}}
46+
uses: devicons/public-upload-to-imgur@main
47+
if: success()
4748
with:
48-
img_path: ./screenshots/screenshot_*.png
49+
path: ./screenshots/screenshot_*.png
4950
client_id: ${{secrets.IMGUR_CLIENT_ID}}
50-
- name: Generate the markdowns for the screenshot
51-
run: |
51+
- name: Generate the markdowns for the screenshot and put it in the DETAILED_IMGS_MARKDOWN env var
52+
env:
53+
IMG_URLS: ${{ steps.new_icons_detailed_step.outputs.img_url }}
54+
run: |
5255
echo "DETAILED_IMGS_MARKDOWN<<EOF" >> $GITHUB_ENV
53-
python ./.github/scripts/generate_screenshot_markdown.py >> $GITHUB_ENV
56+
python ./.github/scripts/generate_screenshot_markdown.py "%IMG_URLS%" >> $GITHUB_ENV
5457
echo "EOF" >> $GITHUB_ENV
58+
shell: cmd
5559
- name: Comment on the PR about the result
5660
uses: github-actions-up-and-running/pr-comment@v1.0.1
5761
env:

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"description": "Programming related icons collection",
55
"main": "devicon.min.css",
66
"scripts": {
7-
"build-css": "gulp updateCss && gulp clean"
7+
"build-css": "gulp updateCss && gulp clean",
8+
"peek-test": "python ./.github/scripts/icomoon_peek.py ./.github/scripts/build_assets/geckodriver-v0.27.0-win64/geckodriver.exe ./icomoon.json ./devicon.json ./icons ./ --pr_title \"%PR_TITLE%\"",
9+
"build-test": "python ./.github/scripts/icomoon_build.py ./.github/scripts/build_assets/geckodriver-v0.27.0-win64/geckodriver.exe ./icomoon.json ./devicon.json ./icons ./"
10+
811
},
912
"repository": {
1013
"type": "git",

0 commit comments

Comments
 (0)