From 7c61625aff9d8db066c90584caf50917f3bdcabd Mon Sep 17 00:00:00 2001 From: Koosemose Date: Mon, 21 Nov 2016 17:04:06 -0500 Subject: [PATCH] Stylecopping in Travis (#1636) * Run Stylecop in Travis Build * Explicitly Ignore StreamingAssets * Report clean Stylecop * Use build matrix --- .travis.yml | 13 +++++++++++-- Scripts/check-style.sh | 14 ++++++++++++++ Scripts/install-stylecop.sh | 3 +++ Scripts/mono-version.txt | 1 + Scripts/mono.sh | 4 ++++ Scripts/test.sh | 17 +++++++---------- Scripts/travis.sh | 13 +++++++++++++ Settings.StyleCop | 1 + 8 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 Scripts/check-style.sh create mode 100644 Scripts/install-stylecop.sh create mode 100644 Scripts/mono-version.txt create mode 100644 Scripts/mono.sh create mode 100644 Scripts/travis.sh diff --git a/.travis.yml b/.travis.yml index 41e5a74d..fd7bceec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,15 +3,24 @@ # Using objective-c since windows build images are not available # The chmod-ing may be uneccesary language: objective-c -osx_image: xcode61 +osx_image: xcode6.4 rvm: - 2.1.2 before_install: - chmod +x ./Scripts/install.sh - chmod +x ./Scripts/test.sh + - chmod +x ./Scripts/mono.sh + - chmod +x ./Scripts/install-stylecop.sh + - chmod +x ./Scripts/check-style.sh + - chmod +x ./Scripts/travis.sh +env: + - JOB=unit-test + - JOB=stylecop install: - ./Scripts/install.sh +- ./Scripts/mono.sh +- ./Scripts/install-stylecop.sh script: -- ./Scripts/test.sh --travis +- ./Scripts/travis.sh notifications: email: false diff --git a/Scripts/check-style.sh b/Scripts/check-style.sh new file mode 100644 index 00000000..d40aa658 --- /dev/null +++ b/Scripts/check-style.sh @@ -0,0 +1,14 @@ +echo "Stylecopping" +StylecopOutput=$(mono /opt/stylecop/StyleCopCmd.Console.exe -rd Assets/ -vt) +StyleCopErrorCode=$? + +if [ "$StyleCopErrorCode" == "0" ]; then + echo '\nNo Stylecop violations were found.\n' +fi + + +if [ "$StyleCopErrorCode" != "0" ]; then + echo '\nThe following Stylecop violations were thrown:\n' + echo "$StylecopOutput\n" + exit 1 +fi diff --git a/Scripts/install-stylecop.sh b/Scripts/install-stylecop.sh new file mode 100644 index 00000000..4bf50f9c --- /dev/null +++ b/Scripts/install-stylecop.sh @@ -0,0 +1,3 @@ +wget -O scc.zip "https://github.com/enckse/StyleCopCmd/releases/download/v1.3.6/StyleCopCmd-1.3.6.zip" +sudo mkdir /opt/stylecop +sudo unzip scc.zip -d /opt/stylecop \ No newline at end of file diff --git a/Scripts/mono-version.txt b/Scripts/mono-version.txt new file mode 100644 index 00000000..512d523b --- /dev/null +++ b/Scripts/mono-version.txt @@ -0,0 +1 @@ +3.12.1 \ No newline at end of file diff --git a/Scripts/mono.sh b/Scripts/mono.sh new file mode 100644 index 00000000..e7bfc8ea --- /dev/null +++ b/Scripts/mono.sh @@ -0,0 +1,4 @@ +wget -O "mono-version.txt" "https://raw.githubusercontent.com/enckse/travis-mono-scripts/master/mono-version.txt" +VER=$(cat "mono-version.txt") +wget "http://download.mono-project.com/archive/$VER/macos-10-x86/MonoFramework-MDK-$VER.macos10.xamarin.x86.pkg" +sudo installer -pkg "MonoFramework-MDK-$VER.macos10.xamarin.x86.pkg" -target / \ No newline at end of file diff --git a/Scripts/test.sh b/Scripts/test.sh index 8e77d89d..ab3b903b 100644 --- a/Scripts/test.sh +++ b/Scripts/test.sh @@ -100,6 +100,7 @@ if [ "$endTestsFold" = 0 ]; then travecho 'travis_fold:end:tests' fi + #TERRIBLE error check logic - Please fix ASAP errorCount=$(grep "failures" EditorTestResults.xml | awk -F"\"" '{print $8}') #find line with 'failures' and returns characters between quotation mark 8 and 9 @@ -110,8 +111,7 @@ if [ "$errorCount" != "0" ]; then printf '\nThe following unit tests failed:' echo | grep 'success="False"' EditorTestResults.xml | grep 'test-case' - rm "$(pwd)"/EditorTestResults.xml - exit 1 + exitStatus=1 fi errorCount=$(grep "failures" EditorTestResults.xml | awk -F"\"" '{print $6}') #now for errors @@ -119,8 +119,7 @@ errorCount=$(grep "failures" EditorTestResults.xml | awk -F"\"" '{print $6}') #n if [ "$errorCount" != "0" ]; then echo "$errorCount" ' unit tests threw errors!' - rm "$(pwd)"/EditorTestResults.xml - exit 1 + exitStatus=1 fi errorCount=$(grep "failures" EditorTestResults.xml | awk -F"\"" '{print $12}') #inconlusive tests @@ -128,8 +127,7 @@ errorCount=$(grep "failures" EditorTestResults.xml | awk -F"\"" '{print $12}') # if [ "$errorCount" != "0" ]; then echo "$errorCount" ' unit tests were inconlusive!' - rm "$(pwd)"/EditorTestResults.xml - exit 1 + exitStatus=1 fi @@ -138,9 +136,8 @@ errorCount=$(grep "failures" EditorTestResults.xml | awk -F"\"" '{print $18}') # if [ "$errorCount" != "0" ]; then echo "$errorCount" ' unit tests were invalid!' - rm "$(pwd)"/EditorTestResults.xml - exit 1 + exitStatus=1 fi -#end of unit test checks. at this point the test have suceeded or exited with an error code. - +#end of unit test checks. at this point the test have suceeded or set exitStatus to 1. rm "$(pwd)"/EditorTestResults.xml +exit $exitStatus \ No newline at end of file diff --git a/Scripts/travis.sh b/Scripts/travis.sh new file mode 100644 index 00000000..bfe3abf4 --- /dev/null +++ b/Scripts/travis.sh @@ -0,0 +1,13 @@ +#! /bin/sh +# This script is responsible for running the script that matches +# the environment variable travis selects. + +if [ "$JOB" == "unit-test" ]; then + ./Scripts/test.sh --travis + exit $? +fi + + +if [ "$JOB" == "stylecop" ]; then + ./Scripts/check-style.sh +fi \ No newline at end of file diff --git a/Settings.StyleCop b/Settings.StyleCop index ce4f35a7..ec950eb3 100644 --- a/Settings.StyleCop +++ b/Settings.StyleCop @@ -13,6 +13,7 @@ \.g\.cs$ \.generated\.cs$ \.g\.i\.cs$ + StreamingAssets[/\\].+\.cs$ TemporaryGeneratedFile_.*\.cs$