ci(icons): upload icons to cloudflare pages #2
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
name: icons.yml | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- v2 | |
paths: | |
- configs/*.json | |
- .github/workflows/icons.yml | |
jobs: | |
icons: | |
runs-on: ubuntu-latest | |
name: 🖼️ Create icons | |
steps: | |
- name: 🛠 setup Node.js | |
uses: actions/setup-node@v4 | |
- name: 📥️ checkout | |
uses: actions/checkout@v4 | |
with: | |
sparse-checkout: | | |
configs | |
- name: 🍱 install converter | |
run: npm install -gy svgexport | |
- name: 🖼️ create icons | |
run: | | |
# create output directories | |
mkdir svg | |
mkdir png | |
# set sizes | |
size=1000 | |
# find configs and print them in a line each | |
jq -nMr '[inputs | select(.icon) | [(input_filename | gsub("^configs/|.json$"; "")), .icon, .github.user, .github.repo, (.github.branch | if . == "" then "main" else . end)] | join("\n")] | join("\n")' configs/*.json | \ | |
# for each config | |
while read -r config; read -r icon; read -r user; read -r repo; read -r branch; do | |
svgname="svg/$config.svg" | |
pngname="png/$config.png" | |
branch=${branch:="main"} | |
moothel="https://raw.githubusercontent.com/$user/$repo/$branch/img/moothel.png" | |
# write svg to a file | |
echo "$config" | |
echo "<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 $size $size'>" > "$svgname" | |
echo " <image x='0' y='0' width='100%' height='100%' preserveAspectRatio='meet' href='$moothel'/>" >> "$svgname" | |
echo " <rect x='66%' y='66%' width='33%' height='33%' fill='white' opacity='0.5'/>" >> "$svgname" | |
echo " <image x='66%' y='66%' width='33%' preserveAspectRatio='xMidYMid meet' href='$icon'/>" >> "$svgname" | |
echo "</svg>" >> "$svgname" | |
# convert to png | |
svgexport "$svgname" "$pngname" | |
done | |
- name: 📤 upload icons | |
uses: actions/upload-artifact@v4 | |
with: | |
name: icons | |
path: png/ | |
- name: 🚀 deploy icons | |
uses: cloudflare/wrangler-action@v3 | |
with: | |
apiToken: ${{ secrets.ICONS_UPLOAD_CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.ICONS_UPLOAD_CLOUDFLARE_ACCOUNT_ID }} | |
command: | | |
pages deploy png --project-name=better-moodle-icons |