Skip to content

feat(Icons): Include new icons equal, rank and ring #195

feat(Icons): Include new icons equal, rank and ring

feat(Icons): Include new icons equal, rank and ring #195

Workflow file for this run

name: Check icons keywords
permissions:
contents: write
on:
workflow_dispatch:
# push:
# paths:
# - "icons/**"
pull_request:
branches:
- production
paths:
- "icons/**"
jobs:
check-concepts:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
persist-credentials: false
- name: List SVG files
run: |
ICONS_DIR="icons"
echo "Listing SVG files..."
# Use 'find' to get all SVG files in the icons directory
find $ICONS_DIR -type f -name "*.svg" |
# Use 'basename' to get the file names without the path
xargs -I {} basename {} |
# Use 'sed' to remove the "-filled", "-light", "-regular" parts and the ".svg" extension
sed 's/\(-filled\|-light\|-regular\)\.svg//' |
# Use 'sort -u' to get a unique list of file names
sort -u > icons.txt
# Show the contents of the icons.txt file in the console
echo "Found $(cat icons.txt | wc -l) unique icons"
continue-on-error: false
- name: Read JSON file
run: |
JSON_FILE="icons/icons-keywords.json"
echo "Reading JSON file..."
if [ -f "$JSON_FILE" ]; then
cat $JSON_FILE > data.json
echo "JSON file loaded successfully"
else
echo "Keywords JSON file not found!"
exit 1
fi
continue-on-error: false
- name: Check for missing icons in JSON
id: check-concepts
run: |
echo "Checking for icons missing in JSON..."
missing_icons=""
for icon_name in $(cat icons.txt); do
# Check if icon exists in JSON
if ! grep -q "\"$icon_name\":" data.json; then
missing_icons="$missing_icons\n\033[0;31m× $icon_name\033[0m"
fi
done
# Show the complete list of missing icons
if [ -n "$missing_icons" ]; then
echo -e "\n\033[4mIcons Missing in JSON\033[0m"
echo -e "$missing_icons \n"
echo "❌ Found icons not present in icons-keywords.json. Please add these icon concepts to the JSON file."
exit 1 # End the execution with an error code
else
echo "✅ All icons are present in icons-keywords.json!"
fi
continue-on-error: false
- name: Cleanup
run: |
rm data.json
rm icons.txt
continue-on-error: true
check-keywords:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
persist-credentials: false
- name: List SVG files
run: |
ICONS_DIR="icons"
echo "Listing SVG files..."
# Use 'find' to get all SVG files in the icons directory
find $ICONS_DIR -type f -name "*.svg" |
# Use 'basename' to get the file names without the path
xargs -I {} basename {} |
# Use 'sed' to remove the "-filled", "-light", "-regular" parts and the ".svg" extension
sed 's/\(-filled\|-light\|-regular\)\.svg//' |
# Use 'sort -u' to get a unique list of file names
sort -u > icons.txt
# Show the contents of the icons.txt file in the console
echo "Found $(cat icons.txt | wc -l) unique icons"
continue-on-error: false
- name: Read JSON file
run: |
JSON_FILE="icons/icons-keywords.json"
echo "Reading JSON file..."
if [ -f "$JSON_FILE" ]; then
cat $JSON_FILE > data.json
echo "JSON file loaded successfully"
else
echo "Keywords JSON file not found!"
exit 1
fi
continue-on-error: false
- name: Check for empty keywords
id: check-keywords
run: |
echo "Checking for icons with empty keywords..."
empty_keywords=""
for icon_name in $(cat icons.txt); do
# Check if icon exists in JSON and has empty keywords array
if grep -q "\"$icon_name\":" data.json; then
keywords_check=$(cat data.json | jq -r ".[\"$icon_name\"].keywords | length")
if [ "$keywords_check" -eq 0 ]; then
empty_keywords="$empty_keywords\n\033[0;33m× $icon_name\033[0m"
fi
fi
done
# Show the complete list of icons with empty keywords
if [ -n "$empty_keywords" ]; then
echo -e "\n\033[4mIcons with Empty Keywords\033[0m"
echo -e "$empty_keywords \n"
echo "❌ Found icons with empty keywords arrays. Please add keywords to these icons in icons-keywords.json."
exit 1 # End the execution with an error code
else
echo "✅ All icons have keywords assigned!"
fi
continue-on-error: false
- name: Cleanup
run: |
rm data.json
rm icons.txt
continue-on-error: true
generate-concepts-and-keywords:
runs-on: ubuntu-latest
needs: [check-concepts, check-keywords]
# Only run if checks fail AND PR is from same repository (protects OPENAI_API_KEY from forks)
if: always() && (needs.check-concepts.result == 'failure' || needs.check-keywords.result == 'failure') && github.event.pull_request.head.repo.full_name == github.repository
steps:
- name: Validate and sanitize ref
id: validate_ref
env:
HEAD_REF: ${{ github.head_ref }}
run: |
# Validate that head_ref only contains safe characters
if ! printf '%s' "$HEAD_REF" | grep -Eq '^[a-zA-Z0-9/_.-]+$'; then
echo "❌ Invalid ref name: $HEAD_REF"
exit 1
fi
echo "ref=$HEAD_REF" >> "$GITHUB_OUTPUT"
- name: Checkout repository
uses: actions/checkout@v6
with:
persist-credentials: false
ref: ${{ steps.validate_ref.outputs.ref }}
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.x"
- name: Upgrade pip, setuptools, and wheel
run: |
pip install --upgrade pip setuptools wheel
- name: Install dependencies
run: |
pip install openai python-dotenv --use-pep517
- name: Install prettier
run: npm install -g prettier
- name: Run keywords generator
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: python3 .github/keywords/keywords-generator.py
- name: Commit & Push
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_MISTICA }}
HEAD_REF: ${{ steps.validate_ref.outputs.ref }}
run: |
# Configure git credentials using GITHUB_TOKEN
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git
git config user.name "github-actions"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .
# Check if there are any changes to commit
if git diff --staged --quiet; then
echo "No changes to commit. Skipping commit and push."
else
echo "Changes detected. Committing and pushing..."
git commit -m "Icons keywords autogenerated"
# Use validated ref variable
git push origin "$HEAD_REF"
echo "Successfully committed and pushed changes."
fi
check-categories:
runs-on: ubuntu-latest
env:
VALID_CATEGORIES: |
Actions and system
Activities
Alerts and feedbacks
Arrows
Business and finance
Development
Files
Health
Home and devices
Maps and vehicles
Media
Nature and sustainability
Others
People and users
Security
Telco and comms
Time
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
persist-credentials: false
- name: List SVG files
run: |
ICONS_DIR="icons"
echo "Listing SVG files..."
# Use 'find' to get all SVG files in the icons directory
find $ICONS_DIR -type f -name "*.svg" |
# Use 'basename' to get the file names without the path
xargs -I {} basename {} |
# Use 'sed' to remove the "-filled", "-light", "-regular" parts and the ".svg" extension
sed 's/\(-filled\|-light\|-regular\)\.svg//' |
# Use 'sort -u' to get a unique list of file names
sort -u > icons.txt
# Show the contents of the icons.txt file in the console
echo "Found $(cat icons.txt | wc -l) unique icons"
continue-on-error: false
- name: Read JSON file
run: |
JSON_FILE="icons/icons-keywords.json"
echo "Reading JSON file..."
if [ -f "$JSON_FILE" ]; then
cat $JSON_FILE > data.json
echo "JSON file loaded successfully"
else
echo "Keywords JSON file not found!"
exit 1
fi
continue-on-error: false
- name: Check for uncategorized icons
id: check-categories
run: |
echo "Checking for icons without categories and invalid categories..."
# Define valid categories
valid_categories=(
"Actions and system"
"Activities"
"Alerts and feedbacks"
"Arrows"
"Business and finance"
"Development"
"Files"
"Health"
"Home and devices"
"Maps and vehicles"
"Media"
"Nature and sustainability"
"Others"
"People and users"
"Security"
"Telco and comms"
"Time"
)
uncategorized_icons=""
invalid_categories=""
for icon_name in $(cat icons.txt); do
# Check if icon exists in JSON and has a non-empty category array
category_check=$(cat data.json | jq -r "if has(\"$icon_name\") then .[\"$icon_name\"].category | length else 0 end")
if [ "$category_check" -eq 0 ]; then
uncategorized_icons="$uncategorized_icons\n\033[0;31m× $icon_name\033[0m"
else
# Check if categories are valid - using a different approach to handle spaces
while IFS= read -r category; do
# Check if category is in valid list
valid=false
for valid_cat in "${valid_categories[@]}"; do
if [ "$category" = "$valid_cat" ]; then
valid=true
break
fi
done
if [ "$valid" = false ]; then
invalid_categories="$invalid_categories\n\033[0;33m× $icon_name\033[0m - Invalid category: '$category'"
fi
done < <(cat data.json | jq -r ".[\"$icon_name\"].category[]")
fi
done
# Show the complete list of issues
has_errors=false
if [ -n "$uncategorized_icons" ]; then
echo -e "\n\033[4mIcons without categories\033[0m"
echo -e "$uncategorized_icons \n"
has_errors=true
fi
if [ -n "$invalid_categories" ]; then
echo -e "\n\033[4mIcons with invalid categories\033[0m"
echo -e "$invalid_categories \n"
echo "Valid categories are:"
for valid_cat in "${valid_categories[@]}"; do
echo " - $valid_cat"
done
echo ""
has_errors=true
fi
if [ "$has_errors" = true ]; then
echo "❌ Found icons with missing or invalid categories in icons-keywords.json."
exit 1 # End the execution with an error code
else
echo "✅ All icons have valid categories assigned in icons-keywords.json!"
fi
continue-on-error: false
- name: Cleanup
run: |
rm icons.txt
rm data.json
continue-on-error: true