Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Commit

Permalink
Update (#22)
Browse files Browse the repository at this point in the history
* rspec, fix if TargetAttributes missing

* fix registering device

* do not force enable device

* fixed provided an older version log

* check if managed profile contains the provided cert

* fix

* check if profile expired

* DateTime Time comparation fix

* pr fixes

* PR fixes
  • Loading branch information
godrei committed Mar 29, 2018
1 parent 8f8503e commit 058787c
Show file tree
Hide file tree
Showing 32 changed files with 1,539 additions and 60 deletions.
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--require spec_helper
20 changes: 13 additions & 7 deletions .rubocop_todo.yml
@@ -1,33 +1,39 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-03-20 12:59:14 +0100 using RuboCop version 0.53.0.
# on 2018-03-29 11:31:51 +0200 using RuboCop version 0.54.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 25
# Offense count: 27
Metrics/AbcSize:
Max: 65

# Offense count: 3
# Offense count: 4
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 311

# Offense count: 11
# Offense count: 12
Metrics/CyclomaticComplexity:
Max: 18

# Offense count: 32
# Offense count: 33
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 61

# Offense count: 10
# Offense count: 11
Metrics/PerceivedComplexity:
Max: 22

# Offense count: 1
# Cop supports --auto-correct.
Style/BlockComments:
Exclude:
- 'spec/spec_helper.rb'

# Offense count: 1
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Expand All @@ -51,7 +57,7 @@ Style/RescueStandardError:
- 'lib/autoprovision/portal/profile_client.rb'
- 'step.rb'

# Offense count: 183
# Offense count: 202
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Expand Up @@ -4,3 +4,8 @@ gem 'fastlane'
gem 'openssl'
gem 'plist'
gem 'xcodeproj'

group :test do
gem 'rspec'
gem 'rubocop'
end
55 changes: 45 additions & 10 deletions Gemfile.lock
@@ -1,9 +1,10 @@
GEM
remote: https://rubygems.org/
specs:
CFPropertyList (2.3.6)
CFPropertyList (3.0.0)
addressable (2.5.2)
public_suffix (>= 2.0.2, < 4.0)
ast (2.4.0)
atomos (0.1.2)
babosa (1.0.2)
claide (1.0.2)
Expand All @@ -13,10 +14,11 @@ GEM
highline (~> 1.7.2)
declarative (0.0.10)
declarative-option (0.1.0)
diff-lcs (1.3)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.2.1)
excon (0.60.0)
excon (0.62.0)
faraday (0.14.0)
multipart-post (>= 1.2, < 3)
faraday-cookie_jar (0.0.6)
Expand All @@ -25,13 +27,13 @@ GEM
faraday_middleware (0.12.2)
faraday (>= 0.7.4, < 1.0)
fastimage (2.1.1)
fastlane (2.81.0)
fastlane (2.88.0)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.3, < 3.0.0)
babosa (>= 1.0.2, < 2.0.0)
bundler (>= 1.12.0, < 2.0.0)
colored
commander-fastlane (>= 4.4.5, < 5.0.0)
commander-fastlane (>= 4.4.6, < 5.0.0)
dotenv (>= 2.1.1, < 3.0.0)
excon (>= 0.45.0, < 1.0.0)
faraday (~> 0.9)
Expand All @@ -50,16 +52,17 @@ GEM
public_suffix (~> 2.0.0)
rubyzip (>= 1.1.0, < 2.0.0)
security (= 0.1.3)
simctl (~> 1.6)
slack-notifier (>= 2.0.0, < 3.0.0)
terminal-notifier (>= 1.6.2, < 2.0.0)
terminal-table (>= 1.4.5, < 2.0.0)
tty-screen (>= 0.6.3, < 1.0.0)
tty-spinner (>= 0.8.0, < 1.0.0)
word_wrap (~> 1.0.0)
xcodeproj (>= 1.5.2, < 2.0.0)
xcodeproj (>= 1.5.7, < 2.0.0)
xcpretty (>= 0.2.4, < 1.0.0)
xcpretty-travis-formatter (>= 0.0.3)
gh_inspector (1.1.2)
gh_inspector (1.1.3)
google-api-client (0.13.6)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 0.5)
Expand Down Expand Up @@ -93,24 +96,54 @@ GEM
multi_json (1.13.1)
multi_xml (0.6.0)
multipart-post (2.0.0)
nanaimo (0.2.3)
nanaimo (0.2.4)
naturally (2.1.0)
openssl (2.1.0)
os (0.9.6)
parallel (1.12.1)
parser (2.5.0.5)
ast (~> 2.4.0)
plist (3.4.0)
powerpack (0.1.1)
public_suffix (2.0.5)
rainbow (3.0.0)
representable (3.0.4)
declarative (< 0.1.0)
declarative-option (< 0.2.0)
uber (< 0.2.0)
retriable (3.1.1)
rouge (2.0.7)
rspec (3.7.0)
rspec-core (~> 3.7.0)
rspec-expectations (~> 3.7.0)
rspec-mocks (~> 3.7.0)
rspec-core (3.7.1)
rspec-support (~> 3.7.0)
rspec-expectations (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-mocks (3.7.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
rubocop (0.54.0)
parallel (~> 1.10)
parser (>= 2.5)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.9.0)
rubyzip (1.2.1)
security (0.1.3)
signet (0.8.1)
addressable (~> 2.3)
faraday (~> 0.9)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
simctl (1.6.2)
CFPropertyList
naturally
slack-notifier (2.3.2)
terminal-notifier (1.8.0)
terminal-table (1.8.0)
Expand All @@ -125,12 +158,12 @@ GEM
unf_ext (0.0.7.5)
unicode-display_width (1.3.0)
word_wrap (1.0.0)
xcodeproj (1.5.6)
CFPropertyList (~> 2.3.3)
xcodeproj (1.5.7)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.2)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.2.3)
nanaimo (~> 0.2.4)
xcpretty (0.2.8)
rouge (~> 2.0.7)
xcpretty-travis-formatter (1.0.0)
Expand All @@ -143,6 +176,8 @@ DEPENDENCIES
fastlane
openssl
plist
rspec
rubocop
xcodeproj

BUNDLED WITH
Expand Down
19 changes: 16 additions & 3 deletions bitrise.yml
Expand Up @@ -25,13 +25,26 @@ workflows:
- audit-this-step
steps:
- script:
title:
title: bundle install
inputs:
- content: |-
#!/bin/bash
set -e
bundle install
- script:
title: rubocop
inputs:
- content: |-
#!/bin/bash
set -e
bundle exec rubocop
- script:
title: rspec
inputs:
- content: |-
#!/bin/bash
set -e
gem install rubocop --no-document
rubocop
bundle exec rspec
after_run:
- test_bundle_id
- test_xcode_managed
Expand Down
1 change: 1 addition & 0 deletions lib/autoprovision.rb
Expand Up @@ -4,5 +4,6 @@

require_relative 'autoprovision/project_helper'
require_relative 'autoprovision/keychain_helper'
require_relative 'autoprovision/utils'

require_relative 'autoprovision/portal/device_client'
15 changes: 2 additions & 13 deletions lib/autoprovision/certificate_helper.rb
@@ -1,4 +1,5 @@
require_relative 'certificate_info'
require_relative 'utils'
require_relative 'portal/certificate_client'

# CertificateHelper ...
Expand Down Expand Up @@ -106,18 +107,6 @@ def certificate_info(distribution_type)
end
end

def certificate_common_name(certificate)
common_name = certificate.subject.to_a.find { |name, _, _| name == 'CN' }[1]
common_name = common_name.force_encoding('UTF-8')
common_name
end

private

def certificate_name_and_serial(certificate)
"#{certificate_common_name(certificate)} [#{certificate.serial}]"
end

def identify_certificate_infos(certificate_infos)
Log.info('Identify Certificates on Developer Portal')

Expand Down Expand Up @@ -183,7 +172,7 @@ def download(portal_certificate)
def certificate_matches(certificate1, certificate2)
return true if certificate1.serial == certificate2.serial

if certificate_common_name(certificate1) == certificate_common_name(certificate2)
if certificate_common_name(certificate1) == certificate_common_name(certificate2) && certificate1.not_after < certificate2.not_after
Log.warn("Provided an older version of #{certificate_common_name(certificate1)} certificate (serial: #{certificate1.serial} expire: #{certificate1.not_after}),\n" \
"please download the most recent version from the Apple Developer Portal (serial: #{certificate2.serial} expire: #{certificate2.not_after}) and use it on Bitrise!")
end
Expand Down
10 changes: 3 additions & 7 deletions lib/autoprovision/portal/device_client.rb
Expand Up @@ -5,14 +5,14 @@
module Portal
# DeviceClient ...
class DeviceClient
def self.ensure_test_devices(test_devices)
def self.ensure_test_devices(test_devices, device_client = Spaceship::Portal.device)
if test_devices.to_a.empty?
Log.success('no test devices registered on bitrise')
return
end

portal_devices = nil
run_and_handle_portal_function { portal_devices = Spaceship::Portal.device.all(mac: false, include_disabled: true) || [] }
run_and_handle_portal_function { portal_devices = device_client.all(mac: false, include_disabled: true) || [] }
test_devices.each do |test_device|
registered_test_device = nil

Expand All @@ -25,10 +25,8 @@ def self.ensure_test_devices(test_devices)
end

unless registered_test_device
registered_test_device = nil

begin
Spaceship::Portal.device.create!(name: test_device.name, udid: test_device.udid)
registered_test_device = device_client.create!(name: test_device.name, udid: test_device.udid)
rescue Spaceship::Client::UnexpectedResponse => ex
message = result_string(ex)
raise ex unless message
Expand All @@ -41,8 +39,6 @@ def self.ensure_test_devices(test_devices)
end

raise 'failed to find or create device' unless registered_test_device

registered_test_device.enable!
end

Log.success("every test devices (#{test_devices.length}) registered on bitrise are registered on developer portal")
Expand Down

0 comments on commit 058787c

Please sign in to comment.