fastlane-old / spaceship

Ruby library to access the Apple Dev Center and iTunes Connect
https://spaceship.airforce
671 stars 83 forks source link

undefined method `[]' for nil:NilClass #189

Closed realf closed 8 years ago

realf commented 8 years ago

I am trying to update APNS certificates with pem for all apps on team's Apple Developer Portal (over 300 apps for now). After successfull updating several certificates Spaceship fails with error:

undefined method `[]' for nil:NilClass

15:05:15 /usr/local/lib/ruby/gems/2.2.0/gems/spaceship-0.15.1/lib/spaceship/client.rb:257:in `parse_response': undefined method `[]' for nil:NilClass (NoMethodError)
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/spaceship-0.15.1/lib/spaceship/portal/portal_client.rb:60:in `teams'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/spaceship-0.15.1/lib/spaceship/portal/ui/select_team.rb:35:in `select_team'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/spaceship-0.15.1/lib/spaceship/portal/portal_client.rb:76:in `select_team'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/pem-1.1.0/lib/pem/manager.rb:36:in `login'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/pem-1.1.0/lib/pem/manager.rb:10:in `start'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/lib/fastlane/actions/pem.rb:19:in `run'
15:05:15    from /Users/apnsupdater/.jenkins/workspace/Netpulse-fastlane-apns-updater/fastlane/actions/update_apns_certificates.rb:42:in `block in run'
15:05:15    from /Users/apnsupdater/.jenkins/workspace/Netpulse-fastlane-apns-updater/fastlane/actions/update_apns_certificates.rb:36:in `each'
15:05:15    from /Users/apnsupdater/.jenkins/workspace/Netpulse-fastlane-apns-updater/fastlane/actions/update_apns_certificates.rb:36:in `run'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/lib/fastlane/runner.rb:142:in `block (2 levels) in execute_action'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/lib/fastlane/actions/actions_helper.rb:37:in `execute_action'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/lib/fastlane/runner.rb:128:in `block in execute_action'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/lib/fastlane/runner.rb:127:in `chdir'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/lib/fastlane/runner.rb:127:in `execute_action'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/lib/fastlane/fast_file.rb:149:in `method_missing'
15:05:15    from Fastfile:83:in `block (2 levels) in parsing_binding'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/lib/fastlane/lane.rb:36:in `call'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/lib/fastlane/lane.rb:36:in `call'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/lib/fastlane/runner.rb:51:in `block in execute'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/lib/fastlane/runner.rb:46:in `chdir'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/lib/fastlane/runner.rb:46:in `execute'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/lib/fastlane/lane_manager.rb:43:in `cruise_lane'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/lib/fastlane/command_line_handler.rb:31:in `handle'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/bin/fastlane:35:in `block (2 levels) in run'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/commander-4.3.5/lib/commander/command.rb:178:in `call'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/commander-4.3.5/lib/commander/command.rb:178:in `call'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/commander-4.3.5/lib/commander/command.rb:153:in `run'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/commander-4.3.5/lib/commander/runner.rb:428:in `run_active_command'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/commander-4.3.5/lib/commander/runner.rb:68:in `run!'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/commander-4.3.5/lib/commander/delegates.rb:15:in `run!'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/bin/fastlane:152:in `run'
15:05:15    from /usr/local/lib/ruby/gems/2.2.0/gems/fastlane-1.44.0/bin/fastlane:158:in `<top (required)>'
15:05:15    from /usr/local/bin/fastlane:23:in `load'
15:05:15    from /usr/local/bin/fastlane:23:in `<main>'

Crash report id: dbcad4da2142382a16f5382496a86ad6

realf commented 8 years ago

The issue is present in spaceship-0.15.2 as well

KrauseFx commented 8 years ago

Can you share your actions/update_apns_certificates?

realf commented 8 years ago

Hi @KrauseFx, In a nutshell this is what I have.

require "spaceship"

module Fastlane
  module Actions
    module SharedValues
      UPDATE_APNS_CERTIFICATES_CUSTOM_VALUE = :UPDATE_APNS_CERTIFICATES_CUSTOM_VALUE
    end

    # To share this integration with the other fastlane users:
    # - Fork https://github.com/KrauseFx/fastlane
    # - Clone the forked repository
    # - Move this integration into lib/fastlane/actions
    # - Commit, push and submit the pull request

    class UpdateApnsCertificatesAction < Action
      def self.run(params)
        # fastlane will take care of reading in the parameter and fetching the environment variable:
        #         Helper.log.info "Parameter API Token: #{params[:api_token]}"

        # sh "shellcommand ./path"

        # Actions.lane_context[SharedValues::UPDATE_APNS_CERTIFICATES_CUSTOM_VALUE] = "my_val"

        # ENV prefixed vars are defined in env files
        accountManager = CredentialsManager::AccountManager.new(user: ENV['ENV_APPLE_ID'])
        Spaceship.login(accountManager.user, accountManager.password)
        Spaceship.client.team_id = ENV['ENV_TEAM_ID']

        # Save env variables
        saved_pem_app_identifier = ENV['PEM_APP_IDENTIFIER']
        saved_pem_file_name = ENV['PEM_FILE_NAME']

        # List apps on Dev Portal
        apps = Spaceship.app.all
        apps.each do |app|
          ENV['PEM_APP_IDENTIFIER'] = app.bundle_id
          if app.bundle_id.include? '*'
            puts "Skipping pem for Bundle ID: #{app.bundle_id}"
            next
          end

          ENV['PEM_FILE_NAME'] = "production_#{app.bundle_id}"

          puts "Running pem for Bundle ID: #{app.bundle_id}"

          attempt_count = 1
          begin
            Fastlane::Actions::PemAction.run(params)
          rescue
            attempt_count += 1
            if attempt_count < 10
              puts "Retrying to pem. Attempt # #{attempt_count}..."
              retry
            else
              raise
            end
          end
        end

        # Restore env variables
        ENV['PEM_APP_IDENTIFIER'] = saved_pem_app_identifier
        ENV['PEM_FILE_NAME'] = saved_pem_file_name
      end

      #####################################################
      # @!group Documentation
      #####################################################

      def self.description
        # "A short description with <= 80 characters of what this action does"
        "Update all APNS certificates"
      end

      def self.details
        # Optional:
        # this is your change to provide a more detailed description of this action
        "You can use this action to update push certificates for all your apps."
      end

      def self.available_options
        # Define all options your action supports. 
        Fastlane::Actions::PemAction.available_options
      end

      def self.output
        # Define the shared values you are going to provide
        # Example
#         [
#           ['UPDATE_APNS_CERTIFICATES_CUSTOM_VALUE', 'A description of what this value contains']
#         ]
      end

      def self.return_value
        # If you method provides a return value, you can describe here what it does
      end

      def self.authors
        # So no one will ever forget your contribution to fastlane :) You are awesome btw!
        ["realf"]
      end

      def self.is_supported?(platform)
        # you can do things like
        # 
        #  true
        # 
        #  platform == :ios
        # 
        #  [:ios, :mac].include?(platform)
        # 

        platform == :ios
      end
    end
  end
end
KrauseFx commented 8 years ago

Could you try the latest spaceship release?

realf commented 8 years ago

@KrauseFx Since this is a production I cannot do it right now (we have a schedule for this procedure) but when I can I will update the issue. Thanks.

KrauseFx commented 8 years ago

Sounds good :+1:

fastlanebot commented 8 years ago

This issue was migrated to https://github.com/fastlane/fastlane/issues/2038. Please post all further comments there.

fastlane is now a mono repo, you can read more about the change in our blog post. All tools are now available in the fastlane main repo :rocket: