Skip to content

Commit

Permalink
Remove environment variables and use parameters instead (ashfurrow#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasCombe5555 committed Sep 2, 2021
1 parent 0526364 commit 14b0721
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
9 changes: 4 additions & 5 deletions ext/swiftlint/Rakefile
Expand Up @@ -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

Expand Down
46 changes: 39 additions & 7 deletions 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}"

0 comments on commit 14b0721

Please sign in to comment.