-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
80 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: generate-svg-counter | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
generate-counter: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: true | ||
token: ${{ secrets.PUSH_TOKEN }} | ||
|
||
- name: Set up Python 3.11 | ||
uses: actions/[email protected] | ||
with: | ||
python-version: 3.11 | ||
- name: Install Poetry | ||
run: curl -sSL https://install.python-poetry.org | python - | ||
- name: Install dependencies with Poetry | ||
run: poetry install | ||
- name: Generate shields.io URL | ||
run: poetry run python bin/gen_counter.py -f yaml/ | ||
id: counter | ||
- name: Update README | ||
run: | | ||
echo ${{ steps.counter.outputs.result }} | ||
sed -i "s|https://img.shields.io/badge/Drivers-.*-flat.svg|${{ steps.counter.outputs.result }}|" README.md | ||
shell: bash | ||
- name: update github with new site | ||
run: | | ||
# configure git to prep for commit | ||
git config user.email "[email protected]" | ||
git config user.name "publish bot" | ||
git config --global push.default simple | ||
git add README.md | ||
git commit --allow-empty -m "updating drivers count in README.md [ci skip]" | ||
git push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import os | ||
import argparse | ||
import urllib.parse | ||
import yaml | ||
|
||
# Parse command line arguments | ||
parser = argparse.ArgumentParser(description='Generate an SVG counter for a folder with a list of YAML files.') | ||
parser.add_argument('-f', '--folder', metavar='FOLDER', type=str, default='yaml/', help='the folder to search for YAML files (default: yaml/)') | ||
args = parser.parse_args() | ||
|
||
# Find YAML files in the specified folder | ||
sample_count = 0 | ||
for filename in os.listdir(args.folder): | ||
if filename.endswith('.yaml'): | ||
with open(os.path.join(args.folder, filename), 'r') as f: | ||
yaml_data = yaml.safe_load(f) | ||
if yaml_data is not None and 'KnownVulnerableSamples' in yaml_data: | ||
sample_count += len(yaml_data['KnownVulnerableSamples']) | ||
|
||
# Generate the shields.io badge URL | ||
params = { | ||
'label': 'Drivers', | ||
'message': str(sample_count), | ||
'style': 'flat' | ||
} | ||
url = 'https://img.shields.io/badge/{}-{}-{}.svg'.format( | ||
urllib.parse.quote_plus(params['label']), | ||
urllib.parse.quote_plus(params['message']), | ||
urllib.parse.quote_plus(params['style']) | ||
) | ||
|
||
# Save shields URL in Github Output to be used in the next step. | ||
with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: | ||
print(f'result={url}', file=fh) |
This file was deleted.
Oops, something went wrong.
Binary file not shown.