Skip to content

New Feature: Upgrade Peekbot #966

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

Merged
merged 10 commits into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Proxy for using W3C WebDriver compatible clients to interact with Gecko-based br
This program provides the HTTP API described by the WebDriver protocol to communicate with Gecko browsers, such as Firefox.
It translates calls into the Marionette remote protocol by acting as a proxy between the local- and remote ends.

This application was taken from: https://github.com/mozilla/geckodriver/releases/tag/v0.29.1
This application was taken from: https://github.com/mozilla/geckodriver/releases/tag/v0.30.0
Binary file not shown.
59 changes: 57 additions & 2 deletions .github/scripts/build_assets/selenium_runner/SeleniumRunner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pathlib import Path
from selenium.webdriver.common import service

from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
Expand Down Expand Up @@ -69,6 +71,11 @@ class SeleniumRunner:
IcomoonPage.GENERATE_FONT: ICOMOON_URL + "/font"
}

"""
Number of retries for creating a web driver instance.
"""
MAX_RETRY = 5

"""
The different types of alerts that this workflow will encounter.
It contains part of the text in the actual alert and buttons
Expand Down Expand Up @@ -126,6 +133,7 @@ def set_browser_options(self, download_path: str, geckodriver_path: str,
:raises AssertionError: if the page title does not contain
"IcoMoon App".
"""
# customize the download options
options = Options()
allowed_mime_types = "application/zip, application/gzip, application/octet-stream"
# disable prompt to download from Firefox
Expand All @@ -138,15 +146,62 @@ def set_browser_options(self, download_path: str, geckodriver_path: str,
options.headless = headless

print("Activating browser client...")
self.driver = WebDriver(options=options, executable_path=geckodriver_path)
self.driver = self.create_driver_instance(options, geckodriver_path)

self.driver.get(self.ICOMOON_URL)
assert "IcoMoon App" in self.driver.title
# wait until the whole web page is loaded by testing the hamburger input
WebDriverWait(self.driver, self.LONG_WAIT_IN_SEC).until(
ec.element_to_be_clickable((By.XPATH, "(//i[@class='icon-menu'])[2]"))
)
print("Accessed icomoon.io")

def create_driver_instance(self, options: Options, geckodriver_path: str):
"""
Create a WebDriver instance. Isolate retrying code here to address
"no connection can be made" error.
:param options: the FirefoxOptions for the browser.
:param geckodriver_path: the path to the firefox executable.
the icomoon.zip to.
"""
retries = SeleniumRunner.MAX_RETRY
finished = False
driver = None
err_msgs = [] # keep for logging purposes
while not finished and retries > 0:
try:
# order matters, don't change the lines below
finished = True # signal we are done in case we are actually done

# customize the local server
service = None
# first retry: use 8080
# else: random
if retries == SeleniumRunner.MAX_RETRY:
service = Service(executable_path=geckodriver_path, port=8080)
else:
service = Service(executable_path=geckodriver_path)
driver = WebDriver(options=options, service=service)
except SeleniumTimeoutException as e:
# retry. This is intended to catch "no connection could be made" error
retries -= 1
finished = False # flip the var so we can retry
msg = f"Retry {retries}/{SeleniumRunner.MAX_RETRY} SeleniumTimeoutException: {e.msg}"
print(msg)
err_msgs.append(msg)
except Exception as e:
# anything else: unsure if retry works. Just end the retry
msg = f"Retry {retries}/{SeleniumRunner.MAX_RETRY} Exception: {e}"
err_msgs.append(msg)
print(msg)
break

if driver is not None:
return driver

err_msg_formatted = '\n'.join(reversed(err_msgs))
msg = f"Unable to create WebDriver Instance:\n{err_msg_formatted}"
raise Exception(msg)

def switch_toolbar_option(self, option: IcomoonOptionState):
"""
Switch the toolbar option to the option argument.
Expand Down
2 changes: 1 addition & 1 deletion .github/scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
selenium==3.141.0
selenium==4.1.0
requests==2.25.1
10 changes: 5 additions & 5 deletions .github/workflows/peek_icons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: echo $PR_NUM > pr_num.txt

- name: Upload the PR number
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v2.2.4
with:
name: pr_num
path: ./pr_num.txt
Expand All @@ -41,25 +41,25 @@ jobs:
shell: cmd
run: >
python ./.github/scripts/icomoon_peek.py
./.github/scripts/build_assets/geckodriver-v0.29.1-win64/geckodriver.exe ./icomoon.json
./.github/scripts/build_assets/geckodriver-v0.30.0-win64/geckodriver.exe ./icomoon.json
./devicon.json ./icons ./ --headless --pr_title "%PR_TITLE%"

- name: Upload the err messages (created by icomoon_peek.py)
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v2.2.4
if: always()
with:
name: err_messages
path: ./err_messages.txt

- name: Upload screenshots for comments
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v2.2.4
if: success()
with:
name: screenshots
path: ./screenshots/*.png

- name: Upload geckodriver.log for debugging purposes
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v2.2.4
if: failure()
with:
name: geckodriver-log
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/post_peek_screenshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,20 @@ jobs:
Hi there,

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).
{0}

Here are the SVGs as intepreted by Icomoon when we upload the files:
{1}
{0}

Here are the zoomed-in screenshots of the added icons as **SVGs**. This is how Icomoon intepret the uploaded SVGs:
{2}
{1}

Here are the icons that will be generated by Icomoon:
{3}
{2}

Here are the zoomed-in screenshots of the added icons as **icons**. This is what the font will look like:
{3}
{4}

You can click on the pictures and zoom on them if needed.

The maintainers will now check for:
1. The number of Glyphs matches the number of SVGs that were selected.
2. The icons (second group of pictures) look the same as the SVGs (first group of pictures).
Expand All @@ -116,11 +115,11 @@ jobs:
${{
format(
env.MESSAGE,
steps.err_message_reader.outputs.content,
fromJSON(steps.svgs_overview_img_step.outputs.markdown_urls)[0],
join(fromJSON(steps.svgs_detailed_img_step.outputs.markdown_urls), ' '),
fromJSON(steps.icons_overview_img_step.outputs.markdown_urls)[0],
join(fromJSON(steps.icons_detailed_img_step.outputs.markdown_urls), ' ')
join(fromJSON(steps.icons_detailed_img_step.outputs.markdown_urls), ' '),
steps.err_message_reader.outputs.content
)
}}

Expand Down