PhoneGap Build API - Ant deploy helper script

After starting to develop a mobile app based on PhoneGap and its build service, I decided to automate the deployment via REST. Here is my little ant script. Feel free to adopt, extend, comment and / or share.
<?xml version="1.0" encoding="UTF-8"?>
<project name='PGBuildDeployer' default="info">

    <property file="./build.properties" />
 <property name="project.tmp" value="./tmp/www"/>
 <property name="project.zip" value="www.zip"/>
 <property name="project.assetDir" value="./assets/www"/> 
 <property name="project.file" value="index.html"/>
 <property name="api.urlprefix" value="https://build.phonegap.com/api/v1/apps/${project.id}" />
 <property name="api.urlsuffix" value="?auth_token=${user.token}" />
 <property name="api.keystore" value="https://build.phonegap.com/api/v1/keys/ios/${ios.key}${api.urlsuffix}" />
 
 <target name='info'>
     <echo message="init: Preparing data for upload" />
     <echo message="deploy: Deploy th phonegap's build service" />
    </target>
    
 <target name="init">
     
     <!-- Prepare temp -->
     <delete dir="${project.tmp}" quiet="true" />
     <mkdir dir="${project.tmp}"/>               
     <copy todir="${project.tmp}">
       <fileset dir="${project.assetDir}" excludes="${project.file}" />
     </copy>

     <!-- Remove cordova and debug libraries -->     
     <copy file="${project.assetDir}/${project.file}" tofile="${project.tmp}/${project.file}">
         <filterchain>
    <linecontainsregexp negate="true">
                 <regexp pattern="phonegap-desktop\.js" />                 
             </linecontainsregexp>            
           
          <linecontainsregexp negate="true">
     <regexp pattern="cordova-\d*\.\d*\.\d*\.js"/>
    </linecontainsregexp>
            </filterchain>
  </copy>
     
     <!-- Insert phonegap.js -->
     <replaceregexp file="${project.tmp}/${project.file}"
               match="&lt;!--phonegap-->"
               replace="&lt;script src='phonegap\.js'>&lt;\/script>"
               byline="true" />
     
     <!-- Replace facebook plugin paths --> 
     <replaceregexp file="${project.tmp}/${project.file}"
               match="\.\/js\/facebook_js_sdk\.js"
               replace="facebook-js-sdk\.js"
               byline="true" />    
     <replaceregexp file="${project.tmp}/${project.file}"
               match="\.\/js\/cdv-plugin-fb-connect\.js"
               replace="cdv-plugin-fb-connect\.js"
               byline="true" />
               
     <!-- Remove uneccesary files -->
     <delete file="${project.tmp}/debugdata.json" />
  <delete file="${project.tmp}/js/phonegap-desktop.js" />
  <delete file="${project.tmp}/js/cordova-2.2.0.js" />
  <delete file="${project.tmp}/js/cdv-plugin-fb-connect.js" />
  <delete file="${project.tmp}/js/facebook_js_sdk.js" />
  
  <!-- Packing files -->
  <zip destfile="${project.tmp}/${project.zip}" basedir="${project.tmp}" />
 </target> 
 
 <!-- Upload to Phonegap build service  --> 
 <target name='deploy' depends="init">
     <!-- Upload -->
  <exec executable='curl' failonerror='true'>
      <arg value='-X'/>
   <arg value='PUT'/>
   <arg value='-F'/>
   <arg value='file=@${project.tmp}/${project.zip}'/>   
   <arg value='${api.urlprefix}${api.urlsuffix}'/>   
  </exec>
  
  <!-- Unlock iOs key -->  
     <exec executable="curl" failonerror="true">   
      <arg value="-d" />
      <arg value="'data={&quot;password&quot;:&quot;${ios.pwd}&quot;}'" />
      <arg value='-X'/>
   <arg value='PUT'/>
      <arg value="${api.keystore}" />
  </exec>

  <!-- Trigger build -->
  <exec executable="curl" failonerror="true">
   <arg value='-X'/>
   <arg value='POST'/>
      <arg value="-d" />
      <arg value="''" />
      <arg value="${api.urlprefix}/build${api.urlsuffix}" />
  </exec>
 </target>

</project>

Needed properties:

project.name=FooBar
project.id=12345
user.email=abc@mail.de
user.token=GJopNKbk12zuEvRg75Gv
ios.key=12345
ios.pwd=XXX

No comments:

Post a Comment