add validate github workflow

This commit is contained in:
b2un0 2025-02-21 13:20:08 +01:00 committed by Nick Ortakales
parent 2410015f46
commit 408a6e6b2b
3 changed files with 75 additions and 37 deletions

17
.github/workflows/validate.yaml vendored Normal file
View file

@ -0,0 +1,17 @@
name: Validate NFC Files
on:
push:
pull_request:
types: [ opened, synchronize, reopened ]
jobs:
validation:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: validate
run: ./validation.sh

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
Extra Extra
*.ini *.ini
.idea

View file

@ -1,6 +1,6 @@
#!/bin/bash #!/usr/bin/env bash
shopt -s globstar ERR_FOUND=0
REQUIRED_PATTERNS=( REQUIRED_PATTERNS=(
"Filetype: Flipper NFC device" "Filetype: Flipper NFC device"
@ -24,25 +24,45 @@ REQUIRED_PATTERNS=(
"Lock EAS: false" "Lock EAS: false"
) )
for filename in **/*.nfc; do FORBIDDEN_PATTERNS=(
"Subtype: ([0-9]){2}"
# Add more forbidden patterns here
)
# Use process substitution so that ERR_FOUND is updated in the main shell.
while read -r filename; do
content=$(cat "$filename")
for pattern in "${REQUIRED_PATTERNS[@]}"; do for pattern in "${REQUIRED_PATTERNS[@]}"; do
if [ -z "$(grep -P "$pattern" "$filename")" ]; then if ! echo "$content" | awk "/$pattern/ { found=1 } END { exit !found }"; then
echo $filename echo "$filename"
echo " Missing: $pattern" echo " Missing: $pattern"
ERR_FOUND=1
fi fi
done done
# The likelihood of two blocks of 00 in data content is almost impossible, # The likelihood of two blocks of 00 in data content is almost impossible,
# so use that as a check for when the full data is not read # so use that as a check for when the full data is not read
if [ ! -z "$(grep -P "Data Content:( [A-F0-9]{2})* 00 00( [A-F0-9]{2})*" "$filename")" ]; then if echo "$content" | awk '/Data Content:( [A-F0-9]{2})* 00 00( [A-F0-9]{2})*/ { found=1 } END { exit !found }'; then
echo $filename echo "$filename"
echo " Full data not read" echo " Full data not read"
ERR_FOUND=1
fi fi
if [ ! -z "$(grep -P "\r" "$filename")" ]; then if echo "$content" | awk '/\r/ { found=1 } END { exit !found }'; then
echo $filename echo "$filename"
echo " Has carriage return characters" echo " Has carriage return characters"
ERR_FOUND=1
fi fi
done for pattern in "${FORBIDDEN_PATTERNS[@]}"; do
if echo "$content" | awk "/$pattern/ { found=1 } END { exit !found }"; then
echo "$filename"
echo " Forbidden pattern found: $pattern"
ERR_FOUND=1
fi
done
done < <(find . -type f -name "*.nfc")
exit $ERR_FOUND