Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make shield service dynamic #63

Merged
merged 2 commits into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ badge --shield "Version-0.0.3-blue" --dark --shield_geometry "+0+25%" --shield_s

![assets/icon175x175_shield_Version-0.0.3-blue-geo-scale.png](assets/icon175x175_shield_Version-0.0.3-blue-geo-scale.png?raw=1) ![assets/icon175x175_fitrack_shield_Version-0.0.3-blue-geo-scale.png](assets/icon175x175_fitrack_shield_Version-0.0.3-blue-geo-scale.png?raw=1)
---

# Installation

Install the gem
Expand All @@ -70,16 +70,16 @@ Install the gem
Call ```badge``` in your projects root folder

badge
It will search all subfolders for your asset catalog app icon set and add the badge to the icons.

It will search all subfolders for your asset catalog app icon set and add the badge to the icons.

You can also run badge on your Android, tvOS icons, or any other iconset.
You have to use the `--glob "/**/*.appiconset/*.{png,PNG}"` parameter to adjust where to find your icons.
You have to use the `--glob "/**/*.appiconset/*.{png,PNG}"` parameter to adjust where to find your icons.

:warning: Note that you have to use a `/` in the beginning of the custom path, even if you're not starting from the root path, f.ex. if your icons are in `res/ios/beta/Appicon/*`, your badge call would be `badge --glob "/res/ios/beta/Appicon/*"`

The keep the alpha channel in the icons use `--alpha_channel`

*Be careful, it actually overwrites the icon files.*

Here is the dark option (also available in combination with ```--alpha```):
Expand All @@ -89,18 +89,18 @@ Here is the dark option (also available in combination with ```--alpha```):
You can also use your custom overlay/badge image

badge --custom "path_to/custom_badge.png"

Add a shield at the top of your icon for all possibilites head over to: [shields.io](http://shields.io/). You just have to add the string of shield (copied from the URL)

badge --shield "Version-0.0.3-blue"

Sometimes the response from shield.io takes a long time and can timeout. You can adjust the timeout to shield.io with `--shield_io_timeout 10` accordingly.
Sometimes the response from shields.io takes a long time and can timeout. You can adjust the timeout to shields.io with `--shield_io_timeout 10` accordingly.

`--shield_gravity North` changes the postion of the shield on the icon. Choices include: NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast.

In version [0.4.0](https://github.com/HazAT/badge/releases/tag/0.4.0) the default behavior of the shield graphic has been changed. The shield graphic will always be resized to **aspect fill** the icon instead of just adding the shield on the icon. The disable to new behaviour use `--shield_no_resize` which now only puts the shield on the icon again.

Add ```--no_badge``` as an option to hide the beta badge completely if you just want to add a shield.
Add ```--no_badge``` as an option to hide the beta badge completely if you just want to add a shield.

Use `badge --help` to get list all possible parameters.

Expand All @@ -118,7 +118,7 @@ lane :appstore do
#add_badge(alpha: true) #or
#add_badge(custom: "/Users/HazA/Desktop/badge.png") #or
#add_badge(shield: "Version-0.0.3-blue", no_badge: true)

xctool
snapshot
sigh
Expand All @@ -134,7 +134,7 @@ end
If Jenkins has problems finding imagemagick on your mac add following env variable to your job:

PATH=$PATH:/usr/local/bin

Make sure you have imagemagick installed on your machine e.g. for Mac its:

brew install imagemagick
Expand Down
10 changes: 7 additions & 3 deletions lib/badge/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@ def self.alpha_dark_badge
File.join assets, 'alpha_badge_dark.png'
end

def self.shield_base_url
def self.shield_service_name
'shields.io'
end

def self.shield_serveice_base_url
'https://img.shields.io'
end

def self.shield_path
'/badge/'
end

def self.shield_io_timeout
def self.shield_service_timeout
10
end

def self.shield_io_retries
def self.shield_service_retries
10
end

Expand Down
6 changes: 3 additions & 3 deletions lib/badge/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def self.available_options
optional: true),

FastlaneCore::ConfigItem.new(key: :shield,
description: "Overlay a shield from shield.io on your icon, eg: Version-1.2-green",
description: "Overlay a shield from #{Badge.shield_service_name} on your icon, eg: Version-1.2-green",
optional: true),

FastlaneCore::ConfigItem.new(key: :shield_io_timeout,
description: "The timeout in seconds we should wait the get a response from shield.io",
FastlaneCore::ConfigItem.new(key: :shield_service_timeout,
description: "The timeout in seconds we should wait the get a response from #{Badge.shield_service_name}",
type: Integer,
optional: true),

Expand Down
22 changes: 11 additions & 11 deletions lib/badge/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,29 @@ def run(path, options)

shield = nil
begin
timeout = Badge.shield_io_timeout
timeout = options[:shield_io_timeout] if options[:shield_io_timeout]
timeout = Badge.shield_service_timeout
timeout = options[:shield_service_timeout] if options[:shield_service_timeout]
Timeout.timeout(timeout.to_i) do
shield = load_shield(options[:shield]) if options[:shield]
end
rescue Timeout::Error
UI.error "Error loading image from shield.io timeout reached. Use --verbose for more info".red
UI.error "Error loading image from #{Badge.shield_service_name} timeout reached. Use --verbose for more info".red
rescue Curl::Err::CurlError => error
response = error.io
UI.error "Error loading image from shield.io response Error. Use --verbose for more info".red
UI.error "Error loading image from #{Badge.shield_service_name} response Error. Use --verbose for more info".red
UI.verbose response.status if FastlaneCore::Globals.verbose?
rescue MiniMagick::Invalid
UI.error "Error validating image from shield.io. Use --verbose for more info".red
UI.error "Error validating image from #{Badge.shield_service_name}. Use --verbose for more info".red
rescue Exception => error
UI.error "Other error occured. Use --verbose for more info".red
UI.verbose error if FastlaneCore::Globals.verbose?
end

if options[:shield] && shield == nil
if @@retry_attemps >= Badge.shield_io_retries
UI.error "Cannot load image from shield.io skipping it...".red
if @@retry_attemps >= Badge.shield_service_retries
UI.error "Cannot load image from #{Badge.shield_service_name} skipping it...".red
else
UI.message "Waiting for #{timeout.to_i}s and retry to load image from shield.io tries remaining: #{Badge.shield_io_retries - @@retry_attemps}".red
UI.message "Waiting for #{timeout.to_i}s and retry to load image from #{Badge.shield_service_name} tries remaining: #{Badge.shield_service_retries - @@retry_attemps}".red
sleep timeout.to_i
@@retry_attemps += 1
return run(path, options)
Expand Down Expand Up @@ -95,7 +95,7 @@ def run(path, options)

def add_shield(icon, result, shield, alpha_channel, shield_gravity, shield_no_resize, shield_scale, shield_geometry)
UI.message "'#{icon.path}'"
UI.verbose "Adding shield.io image ontop of icon".blue
UI.verbose "Adding #{Badge.shield_service_name} image ontop of icon".blue

shield_scale = shield_scale ? shield_scale.to_f : 1.0

Expand All @@ -120,10 +120,10 @@ def add_shield(icon, result, shield, alpha_channel, shield_gravity, shield_no_re
end

def load_shield(shield_string)
url = Badge.shield_base_url + Badge.shield_path + shield_string + (@@rsvg_enabled ? ".svg" : ".png")
url = Badge.shield_serveice_base_url + Badge.shield_path + shield_string + (@@rsvg_enabled ? ".svg" : ".png")
file_name = shield_string + (@@rsvg_enabled ? ".svg" : ".png")

UI.verbose "Trying to load image from shield.io. Timeout: #{Badge.shield_io_timeout}s".blue
UI.verbose "Trying to load image from #{Badge.shield_service_name}. Timeout: #{Badge.shield_service_timeout}s".blue
UI.verbose "URL: #{url}".blue

Curl::Easy.download(url, file_name)
Expand Down