Skip to content

Commit

Permalink
Html to img (#71)
Browse files Browse the repository at this point in the history
* Create html-to-img.py

* Update generate_svg.sh

* Update generate_svg.sh

* Update generate_svg.sh

* Update generate_svg.sh

* Update generate_svg.sh

* Update generate_svg.sh

* Update html-to-img.py

* Update generate_svg.sh

* Update generate_svg.sh

* finally got the image properly creating

* Theoretically this solves the main deploy issue

* Added concurrency protections

* Added concurrency protections 2

* Added concurrency protections 3
  • Loading branch information
mmilunicmobile authored Jan 10, 2025
1 parent 978e8e2 commit 42bce65
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/statistics.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
name: Statistics Tracker

on:
push
on: [push, workflow_call]

permissions:
pages: write
id-token: write

jobs:

build:
concurrency:
group: statistics-deploy
cancel-in-progress: true
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -19,6 +21,12 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Imgkit
run: |
pip install imgkit
- name: Install wkhtmltopdf
run: |
sudo apt-get install wkhtmltopdf
- name: Generate SVG graphic
id: build
run: bash ./generate_svg.sh
Expand All @@ -28,7 +36,15 @@ jobs:
with:
path: stats_tracker/build/

main-deploy:
if: ${{github.ref != 'refs/heads/main'}}
uses:
FRC2593/javabot-2025/.github/workflows/statistics.yml@main

deploy:
concurrency:
group: statistics-deploy
cancel-in-progress: true
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
Expand Down
Binary file modified stats_tracker/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 1 addition & 8 deletions stats_tracker/generate_svg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,4 @@ echo "Deletion(s): $d"
value=$(($i - $d))
echo "Lines of code: $value"
mkdir build
echo "<svg width=\"300px\" height=\"300px\" xmlns=\"http://www.w3.org/2000/svg\">
<style>
@import url(\"https://fonts.googleapis.com/css?family=Source+Code+Pro\");
</style>
<image href=\"https://frc2539.github.io/javabot-2025/background.png\" width=\"100%\"/>
<text x=\"50%\" y=\"90px\" font-size=\"65\" text-anchor=\"middle\" fill=\"black\" font-family=\"Source Code Pro\" font-weight=\"bold\">$value</text>
</svg>" > build/loc.svg
cp background.png build/background.png
python html-to-img.py $value
32 changes: 32 additions & 0 deletions stats_tracker/html-to-img.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import imgkit
import os
import sys

my_path = os.path.abspath("background.png")

value = sys.argv[1]

f = f"""
<style>
@import url('https://fonts.googleapis.com/css2?family=Source+Code+Pro:ital,wght@0,700;1,700&display=swap');
* {{
margin: 0px;
font-family: "Source Code Pro";
font-optical-sizing: auto;
font-weight: 700;
font-style: normal;
}}
</style>
<div style="width:300px">
<img width="300px" src="{my_path}">
<div style="font-size:65px; position: absolute; top: 20px; left: 0px; width: 300px;">
<div style="margin-left: auto; margin-right: auto; width: min; text-align: center;">{value}</div>
</div>
"""

options = {
"enable-local-file-access": "",
"width": "300",
"height": "163"
}
imgkit.from_string(f, 'build/loc.png', options)

0 comments on commit 42bce65

Please sign in to comment.