From 14b0721a5290d920d058df67363996d579392039 Mon Sep 17 00:00:00 2001 From: Nicolas Combe Date: Thu, 2 Sep 2021 18:28:11 -0500 Subject: [PATCH] Remove environment variables and use parameters instead (#162) --- ext/swiftlint/Rakefile | 9 +++--- ext/swiftlint/downloadSwiftlint.sh | 46 +++++++++++++++++++++++++----- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/ext/swiftlint/Rakefile b/ext/swiftlint/Rakefile index 15e960a..614e353 100644 --- a/ext/swiftlint/Rakefile +++ b/ext/swiftlint/Rakefile @@ -10,13 +10,12 @@ namespace :swiftlint do REPO = 'https://github.com/realm/SwiftLint' VERSION = ENV['SWIFTLINT_VERSION'] || DangerSwiftlint::SWIFTLINT_VERSION ASSET = 'portable_swiftlint.zip' - ENV['ASSET'] = ASSET - ENV['URL'] = "#{REPO}/releases/download/#{VERSION}/#{ASSET}" - ENV['SWIFTLINT_MD5_HASH'] = DangerSwiftlint::SWIFTLINT_HASH - ENV['DESTINATION'] = File.expand_path(File.join(File.dirname(__FILE__), 'bin')) + URL = "#{REPO}/releases/download/#{VERSION}/#{ASSET}" + DESTINATION = File.expand_path(File.join(File.dirname(__FILE__), 'bin')) + SWIFTLINT_MD5_HASH = DangerSwiftlint::SWIFTLINT_HASH puts "Downloading swiftlint@#{VERSION}" - sh "./downloadSwiftlint.sh" + sh "./downloadSwiftlint.sh -u #{URL} -d #{DESTINATION} -a #{ASSET} -dh #{SWIFTLINT_MD5_HASH}" end end diff --git a/ext/swiftlint/downloadSwiftlint.sh b/ext/swiftlint/downloadSwiftlint.sh index 58bf06e..1d6323d 100755 --- a/ext/swiftlint/downloadSwiftlint.sh +++ b/ext/swiftlint/downloadSwiftlint.sh @@ -1,11 +1,43 @@ #!/usr/bin/env bash -# frozen_string_literal: true -mkdir -p "${DESTINATION}" -curl -s -L "${URL}" -o "${ASSET}" -if [[ $(md5 -q "${ASSET}") != "${SWIFTLINT_MD5_HASH}" ]]; then - echo "Zip was corrupted, try again later." +### Load arguments +while [[ $# > 0 ]] +do + case "$1" in + -u|--url) + url="$2" + shift;; + + -d|--destination) + destination="$2" + shift;; + + -a|--asset) + asset="$2" + shift;; + + -dh|--default_hash) + default_hash="$2" + shift;; + + --help|*) + echo "Usage:" + echo ' -u --url: URL for SwiftLint version to download' + echo ' -d --destination: Folder where SwiftLint will be downloaded' + echo " -a --asset: Temporary name for the zip file" + echo " -dh --default_hash: Default SwiftLint md5 hash to check for if no version specified" + exit 1;; + esac + shift +done + +### Download +mkdir -p "${destination}" +curl -s -L "${url}" -o "${asset}" +if [[ ! -z "${SWIFTLINT_VERSION}" || $(md5 -q "${asset}") == "${default_hash}" ]]; then + # if another version is set || our hardcoded hash is correct + unzip -o -q "${asset}" -d "${destination}" else - unzip -o -q "${ASSET}" -d "${DESTINATION}" + echo "Zip was corrupted, try again later." fi -rm "${ASSET}" +rm "${asset}"