Skip to content

Commit

Permalink
feat: add checks to translation prs
Browse files Browse the repository at this point in the history
  • Loading branch information
stanvanrooy committed Dec 13, 2023
1 parent a5d149b commit 94dc4be
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 1 deletion.
20 changes: 20 additions & 0 deletions .github/workflows/check-column-count.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: 'Check all lines have an equal amount of columns'

on:
pull_request:

jobs:
check:
name: 'Check column count'
runs-on: ubuntu-20.04

defaults:
run:
shell: bash

steps:
- name: Check
run: |
./scripts/test-columns.sh ems_translations.csv
./scripts/test-columns.sh showroom_translations.csv
20 changes: 20 additions & 0 deletions .github/workflows/check-encoding.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: 'Check all lines have an equal amount of columns'

on:
pull_request:

jobs:
check:
name: 'Check column count'
runs-on: ubuntu-20.04

defaults:
run:
shell: bash

steps:
- name: Check
run: |
./scripts/test-encoding.sh ems_translations.csv
./scripts/test-encoding.sh showroom_translations.csv
20 changes: 20 additions & 0 deletions .github/workflows/check-header-column.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: 'Check all lines have an equal amount of columns'

on:
pull_request:

jobs:
check:
name: 'Check column count'
runs-on: ubuntu-20.04

defaults:
run:
shell: bash

steps:
- name: Check
run: |
./scripts/test-headers.sh ems_translations.csv
./scripts/test-headers.sh showroom_translations.csv
1 change: 0 additions & 1 deletion ems_translations.csv
Original file line number Diff line number Diff line change
Expand Up @@ -799,4 +799,3 @@ Is less or equal to;Is kleiner dan of gelijk aan;Est inférieur ou égal à;Ist
Contains;Bevat;Contient;Enthält;Innehåller;Zawiera;Inneholder;Contiene;Contiene
Starts with;Begint met;Commence par;Beginnt mit;Börjar med;Zaczyna się od;Starter med;Empieza con;Inizia con
Ends with;Eindigt met;Se termine par;Endet mit;Slutar med;Kończy się na;Slutter med;Termina con;Finisce con

6 changes: 6 additions & 0 deletions scripts/test-columns.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
count=$(awk -F';' '{print NF-1}' "$1" | sort | uniq | wc -l)
if [ "$count" -ne 1 ]; then
echo "Error: $1 has different number of columns" >&2
exit 1
fi
exit 0
6 changes: 6 additions & 0 deletions scripts/test-encoding.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
if ! file -bi "$1" | grep -q "utf-8"; then
echo "Error: $1 is not encoded in UTF-8" >&2
exit 1
fi

26 changes: 26 additions & 0 deletions scripts/test-headers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
file="$1"
header=$(head -n 1 "$file" | tr -d '\r' | tr -d '\n' | tr -d '\r\n')
IFS=';' read -ra header_array <<< "$header"

declare -A header_map

for h in "${header_array[@]}"; do
if [ ${#h} -ne 2 ]; then
echo "Error: Header $h is not 2 characters long" >&2
exit 1
fi

if [[ ${header_map[$h]} ]]; then
echo "Error: Header $h is duplicated" >&2
exit 1
else
header_map[$h]=1
fi

if [[ $h =~ [A-Z] ]]; then
echo "Error: Header $h contains uppercase characters" >&2
exit 1
fi
done

0 comments on commit 94dc4be

Please sign in to comment.