mirror of
https://github.com/walkxcode/dashboard-icons.git
synced 2025-10-26 13:09:04 +08:00
135 lines
5.9 KiB
YAML
135 lines
5.9 KiB
YAML
name: "[Icon] Icon addition approved"
|
|
on:
|
|
issues:
|
|
types: [labeled]
|
|
|
|
jobs:
|
|
add-icon:
|
|
runs-on: ubuntu-latest
|
|
# This condition ensures the job only runs when the 'approved' label is added and the issue title starts with 'feat(icons): add '
|
|
if: |
|
|
contains(github.event.issue.labels.*.name, 'approved') &&
|
|
startsWith(github.event.issue.title, 'feat(icons): add ')
|
|
env:
|
|
ICON_TYPE: ${{ contains(github.event.issue.labels.*.name, 'normal-icon') && 'normal' || 'monochrome' }}
|
|
steps:
|
|
- name: Obtain token
|
|
id: obtainToken
|
|
uses: tibdex/github-app-token@v2
|
|
with:
|
|
private_key: ${{ secrets.DASHBOARD_ICONS_MANAGER_APP_PRIVATE_KEY }}
|
|
app_id: ${{ vars.DASHBOARD_ICONS_MANAGER_APP_ID }}
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
env:
|
|
GITHUB_TOKEN: ${{ steps.obtainToken.outputs.token }}
|
|
- name: Set Up Python
|
|
uses: actions/setup-python@v4
|
|
with:
|
|
python-version: "3.11"
|
|
- name: Install Dependencies
|
|
run: |
|
|
pip install cairosvg pillow requests
|
|
sudo apt-get update
|
|
sudo apt-get install -y zopfli webp
|
|
- name: Parse issue form
|
|
id: parse_issue_form
|
|
run: echo "ISSUE_FORM=$(python scripts/parse_issue_form.py)" >> "$GITHUB_OUTPUT"
|
|
env:
|
|
INPUT_ISSUE_BODY: ${{ github.event.issue.body }}
|
|
- name: Validate Categories
|
|
run: |
|
|
import json
|
|
import sys
|
|
import os
|
|
|
|
# Load allowed categories from metadata.map.json
|
|
map_file = "metadata.map.json"
|
|
try:
|
|
with open(map_file, 'r', encoding='utf-8') as f:
|
|
map_data = json.load(f)
|
|
# Assuming the first key in the map holds the example structure
|
|
example_key = list(map_data.keys())[0]
|
|
allowed_categories = set(map_data[example_key]['categories'])
|
|
print(f"Loaded {len(allowed_categories)} allowed categories from {map_file}")
|
|
except Exception as e:
|
|
print(f"::error file={map_file}::Failed to load or parse allowed categories from {map_file}: {e}")
|
|
sys.exit(1)
|
|
|
|
# Load submitted form data
|
|
form_json_string = os.environ.get('INPUT_ISSUE_FORM')
|
|
if not form_json_string:
|
|
print("::error::Failed to get form JSON from environment variable.")
|
|
sys.exit(1)
|
|
|
|
try:
|
|
form_data = json.loads(form_json_string)
|
|
except json.JSONDecodeError as e:
|
|
print(f"::error::Failed to parse form JSON: {e}")
|
|
print(f"Form JSON string was: {form_json_string}")
|
|
sys.exit(1)
|
|
|
|
# Extract submitted categories (handle potential missing key or None value)
|
|
submitted_categories_str = form_data.get('Categories') # Label from issue form
|
|
submitted_categories = set()
|
|
if submitted_categories_str:
|
|
submitted_categories = set(cat.strip() for cat in submitted_categories_str.split('\\n') if cat.strip())
|
|
|
|
print(f"Submitted categories: {submitted_categories or 'None'}")
|
|
|
|
# Validate
|
|
invalid_categories = submitted_categories - allowed_categories
|
|
|
|
if invalid_categories:
|
|
print(f"::error::Invalid categories found: {', '.join(sorted(list(invalid_categories)))}")
|
|
print("Please ensure all submitted categories exist in metadata.map.json.")
|
|
sys.exit(1)
|
|
else:
|
|
print("All submitted categories are valid.")
|
|
|
|
env:
|
|
INPUT_ISSUE_FORM: ${{ steps.parse_issue_form.outputs.ISSUE_FORM }}
|
|
- name: Create metadata file
|
|
run: python scripts/generate_metadata_file.py ${{ env.ICON_TYPE }} addition
|
|
env:
|
|
INPUT_ISSUE_FORM: ${{ steps.parse_issue_form.outputs.ISSUE_FORM }}
|
|
INPUT_ISSUE_AUTHOR_ID: ${{ github.event.issue.user.id }}
|
|
INPUT_ISSUE_AUTHOR_LOGIN: ${{ github.event.issue.user.login }}
|
|
- name: Generate icons
|
|
run: python scripts/generate_icons.py ${{ env.ICON_TYPE }} addition
|
|
env:
|
|
INPUT_ISSUE_FORM: ${{ steps.parse_issue_form.outputs.ISSUE_FORM }}
|
|
- name: Generate File Tree
|
|
run: python scripts/generate_file_tree.py svg png webp
|
|
- name: Generate full metadata file
|
|
run: python scripts/generate_metadata.py
|
|
- name: Extract icon name
|
|
id: extract_icon_name
|
|
run: echo "ICON_NAME=$(python scripts/print_icon_name.py ${{ env.ICON_TYPE }} addition)" >> "$GITHUB_OUTPUT"
|
|
env:
|
|
INPUT_ISSUE_FORM: ${{ steps.parse_issue_form.outputs.ISSUE_FORM }}
|
|
- name: Compress icons
|
|
run: |
|
|
echo "Compressing PNGs..."
|
|
find png/ -iname "${{ steps.extract_icon_name.outputs.ICON_NAME }}*.png" -print0 | xargs -0 -P 4 -I{} zopflipng -y {} {}
|
|
echo "Compressing WEBPs..."
|
|
find webp/ -iname "${{ steps.extract_icon_name.outputs.ICON_NAME }}*.webp" -print0 | xargs -0 -P 4 -I{} bash -c 'cwebp -quiet -lossless "$1" -o "$1"' _ {}
|
|
- name: Commit changes
|
|
run: |
|
|
git config --global user.email "193821040+dashboard-icons-manager[bot]@users.noreply.github.com"
|
|
git config --global user.name "Dashboard Icons Manager"
|
|
git add .
|
|
git commit -m "feat(icons): add ${{ steps.extract_icon_name.outputs.ICON_NAME }}"
|
|
|
|
- name: Create Pull Request
|
|
uses: peter-evans/create-pull-request@v7
|
|
with:
|
|
token: ${{ steps.obtainToken.outputs.token }}
|
|
branch: icons/add-${{steps.extract_icon_name.outputs.ICON_NAME}}
|
|
base: main
|
|
title: "feat(icons): add ${{steps.extract_icon_name.outputs.ICON_NAME}}"
|
|
delete-branch: true
|
|
body: |
|
|
This PR adds the icon ${{steps.extract_icon_name.outputs.ICON_NAME}} added in #${{github.event.issue.number}} to the project.
|
|
Closes #${{github.event.issue.number}}
|