diff --git a/.travis.yml b/.travis.yml index 359a3b0688b..f92068ba10a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -140,6 +140,8 @@ install: script: # fail fast - set -e + # fail if the test files have changes + - bin/utils/detect_test_file_changes.rb bin/utils/test_file_list.yaml # fail if templates/generators contain carriage return '\r' - /bin/bash ./bin/utils/detect_carriage_return.sh # fail if generators contain merge conflicts diff --git a/bin/utils/detect_test_file_changes.rb b/bin/utils/detect_test_file_changes.rb new file mode 100755 index 00000000000..9ba2d646ce1 --- /dev/null +++ b/bin/utils/detect_test_file_changes.rb @@ -0,0 +1,57 @@ +#!/usr/bin/env ruby +# ruby script to detect changes in test-related files +require 'yaml' +require 'digest' + +hash = Digest::SHA256.hexdigest("xyz") + +filename= ARGV[0] + +if !filename + puts "Usage: #{$0} filename" + exit 1 +end + +if !File.file? filename + warn "Error. #{filename} doesn't exist." + exit 1 +end + +mismatch = 0 +count = 0 + +test_files = YAML.load_file(filename) +test_files.each do |test_file| + count = count + 1 + # file still exists? + if !File.file? test_file['filename'] + warn "Error. Provided test file `#{test_file['filename']}` doesn't exist." + mismatch = mismatch + 1 + end + + # check sha256 hash + sha256 = Digest::SHA256.hexdigest(File.read(test_file['filename'])) + if test_file['sha256'] != sha256 + warn "Looks like #{test_file['filename']} has been modified as its SHA256 `#{sha256}` is not the same as the one in the record: #{test_file['sha256']}" + mismatch = mismatch + 1 + else + # no change to the test file + end +end + +if mismatch > 0 + warn "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + warn "There are #{mismatch} mismatch. Please review the test files to ensure it has not been deleted/regenerated." + warn "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + exit 1 +else + puts "OK. All matched!" +end + +if count == 0 + warn "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + warn "Looks like the test file list in #{filename} is empty! Please check!" + warn "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + exit 1 +end + diff --git a/bin/utils/test_file_list.yaml b/bin/utils/test_file_list.yaml new file mode 100644 index 00000000000..3d7cf02ace5 --- /dev/null +++ b/bin/utils/test_file_list.yaml @@ -0,0 +1,6 @@ +--- +# csharp-netcore test files and image for upload +- filename: "samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools.Test/Api/PetApiTests.cs" + sha256: b74ef9eefa4b41fd3233e083fe2355babf25a77f9073d28e1aa81ae2e0a5f1d0 +- filename: "samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools.Test/linux-logo.png" + sha256: 0a67c32728197e942b13bdda064b73793f12f5c795f1e5cf35a3adf69c973230