Merge pull request #136 from aaronfranke/travis
Add a formatting script for Travis CI
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..7106fe5
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,18 @@
+dist: bionic
+
+stages:
+ - build
+
+matrix:
+ include:
+ - name: Static checks (format.sh)
+ stage: build
+ os: linux
+ addons:
+ apt:
+ packages:
+ - dos2unix
+ - recode
+
+script:
+ - bash ./format.sh
diff --git a/contrib/previewers/lib/README.md b/contrib/previewers/lib/README.md
index 4b5a7b8..bbd2508 100644
--- a/contrib/previewers/lib/README.md
+++ b/contrib/previewers/lib/README.md
@@ -1,3 +1,3 @@
# Single File Basis Universal Transcoder
-Header and implementation generated using the [single file transcoder](../../single_file_transcoder) post-process script. Unlike the examples in that subproject here the transcoder header was kept as a seperate file (using the `-k` option, see the [README](../../single_file_transcoder/README.md)).
\ No newline at end of file
+Header and implementation generated using the [single file transcoder](../../single_file_transcoder) post-process script. Unlike the examples in that subproject here the transcoder header was kept as a seperate file (using the `-k` option, see the [README](../../single_file_transcoder/README.md)).
diff --git a/contrib/single_file_transcoder/examples/testcard-rgba.basis.inc b/contrib/single_file_transcoder/examples/testcard-rgba.basis.inc
index 7529728..6b9df6e 100644
--- a/contrib/single_file_transcoder/examples/testcard-rgba.basis.inc
+++ b/contrib/single_file_transcoder/examples/testcard-rgba.basis.inc
@@ -1040,4 +1040,4 @@
0x85, 0x35, 0xe1, 0x51, 0x6a, 0xa9, 0x19, 0x6b, 0x00, 0x9b, 0xcb, 0x5f,
0xfb, 0xd8, 0xf8, 0x56, 0xfc, 0x3f, 0xe1, 0xda, 0xfa, 0xff, 0xf6, 0xe3,
0x9c, 0x0e, 0x16, 0xff, 0x31, 0x76, 0x1f, 0x00, 0xf6, 0x64, 0x13, 0xb6,
-0xda, 0x38, 0x76, 0xb1, 0x11, 0xb6, 0xda, 0x38
\ No newline at end of file
+0xda, 0x38, 0x76, 0xb1, 0x11, 0xb6, 0xda, 0x38
diff --git a/contrib/single_file_transcoder/examples/testcard.basis.inc b/contrib/single_file_transcoder/examples/testcard.basis.inc
index 68102c1..d343ab2 100644
--- a/contrib/single_file_transcoder/examples/testcard.basis.inc
+++ b/contrib/single_file_transcoder/examples/testcard.basis.inc
@@ -700,4 +700,4 @@
0xbf, 0xc0, 0x2f, 0x73, 0x60, 0x9f, 0x73, 0xf4, 0x1f, 0x93, 0xf9, 0x0b,
0xf6, 0x8f, 0xdb, 0xfb, 0x12, 0x3e, 0x8a, 0x83, 0x00, 0xa7, 0x1b, 0x6f,
0x76, 0x40, 0x5c, 0xe7, 0x7f, 0x02, 0xb9, 0xf3, 0x85, 0x79, 0x6b, 0x0f,
-0x79, 0x6b, 0x79
\ No newline at end of file
+0x79, 0x6b, 0x79
diff --git a/format.sh b/format.sh
new file mode 100755
index 0000000..5d90393
--- /dev/null
+++ b/format.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+# Loops through all text files tracked by Git.
+git grep -zIl '' |
+while IFS= read -rd '' f; do
+ # Exclude some types of files.
+ if [[ $f == *"proj" ]]; then
+ continue
+ elif [[ $f == *"filters" ]]; then
+ continue
+ elif [[ $f == *"sln" ]]; then
+ continue
+ elif [[ $f == *"json" ]]; then
+ continue
+ elif [[ $f == *"min.js" ]]; then
+ continue
+ fi
+ # Ensures that files are UTF-8 formatted.
+ recode UTF-8 $f 2> /dev/null
+ # Ensures that files have LF line endings.
+ dos2unix $f 2> /dev/null
+ # Ensures that files do not contain a BOM.
+ sed -i '1s/^\xEF\xBB\xBF//' "$f"
+ # Ensures that files end with newline characters.
+ tail -c1 < "$f" | read -r _ || echo >> "$f";
+done
+
+git diff > patch.patch
+FILESIZE=$(stat -c%s patch.patch)
+MAXSIZE=5
+
+# If no patch has been generated all is OK, clean up, and exit.
+if (( FILESIZE < MAXSIZE )); then
+ printf "Files in this commit comply with the formatting rules.\n"
+ rm -f patch.patch
+ exit 0
+fi
+
+# A patch has been created, notify the user, clean up, and exit.
+printf "\n*** The following differences were found between the code "
+printf "and the formatting rules:\n\n"
+cat patch.patch
+printf "\n*** Aborting, please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\n"
+rm -f patch.patch
+exit 1
diff --git a/webgl/transcoder/build/basis_loader.js b/webgl/transcoder/build/basis_loader.js
index f5cd071..8cd4a0e 100644
--- a/webgl/transcoder/build/basis_loader.js
+++ b/webgl/transcoder/build/basis_loader.js
@@ -491,4 +491,4 @@
fail(id, `No url or buffer specified`);
}
};
-}
\ No newline at end of file
+}