1
0
mirror of https://github.com/konpa/devicon.git synced 2025-07-31 20:00:16 +02:00

Added working workflow file

This commit is contained in:
Thomas Bui
2021-01-10 20:01:50 -08:00
parent d0d101a776
commit 3d2e655f81
6 changed files with 84 additions and 38 deletions

View File

@@ -230,3 +230,11 @@ def get_added_modified_svgs(files_added_json_path: str,
svgs.append(path)
return svgs
def write_to_file(path: str, value: any):
"""
Write the value to a JSON file.
"""
with open(path, "w") as file:
file.write(value)

View File

@@ -2,6 +2,7 @@ from typing import List
import xml.etree.ElementTree as et
from pathlib import Path
import os
import json
import platform
import sys
import traceback
@@ -24,6 +25,8 @@ def check_svgs(svg_file_paths: List[Path]):
The style must not contain any 'fill' declarations.
If any error is found, they will be thrown.
:param: svg_file_paths, the file paths to the svg to check for.
:return: None if there no errors. If there is, return a JSON.stringified
list with the error messages in it.
"""
# batch err messages together so user can fix everything at once
err_msgs = []
@@ -63,7 +66,8 @@ def check_svgs(svg_file_paths: List[Path]):
err_msgs.append("\n".join(err_msg))
if len(err_msgs) > 0:
raise Exception("Errors found in these files:\n" + "\n\n".join(err_msgs))
return "\n\n".join(err_msgs)
return 'None'
def set_env_var(key: str, value: str, delimiter: str='~'):

View File

@@ -11,8 +11,8 @@ from build_assets import util
def main():
"""
Check the quality of the svgs.
If any error is found, set an environmental variable called SVG_ERR_MSGS
that will contains the error messages.
If any svg error is found, create a json file called 'svg_err_messages.json'
in the root folder that will contains the error messages.
"""
args = arg_getters.get_check_svgs_on_pr_args()
try:
@@ -21,10 +21,14 @@ def main():
args.files_modified_json_path)
print("SVGs to check: ", *svgs, sep='\n')
util.check_svgs(svgs)
print("All SVGs found were good. Task completed.")
if len(svgs) == 0:
print("No SVGs to check, ending script.")
return
err_messages = util.check_svgs(svgs)
filehandler.write_to_file("./svg_err_messages.txt", err_messages)
print("Task completed.")
except Exception as e:
util.set_env_var("SVG_ERR_MSGS", str(e))
util.exit_with_err(e)

View File

@@ -6,34 +6,40 @@ jobs:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Setup Python v3.8
uses: actions/setup-python@v2
- uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install dependencies
run: python -m pip install --upgrade pip
- name: Get Changed Files and generate files_added.json & files_modified.json
uses: lots0logs/gh-action-get-changed-files@2.1.4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run the check_svg script
run: >
python ./.github/scripts/check_svgs.py ./icomoon.json ./devicon.json ./icons
- name: Save the error messages in an artifact
shell: bash
run: echo $SVG_ERR_MSGS > err_messages.txt # the $SVG_ERR_MSGS is set by the python script above
python ./.github/scripts/check_svgs_on_pr.py $HOME/files_added.json $HOME/files_modified.json
- name: Upload the err messages
uses: actions/upload-artifact@v2
if: success()
with:
name: err_messages
path: ./err_messages.txt
name: svg_err_messages
path: ./svg_err_messages.txt
- name: Save the pr num in an artifact
shell: bash
if: success()
env:
PR_NUM: ${{ github.event.number }}
run: echo $PR_NUM > pr_num.txt
- name: Upload the pr num
uses: actions/upload-artifact@v2
if: success()
with:
name: pr_num
path: ./pr_num.txt

View File

@@ -1,7 +1,7 @@
name: Post the screenshots into a comment from Peek Icons workflow
name: Post the result of a SVG Check into its PR.
on:
workflow_run:
workflows: ["Check SVGs On PR"]
workflows: ['Check SVGs On PR']
types:
- completed
jobs:
@@ -9,9 +9,10 @@ jobs:
name: Post the screenshot
runs-on: ubuntu-18.04
steps:
- name: Fail the workflow if trigger failed so we can still comment on PR
if: ${{ github.event.workflow_run.conclusion != 'success' }}
run: echo "::error ::Check SVGs On PR workflow failed. Failing script"
- name: Check if the trigger run worked. If it failed, fail the current run.
# this is done cause this script should only post the err message if trigger run failed
if: success() && github.event.workflow_run.conclusion != 'success'
uses: cutenode/action-always-fail@v1.0.1
- name: Download workflow artifact
uses: dawidd6/action-download-artifact@v2.11.0
@@ -21,20 +22,22 @@ jobs:
run_id: ${{ github.event.workflow_run.id }}
- name: Get the PR number and save it in $PR_NUM
if: success()
run: |
echo 'PR_NUM<<EOF' >> $GITHUB_ENV
cat ./pr_num/pr_num.txt >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Get the error messages and save it in $SVG_ERR_MSGS
run: |
echo 'SVG_ERR_MSGS<<EOF' >> $GITHUB_ENV
cat ./err_messages/err_messages.txt >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV
- name: Read the message file
if: success()
id: message_reader
uses: juliangruber/read-file-action@v1.0.0
with:
path: ./svg_err_messages/svg_err_messages.txt
- name: Comment on the PR about the result - Success
uses: jungwinter/comment@v1 # let us comment on a specific PR
id: create
if: success() && steps.message_reader.outputs.content == 'None'
env:
MESSAGE: |
Hi!
@@ -50,20 +53,21 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
body: ${{ env.MESSAGE }}
- name: Comment on the PR about the result - Failure
- name: Comment on the PR about the result - SVG Error
uses: jungwinter/comment@v1 # let us comment on a specific PR
if: success() && steps.message_reader.outputs.content != 'None'
env:
MESSAGE: |
Hi!
I'm Devicons' SVG-Checker Bot and it seems we've ran into a problem. I'm supposed to check your svgs but I couldn't do my task due to an issue.
I'm Devicons' SVG-Checker Bot and it seems we have some issues with your SVGs.
Here is what went wrong:
```
{0}
```
For more reference, check out our [CONTRIBUTING guide](https://github.com/devicons/devicon/blob/develop/CONTRIBUTING.md#svgStandards)
For more reference on why these are errors, check out our [CONTRIBUTING guide](https://github.com/devicons/devicon/blob/develop/CONTRIBUTING.md#svgStandards)
Please address these issues. When you update this PR, I will check your SVGs again.
@@ -71,6 +75,25 @@ jobs:
SVG-Checker Bot :smile:
PS. One day, I will be smart enough to fix these errors for you :persevere:. Until then, I can only point them out.
with:
type: create
issue_number: ${{ env.PR_NUM }}
token: ${{ secrets.GITHUB_TOKEN }}
body: ${{ format(env.MESSAGE, steps.message_reader.outputs.content) }}
- name: Comment on the PR about the result - Failure
uses: jungwinter/comment@v1 # let us comment on a specific PR
if: failure() || cancelled()
env:
MESSAGE: |
Hi!
I'm Devicons' SVG-Checker Bot and it seems we've ran into a problem. I'm supposed to check your svgs but I couldn't do my task due to an issue.
Please let my maintainers know of the issues. They will take a look at my work and try to resolve the problem. Until then, please hang tight and sorry for the inconvenience.
Cheers,
SVG-Checker Bot :smile:
with:
type: create
issue_number: ${{ env.PR_NUM }}

View File

@@ -1,7 +1,7 @@
name: Post the screenshots into a comment from Peek Icons workflow
on:
workflow_run:
workflows: ["Peek Icons"]
workflows: ['Peek Icons']
types:
- completed
jobs:
@@ -9,9 +9,9 @@ jobs:
name: Post the screenshot
runs-on: ubuntu-18.04
steps:
- name: Fail the workflow if trigger failed so we can still comment on PR
if: ${{ github.event.workflow_run.conclusion != 'success' }}
run: echo "::error ::Peek Icons workflow failed. Failing script"
- name: Check if the trigger run worked. If not, fail the current run.
if: github.event.workflow_run.conclusion != 'success'
uses: cutenode/action-always-fail@v1.0.1
- name: Download workflow artifact
uses: dawidd6/action-download-artifact@v2.11.0
@@ -28,14 +28,14 @@ jobs:
- name: Upload screenshot of the newly made icons gotten from the artifacts
id: icons_overview_img_step
uses: devicons/public-upload-to-imgur@v2.2.0
uses: devicons/public-upload-to-imgur@v2.2.1
with:
path: ./screenshots/new_icons.png
client_id: ${{secrets.IMGUR_CLIENT_ID}}
- name: Upload zoomed in screenshot of the newly made icons gotten from the artifacts
id: icons_detailed_img_step
uses: devicons/public-upload-to-imgur@v2.2.0
uses: devicons/public-upload-to-imgur@v2.2.1
if: success()
with:
path: ./screenshots/screenshot_*.png
@@ -43,9 +43,10 @@ jobs:
- name: Comment on the PR about the result - Success
uses: jungwinter/comment@v1 # let us comment on a specific PR
if: success()
env:
OVERVIEW_IMG_URL: ${{ fromJSON(steps.icons_overview_img_step.outputs.markdown_urls)[0] }}
DETAILED_IMGS_URL: ${{ join(fromJSON(steps.icons_detailed_img_step.outputs.markdown_urls), '\n') }}
OVERVIEW_IMG_MARKDOWN: ${{ fromJSON(steps.icons_overview_img_step.outputs.markdown_urls)[0] }}
DETAILED_IMGS_MARKDOWN: ${{ join(fromJSON(steps.icons_detailed_img_step.outputs.markdown_urls), '\n') }}
MESSAGE: |
Hi there,
@@ -72,7 +73,7 @@ jobs:
body: ${{format(env.MESSAGE, env.OVERVIEW_IMG_MARKDOWN, env.DETAILED_IMGS_MARKDOWN)}}
- name: Comment on the PR about the result - Failure
if: failure()
if: failure() || cancelled()
uses: jungwinter/comment@v1 # let us comment on a specific PR
env:
MESSAGE: |