From 6c4958a805a32a0534c8e3d6186595bdaafc6aa2 Mon Sep 17 00:00:00 2001 From: dirtyhabits97 Date: Tue, 14 Sep 2021 18:10:50 -0500 Subject: [PATCH 1/7] Don't rely on the swiftlint executable for tests. --- spec/danger_plugin_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/danger_plugin_spec.rb b/spec/danger_plugin_spec.rb index af8927c..75ad33b 100755 --- a/spec/danger_plugin_spec.rb +++ b/spec/danger_plugin_spec.rb @@ -220,6 +220,7 @@ module Danger end it 'crashes if renamed_files is not configured properly' do + allow_any_instance_of(Swiftlint).to receive(:lint).and_return('') allow(@swiftlint.git).to receive(:modified_files).and_return([ 'spec/fixtures/SwiftFileThatWasRenamedToSomethingElse.swift' ]) @@ -227,6 +228,7 @@ module Danger end it 'does not crash if a modified file was renamed' do + allow_any_instance_of(Swiftlint).to receive(:lint).and_return('') allow(@swiftlint.git).to receive(:modified_files).and_return([ 'spec/fixtures/SwiftFileThatWasRenamedToSomethingElse.swift' ]) From b18def9f0b4b8ee8df7dbaf16fbc1042c6a10ea8 Mon Sep 17 00:00:00 2001 From: dirtyhabits97 Date: Tue, 14 Sep 2021 18:25:37 -0500 Subject: [PATCH 2/7] Explicitly call bash in swiftlint's Rakefile --- ext/swiftlint/Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/swiftlint/Rakefile b/ext/swiftlint/Rakefile index 779ed33..b9091cb 100644 --- a/ext/swiftlint/Rakefile +++ b/ext/swiftlint/Rakefile @@ -16,7 +16,7 @@ namespace :swiftlint do SWIFTLINT_MD5_HASH = DangerSwiftlint::SWIFTLINT_HASH puts "Downloading swiftlint@#{VERSION}" - sh "sh #{SCRIPT_PATH}/downloadSwiftlint.sh -u #{URL} -d #{DESTINATION} -a #{ASSET} -dh #{SWIFTLINT_MD5_HASH}" + sh "bash #{SCRIPT_PATH}/downloadSwiftlint.sh -u #{URL} -d #{DESTINATION} -a #{ASSET} -dh #{SWIFTLINT_MD5_HASH}" end end From d11176448b698442255536228e392131e7855c53 Mon Sep 17 00:00:00 2001 From: dirtyhabits97 Date: Tue, 14 Sep 2021 18:42:57 -0500 Subject: [PATCH 3/7] Avoid explicitly setting the shell interpreter. --- ext/swiftlint/Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/swiftlint/Rakefile b/ext/swiftlint/Rakefile index b9091cb..1dd85c0 100644 --- a/ext/swiftlint/Rakefile +++ b/ext/swiftlint/Rakefile @@ -16,7 +16,7 @@ namespace :swiftlint do SWIFTLINT_MD5_HASH = DangerSwiftlint::SWIFTLINT_HASH puts "Downloading swiftlint@#{VERSION}" - sh "bash #{SCRIPT_PATH}/downloadSwiftlint.sh -u #{URL} -d #{DESTINATION} -a #{ASSET} -dh #{SWIFTLINT_MD5_HASH}" + sh "#{SCRIPT_PATH}/downloadSwiftlint.sh -u #{URL} -d #{DESTINATION} -a #{ASSET} -dh #{SWIFTLINT_MD5_HASH}" end end From f3a59ef529f487597bb7c540f1ded9425d50d937 Mon Sep 17 00:00:00 2001 From: dirtyhabits97 Date: Tue, 14 Sep 2021 18:50:41 -0500 Subject: [PATCH 4/7] Run different hash commands depending on the OS. --- ext/swiftlint/downloadSwiftlint.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ext/swiftlint/downloadSwiftlint.sh b/ext/swiftlint/downloadSwiftlint.sh index 1d6323d..24e3d9f 100755 --- a/ext/swiftlint/downloadSwiftlint.sh +++ b/ext/swiftlint/downloadSwiftlint.sh @@ -31,10 +31,18 @@ do shift done +# If macOS +if [[ "$OSTYPE" == "darwin"* ]]; then + hash_cmd="md5 -q ${asset}" +# Default to linux +else + hash_cmd="md5sum ${asset} | awk '{ print $1 }'" +fi + ### Download mkdir -p "${destination}" curl -s -L "${url}" -o "${asset}" -if [[ ! -z "${SWIFTLINT_VERSION}" || $(md5 -q "${asset}") == "${default_hash}" ]]; then +if [[ ! -z "${SWIFTLINT_VERSION}" || "$hash_cmd" == "${default_hash}" ]]; then # if another version is set || our hardcoded hash is correct unzip -o -q "${asset}" -d "${destination}" else From 08c24ee06b880ec4c714fd4c6dc4080c86c4c0c4 Mon Sep 17 00:00:00 2001 From: dirtyhabits97 Date: Tue, 14 Sep 2021 19:07:43 -0500 Subject: [PATCH 5/7] Added flag to debug md5 command --- ext/swiftlint/downloadSwiftlint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ext/swiftlint/downloadSwiftlint.sh b/ext/swiftlint/downloadSwiftlint.sh index 24e3d9f..2c67e59 100755 --- a/ext/swiftlint/downloadSwiftlint.sh +++ b/ext/swiftlint/downloadSwiftlint.sh @@ -31,6 +31,8 @@ do shift done +set -x + # If macOS if [[ "$OSTYPE" == "darwin"* ]]; then hash_cmd="md5 -q ${asset}" From 869a15278b8d5c5e386f487e11bd552a68c61c08 Mon Sep 17 00:00:00 2001 From: dirtyhabits97 Date: Tue, 14 Sep 2021 19:17:51 -0500 Subject: [PATCH 6/7] Calculate the resulting_hash beforehand --- ext/swiftlint/downloadSwiftlint.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ext/swiftlint/downloadSwiftlint.sh b/ext/swiftlint/downloadSwiftlint.sh index 2c67e59..a92769c 100755 --- a/ext/swiftlint/downloadSwiftlint.sh +++ b/ext/swiftlint/downloadSwiftlint.sh @@ -33,18 +33,19 @@ done set -x +### Download +mkdir -p "${destination}" +curl -s -L "${url}" -o "${asset}" + # If macOS if [[ "$OSTYPE" == "darwin"* ]]; then - hash_cmd="md5 -q ${asset}" + resulting_hash=`md5 -q ${asset}` # Default to linux else - hash_cmd="md5sum ${asset} | awk '{ print $1 }'" + resulting_hash=`md5sum ${asset} | awk '{ print $1 }'` fi -### Download -mkdir -p "${destination}" -curl -s -L "${url}" -o "${asset}" -if [[ ! -z "${SWIFTLINT_VERSION}" || "$hash_cmd" == "${default_hash}" ]]; then +if [[ ! -z "${SWIFTLINT_VERSION}" || "$resulting_hash" == "${default_hash}" ]]; then # if another version is set || our hardcoded hash is correct unzip -o -q "${asset}" -d "${destination}" else From cd67dee016ae8ea36f9ac908f62522ff624a82cd Mon Sep 17 00:00:00 2001 From: dirtyhabits97 Date: Tue, 14 Sep 2021 19:24:07 -0500 Subject: [PATCH 7/7] Removed debug flag from install script. --- ext/swiftlint/downloadSwiftlint.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/ext/swiftlint/downloadSwiftlint.sh b/ext/swiftlint/downloadSwiftlint.sh index a92769c..19b29c1 100755 --- a/ext/swiftlint/downloadSwiftlint.sh +++ b/ext/swiftlint/downloadSwiftlint.sh @@ -31,8 +31,6 @@ do shift done -set -x - ### Download mkdir -p "${destination}" curl -s -L "${url}" -o "${asset}"