Skip to content

ValidateSelectors #1501

ValidateSelectors

ValidateSelectors #1501

# This is a basic workflow to help you get started with Actions
name: ValidateSelectors
# Controls when the action will run.
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
# Scheduled trigger
schedule:
- cron: '42 0 * * *'
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
check-selectors:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- name: Download CSS file
run: |
sheets=$(curl --list-only https://discord.com/app | grep -o "<[^<>]*stylesheet[^<>]*\/>" | cut -d " " -f2 | cut -d \" -f2)
for i in $sheets; do
wget -O - >> stylesheet.txt "discord.com$i"
done
- name: Parse discord stylesheet
run: |
sed 's@/\*.*\*/@@g' stylesheet.txt \
| sed '/\/\*/,/\*\//d' \
| tr -d '\r\n' \
| sed 's/{[^{}]\+}//g' \
| sed 's/{[^{}]\+}//g' \
| grep -o '\.[_[:alnum:]-]\+' \
| sort \
| uniq > reference.txt \
&& echo "Discord stylesheet parsed"
- name: Parse repository stylesheets
run: |
cat css/*.css \
| perl -0pe 's@/\*(.|\n)*?\*/@@g' \
| sed '/\/\*/,/\*\//d' \
| tr -d '\r\n' \
| sed 's/{[^{}]\+}//g' \
| sed 's/{[^{}]\+}//g' \
| grep -o '\.[_[:alnum:]-]\+' \
| sort \
| uniq > selectors.txt \
&& echo "User stylesheets concat complete"
- name: Compare repository selectors to reference
run: |
declare -A seen_classes
flag=true
blacklist="blacklist.txt"
differences=$(comm -13 reference.txt selectors.txt)
for file in $(dir css/*.css); do
for line in $differences; do
grep=$(grep -no "$line" "$file") || true
black_grep=$(grep -o "$line" "$blacklist") || true
if [[ -n "$grep" && -z "$black_grep" ]]; then
flag=false
class=$(echo $grep | cut -d ' ' -f 1 | cut -d ':' -f 2)
lines=$(echo ${grep//:$class/','} | tr -d '\r\n')
lines=${lines%','}
if [[ "${seen_classes[$class]}" ]]; then
level="::warning"
else
level="::error"
fi
echo "$level file=$file:: $class [$lines] {$file}"
seen_classes[$class]=true
fi
done
done
if [ $flag = false ]; then
exit 1
else
echo "Finished compare, no difference"
fi