class Object

Public Instance Methods

addInfosToIcon(settings , source_file , dest_file) click to toggle source
# File lib/mercure/update_icon.rb, line 38
def addInfosToIcon (settings , source_file , dest_file)

  projectInfosPath  = settings[:projectInfosPath]
  projectInfos      = Plist::parse_xml(projectInfosPath)

  version = projectInfos["CFBundleVersion"]
  commit  = `git rev-parse --short HEAD`.strip
  branch  = `git rev-parse --abbrev-ref HEAD`.strip
  width   = `identify -format %w #{source_file}`
  caption = iconCaptionForDeploy settings[:deploy]

  command  = "convert -background '#0008'"
  command += " -fill white -gravity center"
  command += " -size #{width}x40"
  command += " caption:\"#{caption}\" \"#{source_file}\""
  command += " +swap -gravity south -composite \"#{dest_file}\""

  system(command)

end
appPath(settings) click to toggle source

Application

# File lib/mercure/paths.rb, line 8
def appPath (settings)
  
  buildDirectory      = settings[:buildDirectory]
  buildConfiguration  = settings[:buildConfiguration]
  buildNumber         = settings[:buildNumber]
  bundleName          = settings[:bundleName]
  
  "#{buildDirectory}/#{buildConfiguration}-iphoneos/#{bundleName}.app"
  
end
buildApp(settings) click to toggle source
# File lib/mercure/build.rb, line 6
def buildApp (settings)
  
  applicationName     = settings[:applicationName]
  projectDirectory    = settings[:projectDirectory]
  
  workspaceName       = settings[:workspaceName]
  schemeName          = settings[:schemeName]
  targetSDK           = settings[:targetSDK]
  
  buildConfiguration  = settings[:buildConfiguration]
  buildDirectory      = settings[:buildDirectory]
  
  puts "Compilation de l'application #{applicationName}"
  
  build_command  = "xcodebuild"
  build_command += " -workspace \"#{workspaceName}\""
  build_command += " -scheme \"#{schemeName}\""
  build_command += " -configuration #{buildConfiguration}"
  build_command += " -sdk iphoneos"
  build_command += " BUILD_DIR=\"#{buildDirectory}\""
  build_command += " BUILD_PRODDUCTS_DIR=\"#{buildDirectory}\"/#{buildConfiguration}-iphoneos"
  build_command += " TARGET_BUILD_DIR=\"#{buildDirectory}\"/#{buildConfiguration}-iphoneos"
  build_command += " CONFIGURATION_BUILD_DIR=\"#{buildDirectory}\"/#{buildConfiguration}-iphoneos"
  build_command += " clean build"
  build_command += " | tee \"#{buildDirectory}/logs/#{applicationName}_building.log\""
  build_command += " | xcpretty -c --report html"
  
  puts build_command
  
  Dir.chdir "#{projectDirectory}"
  system("#{build_command}")
  
end
buildArtefacts(xcode_settings) click to toggle source
# File lib/mercure/deploy.rb, line 227
def buildArtefacts (xcode_settings)
  generateIpa         xcode_settings
  generatePlist       xcode_settings

  # the following line has been commented in order to make it work on Xcode 7
  #  generateChangelog   xcode_settings
end
buildDeploy(deploy) click to toggle source
# File lib/mercure/deploy.rb, line 59
def buildDeploy (deploy)
  
  puts "Chargement des variables"
  settings = load_settings deploy
  
  # on s'assure d'être dans la bonne version du code
  # si le Info.plist ne contient pas de valeur pour la clé
  # :CFBundleVersion (ce qui serait un peu embetant)
  # on taggue le commit courant
  checkOutGitVersion settings

  puts "Création de l'.app"
  buildApp settings
  updateBuild settings
  
  puts "Création de l'.ipa et du .plist"
  buildArtefacts settings
  
end
buildDeployments(plist) click to toggle source

Build

# File lib/mercure/deploy.rb, line 24
def buildDeployments (plist)
  
  deployments = Plist::parse_xml(plist)      
  
  deployments.each do |deploy|
    buildDeploy deploy
  end
  
end
buildDeploymentsByAsking(plist) click to toggle source
# File lib/mercure/deploy.rb, line 34
def buildDeploymentsByAsking (plist)
  
  deployments = Plist::parse_xml(plist)
  
  deployments.each do |deploy|
    
    settings = load_settings deploy
    
    choose do |menu|
      
      versionText = " dans sa version #{settings[:CFBundleVersion]}" if not settings[:CFBundleVersion].nil?
      menu.prompt = "Veux-tu builder #{settings[:applicationName]}#{versionText} ?"

      menu.choice(:oui) do
        say("Bon choix !")
        buildDeploy deploy
      end
      
      menu.choice(:non) { say("Dommage") }
    end

  end  
end
changelogName(settings) click to toggle source

IPA

# File lib/mercure/paths.rb, line 162
def changelogName (settings)

  buildDirectory      = settings[:buildDirectory]
  buildConfiguration  = settings[:buildConfiguration]
  buildNumber         = settings[:buildNumber]
  applicationName     = settings[:applicationName]
  
  pjServerConf        = settings[:deploy]["infosPlist"]["PJServerConf"]

  "changelog.#{applicationName}.#{buildNumber}.html"
    
end
changelogPath(settings) click to toggle source
# File lib/mercure/paths.rb, line 175
def changelogPath (settings)
  
  buildDirectory      = settings[:buildDirectory]
  buildConfiguration  = settings[:buildConfiguration]
  buildNumber         = settings[:buildNumber]
  applicationName     = settings[:applicationName]
  changelogName       = changelogName(settings)
  
  "#{buildDirectory}/#{buildConfiguration}-iphoneos/#{changelogName}"
  
end
checkOutGitVersion(settings) click to toggle source
# File lib/mercure/git.rb, line 5
def checkOutGitVersion (settings)
  
  tags            = `git tag`
  tag_name        = settings[:CFBundleVersion]
  current_commit  = settings[:gitSHA1]
  
  # choose do |menu|
  #   menu.prompt = "Would you like to create a tag for this build ?  "
  #
  #   menu.choice(:yes) { say("Good choice!") }
  #   menu.choice(:no) { say("Too bad") }
  # end
  
  if tags.include?("#{tag_name}\n") == false
    puts "Le tag #{tag_name} n'existe pas."
    puts "Nous allons le créer pour pointer vers le commit actuel (#{current_commit})"

    create_tag = `git tag #{tag_name}`
  end
  
  puts "On checkout le tag #{tag_name}"
end
checkPathOnFTP(host, usermame , password , path) click to toggle source
# File lib/mercure/upload.rb, line 113
def checkPathOnFTP(host, usermame , password , path)
  
  folders = path.split("/")
  
  count = 0

  begin
    ftp = Net::FTP.new(host)
    ftp.login(usermame , password)
  rescue Errno::ECONNRESET => e
    count += 1
    retry unless count > 10
    puts "tried 10 times and couldn't get #{url}: #{e}"
  end
  
  createFolders(ftp , folders)
  
  ftp.close
  
end
createFolders(ftp_connection , folders) click to toggle source
# File lib/mercure/upload.rb, line 134
def createFolders(ftp_connection , folders)
  
  if folders.length < 2
    return
  end
  
  ftp_connection.chdir(folders[0])
  liste = ftp_connection.list
  
  if ! (liste.any? { |element| element.include? folders[1]} )
    ftp_connection.mkdir(folders[1])
  end
  
  createFolders(ftp_connection , folders.slice(1 , folders.length - 1))
  
end
deployDeploy(deploy) click to toggle source

I know, I know

# File lib/mercure/deploy.rb, line 178
def deployDeploy (deploy)
  
  puts "Chargement des variables"
  settings = load_settings deploy
    
  puts "Mise à jour de Parse"
  objectId = updateParse settings
  deploy["parse"]["objectId"] = objectId
  
end
deployDeployments(plist_path) click to toggle source
# File lib/mercure/deploy.rb, line 161
def deployDeployments (plist_path)
  
  plist_content = CFPropertyList::List.new(file: plist_path)
  deployments   = CFPropertyList.native_types(plist_content.value)
  
  deployments.each do |deploy|
    deployDeploy deploy
  end
  
  puts "sauvegardes des infos de parse"
  plist_content.value = CFPropertyList.guess(deployments)
  plist_content.save(plist_path , CFPropertyList::List::FORMAT_XML)
  
end
deployDeploymentsByAsking(plist_path) click to toggle source

Deploy

# File lib/mercure/deploy.rb, line 130
def deployDeploymentsByAsking (plist_path)
  
  plist_content = CFPropertyList::List.new(file: plist_path)
  deployments   = CFPropertyList.native_types(plist_content.value)
  
  deployments.each do |deploy|
    
    settings = load_settings deploy
    
    choose do |menu|
      
      versionText = " dans sa version #{settings[:CFBundleVersion]}" if not settings[:CFBundleVersion].nil?
      menu.prompt = "Veux-tu déployer #{settings[:applicationName]}#{versionText} ?"

      menu.choice(:oui) do
        say("Bon choix !")
        deployDeploy deploy
      end
      
      menu.choice(:non) { say("Dommage") }
    end
    
  end
  
  puts "sauvegardes des infos de parse"
  plist_content.value = CFPropertyList.guess(deployments)
  plist_content.save(plist_path , CFPropertyList::List::FORMAT_XML)
  
end
deployPlistPath(settings) click to toggle source
# File lib/mercure/paths.rb, line 75
def deployPlistPath (settings)

  buildDirectory      = settings[:buildDirectory]
  buildConfiguration  = settings[:buildConfiguration]
  buildNumber         = settings[:buildNumber]
  applicationName     = settings[:applicationName]
  plistName           = plistName settings
  
  "#{buildDirectory}/#{buildConfiguration}-iphoneos/#{plistName}"

end
dsymPath(settings) click to toggle source

Dsym

# File lib/mercure/paths.rb, line 119
def dsymPath (settings)
  
  buildDirectory      = settings[:buildDirectory]
  buildConfiguration  = settings[:buildConfiguration]
  bundleName          = settings[:bundleName]
  
  "#{buildDirectory}/#{buildConfiguration}-iphoneos/#{bundleName}.app.dSYM"
  
end
generateChangelog(deploy) click to toggle source
# File lib/mercure/changelog.rb, line 24
def generateChangelog (deploy)
      
    settings      = load_settings deploy
    changelogPath = changelogPath(settings)
    previousTag   = settings[:deploy]["build"]["previousGitTag"]
    currentTag    = settings[:deploy]["build"]["currentGitTag"]

    name        = 'mercure'
    g           = Gem::Specification.find_by_name( name )
    script_path = File.join( g.full_gem_path, 'lib/mercure/changelog.sh' )

    puts "#{script_path} #{previousTag} #{currentTag} #{changelogPath}"

    system("#{script_path} #{previousTag} #{currentTag} #{changelogPath}")
    
end
generateChangelogs(plist_path) click to toggle source
# File lib/mercure/changelog.rb, line 10
def generateChangelogs (plist_path)
  
  plist_content = CFPropertyList::List.new(file: plist_path)
  deployments   = CFPropertyList.native_types(plist_content.value)
  
  deployments.each do |deploy|
    
    generateChangelog deploy
    
  end

end
generateIpa(settings) click to toggle source
# File lib/mercure/ipa.rb, line 9
def generateIpa settings
    
  buildDirectory      = settings[:buildDirectory]
  buildConfiguration  = settings[:buildConfiguration]
  buildNumber         = settings[:buildNumber]
  applicationName     = settings[:applicationName]
  
  appPath       = appPath(settings)
  ipaPath       = ipaPath(settings)
  
  dsymPath        = dsymPath(settings)
  savedDsymPath   = savedDsymPath(settings)
  zippedDsymPath  = zippedDsymPath(settings)
  
  signingIdentity     = settings[:signingIdentity]
  provisioningProfile = settings[:provisioningProfile]
  
  system "mkdir -p \"#{buildDirectory}/logs/\""
    
  puts "Construction de l'IPA"
  
  # system("codesign -s \"#{signingIdentity}\" \"#{appPath}\"")
  
  signingCommand =  "/usr/bin/xcrun -sdk iphoneos PackageApplication"
  signingCommand +=  " -v \"#{appPath}\""
  signingCommand +=  " -o \"#{ipaPath}\""
  signingCommand +=  " --sign \"#{signingIdentity}\""
  signingCommand +=  " --embed \"#{provisioningProfile}\""
  signingCommand += " | tee \"#{buildDirectory}/logs/#{applicationName}_package.log\""
  
  system("echo \"#{signingCommand}\" | tee \"#{buildDirectory}/logs/#{applicationName}_package.log\" ")
  system signingCommand
  
  system("rm -R -f \"#{savedDsymPath}\"")
  system("cp -R \"#{dsymPath}\" \"#{savedDsymPath}\"")
  system("zip -r \"#{zippedDsymPath}\" \"#{savedDsymPath}\"")
  system("rm -R -f \"#{dsymPath}\"")
  
end
generatePlist(settings) click to toggle source
# File lib/mercure/plist.rb, line 10
def generatePlist (settings)
  
  puts "--> Creation du plist"
  
  buildConfiguration  = settings[:buildConfiguration]
  buildDirectory      = settings[:buildDirectory]
  buildNumber         = settings[:buildNumber]
  projectInfosPath    = settings[:projectInfosPath]
  
  projectInfos    = Plist::parse_xml(projectInfosPath)
  deployPlistPath = deployPlistPath(settings)
  
  deployPlist = Hash.new
  items       = Array.new
  item        = Hash.new
  
  assets        = Array.new
  
  asset         = Hash.new
  asset['kind'] = 'software-package'
  asset['url']  = settings[:deploy]["uploadServer"]["ipa"][0]["publicURL"] + "/" + ipaName(settings)

  assets.push asset
  
  metadata = Hash.new
  
  # the following line has been commented and replaced by th next one in order to make it work on iOS 9...
  # metadata['bundle-identifier'] = settings[:deploy]["infosPlist"]["CFBundleIdentifier"] + ".iOS8"
  metadata['bundle-identifier'] = settings[:deploy]["infosPlist"]["CFBundleIdentifier"]
  metadata['bundle-version']    = projectInfos['CFBundleVersion']
  metadata['subtitle']          = 'by SoLocal'
  metadata['title']             = settings[:deploy]["infosPlist"]["CFBundleDisplayName"]
  metadata['kind']              = 'software'

  item['assets']    = assets
  item['metadata']  = metadata
  
  items.push item
  deployPlist['items'] = items
  Plist::Emit.save_plist(deployPlist , deployPlistPath)
  
end
iconCaptionForDeploy(deploy) click to toggle source
# File lib/mercure/update_icon.rb, line 59
def iconCaptionForDeploy(deploy)
  
  caption = ""
  
  if !deploy["icon"]["addBuildNumber"]
    caption += "#{version}"
  end
  
  
  if !deploy["icon"]["addCommitId"]
    caption += "#{commit}"
  end
    
  caption
end
ipaName(settings) click to toggle source

IPA

# File lib/mercure/paths.rb, line 23
def ipaName (settings)

  buildDirectory      = settings[:buildDirectory]
  buildConfiguration  = settings[:buildConfiguration]
  buildNumber         = settings[:buildNumber]
  applicationName     = settings[:applicationName]
  
  pjServerConf        = settings[:deploy]["infosPlist"]["PJServerConf"]

  if settings[:buildConfiguration] == "Release"
    "#{applicationName}.ipa"
  else
    "#{applicationName}.#{buildNumber}.ipa"
  end
  
end
ipaPath(settings) click to toggle source
# File lib/mercure/paths.rb, line 40
def ipaPath (settings)
  
  buildDirectory      = settings[:buildDirectory]
  buildConfiguration  = settings[:buildConfiguration]
  buildNumber         = settings[:buildNumber]
  applicationName     = settings[:applicationName]
  ipaName             = ipaName(settings)
  
  "#{buildDirectory}/#{buildConfiguration}-iphoneos/#{ipaName}"
  
end
load_settings(deploy) click to toggle source
# File lib/mercure/settings.rb, line 5
def load_settings(deploy)

  settings = Hash.new
  
  settings[:deploy]               = deploy
  
  settings[:applicationName]      = deploy["infosPlist"]["CFBundleDisplayName"]
  settings[:CFBundleVersion]      = deploy["infosPlist"]["CFBundleVersion"]

  settings[:projectDirectory]     = Dir.pwd
  settings[:projectInfosPath]     = settings[:projectDirectory] + "/" + deploy["paths"]["infosPlistRelativePath"]
  
  settings[:bundleName]           = deploy["build"]["projectName"]
  settings[:workspaceName]        = deploy["build"]["workspaceName"]
  settings[:schemeName]           = deploy["build"]["schemeName"]
  settings[:targetSDK]            = deploy["build"]["targetSDK"]

  settings[:buildConfiguration]   = deploy["build"]["buildConfiguration"]
  settings[:buildDirectory]       = settings[:projectDirectory] + "/" + deploy["paths"]["buildRelativePath"]
  settings[:buildNumber]          = `git rev-list --max-count=1 HEAD`[0..7]

  settings[:gitSHA1]              = `git rev-list --max-count=1 HEAD`[0..7]

  settings[:signingIdentity]      = deploy["signing"]["identity"]
  settings[:provisioningProfile]  = "\"#{settings[:projectDirectory]}/#{deploy["signing"]["profile"]}\""
    
  settings

end
localDTMobFile() click to toggle source
# File lib/mercure/paths.rb, line 216
def localDTMobFile
  
  "/tmp/dtmob.xml"
 
end
panDeployments(plist) click to toggle source

pan

# File lib/mercure/deploy.rb, line 193
def panDeployments (plist)
  
  deployments = Plist::parse_xml(plist)      
  
  deployments.each do |deploy|
    
    puts "Chargement des variables"
    settings = load_settings deploy
    
    # on s'assure d'être dans la bonne version du code
    # si le Info.plist ne contient pas de valeur pour la clé
    # :CFBundleVersion (ce qui serait un peu embetant)
    # on taggue le commit courant
    checkOutGitVersion settings

    puts "Création de l'.app"
    buildApp settings
    updateBuild settings
    
    puts "Création de l'.ipa et du .plist"
    buildArtefacts settings
    
    puts "Téléversement de l'.ipa et du .plist"
    uploadArtefacts settings

    puts "Mise à jour de Parse"
    updateParse settings
  
  end
  
end
plistInAppPath(settings) click to toggle source

Plist

# File lib/mercure/paths.rb, line 66
def plistInAppPath (settings)
  
  buildDirectory      = settings[:buildDirectory]
  buildConfiguration  = settings[:buildConfiguration]
  bundleName          = settings[:bundleName]
  
  "#{buildDirectory}/#{buildConfiguration}-iphoneos/#{bundleName}.app/Info.plist"  
end
plistName(settings) click to toggle source
# File lib/mercure/paths.rb, line 96
def plistName (settings)
  
  applicationName     = settings[:applicationName]
  pjServerConf        = settings[:deploy]["infosPlist"]["PJServerConf"]
  buildNumber         = settings[:buildNumber]
  
  "#{applicationName}.#{buildNumber}.plist"
  
end
publicChangelogURL(settings) click to toggle source
# File lib/mercure/paths.rb, line 196
def publicChangelogURL (settings)
  
  publicURL     = settings[:deploy]["uploadServer"]["plist"][0]["publicURL"]  
  changelogName = changelogName (settings)
  
  "#{publicURL}/#{changelogName}"
  
end
publicPlistURL(settings) click to toggle source
# File lib/mercure/paths.rb, line 106
def publicPlistURL (settings)
  
  publicURL  = settings[:deploy]["uploadServer"]["plist"][0]["publicURL"]  
  plistName   = plistName (settings)
  
  "#{publicURL}/#{plistName}"
  
end
remoteChangelogPath(settings , destination) click to toggle source
# File lib/mercure/paths.rb, line 187
def remoteChangelogPath (settings , destination)

  changelogName       = changelogName(settings)
  remotePath          = destination["path"]
  
  "#{remotePath}/#{changelogName}"
  
end
remoteDTMobFile() click to toggle source

Extra

# File lib/mercure/paths.rb, line 210
def remoteDTMobFile
  
  "./dtmob.xml"
  
end
remoteDeployPlistPath(settings , destination) click to toggle source
# File lib/mercure/paths.rb, line 87
def remoteDeployPlistPath (settings , destination)
  
  remotePath  = destination["path"]  
  plistName   = plistName (settings)
  
  "#{remotePath}/#{plistName}"
  
end
remoteDsymPath(settings , destination) click to toggle source
# File lib/mercure/paths.rb, line 146
def remoteDsymPath (settings , destination)
  
  buildNumber         = settings[:buildNumber]
  applicationName     = settings[:applicationName]  
  
  remotePath  = destination["path"]  
  dsymName    = "#{applicationName}.#{buildNumber}.app.dSYM.zip"
  
  "#{remotePath}/#{dsymName}"
  
end
remoteIpaPath(settings , destination) click to toggle source
# File lib/mercure/paths.rb, line 52
def remoteIpaPath (settings , destination)

  ipaName             = ipaName(settings)
  remotePath          = destination["path"]
  
  "#{remotePath}/#{ipaName}"
  
end
savedDsymPath(settings) click to toggle source
# File lib/mercure/paths.rb, line 129
def savedDsymPath (settings)
  
  buildDirectory      = settings[:buildDirectory]
  buildConfiguration  = settings[:buildConfiguration]
  buildNumber         = settings[:buildNumber]
  applicationName     = settings[:applicationName]
  
  "#{buildDirectory}/#{buildConfiguration}-iphoneos/#{applicationName}.#{buildNumber}.app.dSYM"
  
end
tagGit(settings) click to toggle source
# File lib/mercure/git.rb, line 28
def tagGit (settings)
  
  tag_name       = settings[:CFBundleVersion]
  current_commit = settings[:gitSHA1]
  
  # si le tag existe déjà on l'efface
  tags = `git tag`
  
  if tags.include?("#{tag_name}\n")
    puts "Le tag #{tag_name} existe déjà."
    puts "Nous allons le faire pointer vers le commit actuel (#{current_commit})"

    delete_tag = `git tag -d #{tag_name}`
  end
  
  create_tag = `git tag #{tag_name}`

end
updateBuild(settings) click to toggle source
# File lib/mercure/build.rb, line 40
def updateBuild (settings)
  
  updateIcon settings
    
  projectInfosPath  = plistInAppPath(settings)
  
  puts "Mise-à-jour du fichier #{projectInfosPath}"
  
  # projectInfos      = Plist::parse_xml(projectInfosPath)
  
  plist         = CFPropertyList::List.new(file: projectInfosPath)
  projectInfos  = CFPropertyList.native_types(plist.value)
  
  settings[:deploy]["infosPlist"].each do |key , value|
    projectInfos[key] = value
  end
  
  # ajout du SHA1 du commit servant à builder cette version
  projectInfos["lastCommitSHA1"] = settings[:gitSHA1]
  
  
  plist.value = CFPropertyList.guess(projectInfos)
  plist.save(projectInfosPath , CFPropertyList::List::FORMAT_BINARY)
  
end
updateIcon(settings) click to toggle source

adapt this shell script in ruby www.merowing.info/2013/03/overlaying-application-version-on-top-of-your-icon/

# File lib/mercure/update_icon.rb, line 11
def updateIcon (settings)

  iconsBasePath = "#{settings[:projectDirectory]}/PagesJaunes/Data/Images/SPLASH+ICONE"
  icons = [["Icon_base.png" , "Icon.png"] , ["Icon_base@2x.png" , "Icon@2x.png"]]
  
  should_update_icon = settings[:deploy]["icon"]["addExtraInfosInIcon"]
  
  if !should_update_icon
    return
  end
  
  basePath = appPath(settings)

  icons.each do |files|
    
    source_file = "#{iconsBasePath}/#{files[0]}"
    dest_file   = "#{basePath}/#{files[1]}"
    
    puts "Modification de #{source_file}"
    puts "vers #{dest_file}"

    addInfosToIcon settings , source_file , dest_file
    
  end

end
updateParse(settings) click to toggle source
# File lib/mercure/parse.rb, line 9
def updateParse (settings)

  Parse.init  application_id: settings[:deploy]["parse"]["appId"],
              api_key:        settings[:deploy]["parse"]["apiKey"]
              
  parseInfos = settings[:deploy]["parse"]
  
  objectId = parseInfos["objectId"]
  
  if (objectId.nil? or objectId.length == 0)
    appVersion = Parse::Object.new("ApplicationVersion")
  else
    puts "On a déjà déployé cette version, on la met à jour"
    appVersionsQuery = Parse::Query.new("ApplicationVersion")
    appVersionsQuery.eq("objectId", objectId)
    appVersion = appVersionsQuery.get.first
  end

  appVersion["applicationId"]    = parseInfos["applicationId"]
  appVersion["versionNumber"]    = parseInfos["versionNumber"]
  appVersion["versionChangeLog"] = parseInfos["versionChangeLog"]
  appVersion["versionLevel"]     = parseInfos["versionLevel"].to_i
  appVersion["versionUrl"]       = publicPlistURL settings
  appVersion["changelogUrl"]     = publicChangelogURL settings

  result = appVersion.save
  
  if (objectId.nil? or objectId.length == 0)
    puts "le déploiement a été créée"
  else
    puts "le déploiement a bien été mis à jour"
  end  
  
  # on "met à jour" l'application
  
  appQuery = Parse::Query.new("Application")
  appQuery.eq("objectId", parseInfos["applicationId"])
  app = appQuery.get.first
  
  dontCare = app.save
  
  result["objectId"]
  
end
uploadArtefacts(settings) click to toggle source
# File lib/mercure/upload.rb, line 13
def uploadArtefacts(settings)
  
  uploadPlist       settings
  uploadIPA         settings
  # uploadChangelog   settings
  
end
uploadChangelog(settings) click to toggle source
# File lib/mercure/upload.rb, line 74
def uploadChangelog(settings)
  
  settings[:deploy]["uploadServer"]["plist"].each do |destination|
    
    changelogPath         = changelogPath       (settings)
    remoteChangelogPath   = remoteChangelogPath (settings , destination)
    
    files_to_upload = [[changelogPath , remoteChangelogPath]]
    
    uploadFiles(settings , destination , files_to_upload)
    
  end
  
end
uploadDeploy(deploy) click to toggle source
# File lib/mercure/deploy.rb, line 118
def uploadDeploy (deploy)
  puts "Chargement des variables"
  settings = load_settings deploy
  
  puts "Téléversement de l'.ipa et du .plist"
  uploadArtefacts settings
end
uploadDeployments(plist) click to toggle source
# File lib/mercure/deploy.rb, line 108
def uploadDeployments (plist)
  
  deployments = Plist::parse_xml(plist)      
  
  deployments.each do |deploy|
    uploadDeploy deploy
  end
end
uploadDeploymentsByAsking(plist) click to toggle source

Upload

# File lib/mercure/deploy.rb, line 84
def uploadDeploymentsByAsking (plist)
  
  deployments = Plist::parse_xml(plist)
  
  deployments.each do |deploy|
    
    settings = load_settings deploy
    
    choose do |menu|
      
      versionText = " dans sa version #{settings[:CFBundleVersion]}" if not settings[:CFBundleVersion].nil?
      menu.prompt = "Veux-tu uploader #{settings[:applicationName]}#{versionText} ?"

      menu.choice(:oui) do
        say("Bon choix !")
        uploadDeploy deploy
      end
      
      menu.choice(:non) { say("Dommage") }
    end

  end  
end
uploadFiles(settings , destination , files_to_upload) click to toggle source
# File lib/mercure/upload.rb, line 21
def uploadFiles(settings , destination , files_to_upload)
  
  host    = destination["host"]
  login   = destination["login"]
  path    = destination["path"]
  
  if (destination["protocol"] == "ssh")
    uploadViaSSH(host , login , path, files_to_upload)

  elsif (destination["protocol"] == "ftp")
    password = destination["password"]
    uploadViaFTP(host , login , password, path, files_to_upload)

  else 
    puts "Protocole de téléversement inconnu"

  end
  
end
uploadIPA(settings) click to toggle source
# File lib/mercure/upload.rb, line 41
def uploadIPA(settings)

  settings[:deploy]["uploadServer"]["ipa"].each do |destination|
    
    ipaPath         = ipaPath (settings)
    remoteIpaPath   = remoteIpaPath (settings , destination)
    
    dsymPath        = zippedDsymPath(settings)
    remoteDsymPath  = remoteDsymPath(settings , destination)
    
    files_to_upload = [[ipaPath , remoteIpaPath] , [dsymPath , remoteDsymPath]]
    
    uploadFiles(settings , destination , files_to_upload)
    
  end
  
end
uploadPlist(settings) click to toggle source
# File lib/mercure/upload.rb, line 59
def uploadPlist(settings)
  
  settings[:deploy]["uploadServer"]["plist"].each do |destination|
    
    deployPlistPath         = deployPlistPath       (settings)
    remoteDeployPlistPath   = remoteDeployPlistPath (settings , destination)
    
    files_to_upload = [[deployPlistPath , remoteDeployPlistPath]]
    
    uploadFiles(settings , destination , files_to_upload)
    
  end
  
end
uploadViaFTP(host, usermame , password , path, files_to_upload) click to toggle source

files_to_upload is an array of arrays that must be like [local_file_path , remote_file_path]

# File lib/mercure/upload.rb, line 154
def uploadViaFTP(host, usermame , password , path, files_to_upload)
  
  checkPathOnFTP(host, usermame , password , path)
  
  # on est sûr d'avoir le dossier qu'il faut
  # on fait la vraie connexion
  
  ftp = Net::FTP.new(host)
  
  ftp.login(usermame , password)
  
  # ftp.chdir(path)
  
  files_to_upload.each do |names|
    puts "host: #{host}"
    puts 'Envoi du fichier ' + names[0] + ' vers ' + names[1]
    ftp.putbinaryfile(names[0].to_s, names[1])
  end
  
  ftp.close
  
end
uploadViaSSH(host , login , path, files_to_upload) click to toggle source

files_to_upload is an array of arrays that must be like [local_file_path , remote_file_path]

# File lib/mercure/upload.rb, line 91
def uploadViaSSH(host , login , path, files_to_upload)

  # on vérifie si le dossier existe
  check_command = "if [ ! -d \"#{path}\" ]; then mkdir \"#{path}\"; fi"
  
  Net::SSH.start(host, login) do |ssh|
    # capture all stderr and stdout output from a remote process
    output = ssh.exec!(check_command)
    
    puts "check: #{check_command}"
    puts "output : #{output}"
  end

  Net::SCP.start(host, login) do |scp|
    files_to_upload.each do |names|
      puts 'Envoi du fichier ' + names[0] + ' vers ' + names[1]
      scp.upload!(names[0].to_s, names[1])
    end
  end

end
zippedDsymPath(settings) click to toggle source
# File lib/mercure/paths.rb, line 140
def zippedDsymPath (settings)
  
  savedDsymPath(settings) + ".zip"
  
end