Skip to content

Commit

Permalink
CI: Enforce UTF-8 for .cpp/.h/.txt files
Browse files Browse the repository at this point in the history
  • Loading branch information
marktsuchida committed Jun 19, 2024
1 parent b7da0df commit 32f4db9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci-misc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Misc checks

on:
pull_request:
push:
branches:
- main

jobs:
check-utf8-encoding:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./tools/check-utf8.sh
20 changes: 20 additions & 0 deletions tools/check-utf8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

invalid_found=0

# We would like to redirect iconv output to /dev/null, but the macOS version of
# iconv has problems with this ("iconv: iconv(): Inappropriate ioctl for
# device", sporadically for particular inputs). So use a regular file instead.
tmpfile=/tmp/check-utf8-temp
trap "rm -f $tmpfile" EXIT

for file in $(git ls-files | grep -E '\.(cpp|h|txt)$'); do
if ! iconv -f UTF-8 "$file" >$tmpfile; then
echo "Not valid UTF-8: $file" >&2
invalid_found=1
fi
done

[ $invalid_found = 0 ] && echo "All checked files are valid UTF-8" >&2

exit $invalid_found

0 comments on commit 32f4db9

Please sign in to comment.