Check icons keywords #4
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: Check icons keywords | |
on: | |
workflow_dispatch: | |
push: | |
paths: | |
- "icons/**" | |
pull_request: | |
branches: | |
- production | |
paths: | |
- "icons/**" | |
jobs: | |
check_icons: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: List SVG files | |
run: | | |
ICONS_DIR="icons" # Reemplaza con la ubicación real de tu carpeta de iconos | |
echo "Listing SVG files..." | |
# Utiliza 'find' para encontrar todos los archivos SVG en la carpeta de iconos | |
find $ICONS_DIR -type f -name "*.svg" | | |
# Utiliza 'basename' para obtener solo el nombre de archivo sin la ruta | |
xargs -I {} basename {} | | |
# Utiliza 'sed' para quitar las partes "-filled", "-light", "-regular" y la extensión ".svg" | |
sed 's/\(-filled\|-light\|-regular\)\.svg//' | | |
# Utiliza 'sort -u' para obtener una lista única de nombres de archivo | |
sort -u > icons.txt | |
# Muestra el contenido del archivo icons.txt en la consola | |
cat icons.txt | |
continue-on-error: false | |
- name: Read JSON file | |
run: | | |
JSON_FILE="icons/icons-keywords.json" | |
echo "Reading JSON file..." | |
cat $JSON_FILE > data.json | |
continue-on-error: true | |
- name: Extract keywords | |
run: | | |
echo "Extracting keywords from JSON..." | |
# Usamos jq para extraer las claves del JSON y guardarlas en keywords.txt | |
cat data.json | jq -r 'keys[]' > keywords.txt | |
# Mostramos el contenido de keywords.txt para verificar que se han extraído correctamente | |
cat keywords.txt | |
continue-on-error: true | |
- name: Compare with Keywords | |
id: compare | |
run: | | |
echo "Comparing icon names with keywords from JSON..." | |
missing_keywords="" | |
for icon_name in $(cat icons.txt); do | |
if ! grep -q "\"$icon_name\":" data.json; then | |
missing_keywords="$missing_keywords\nIcon name '$icon_name' is missing in the JSON keywords." | |
fi | |
done | |
# Mostrar la lista completa de elementos que faltan | |
echo "Missing Keywords:" | |
echo -e "$missing_keywords" | |
# Detener la acción si se encontraron elementos que faltan | |
if [ -n "$missing_keywords" ]; then | |
exit 1 # Terminar la ejecución con un código de error | |
fi | |
continue-on-error: false | |
- name: Cleanup | |
run: | | |
rm data.json | |
rm icons.txt | |
rm keywords.txt | |
continue-on-error: true |