Search code examples
gitgithubphing

Phing and github


I am trying to automate the deployment of code from a private github repo using phing but having trouble trying to find something that works like an SVN export.

I have read a few post on git archive and git checkout-index but have struggled to get these working with github. I get the impression that they are keen for us to use the zip download as they can cache this etc.

I wouldn't mind downloading the zip from github if there was a simple task in Phing to do this, a simple http task didn't work as it's over https and I guess some sort of authentication is needed first.

I managed to use gitclone task in Phing but the ".git" hidden folder is cloned too which is causing massive headaches...mainly because on subsequent builds I can't delete the build folder as it suggests certain git files, namely *.idx or *.pack are in use.

Has anyone had any luck with phing and a private github repo?

Thanks


Solution

  • @AYK My bad, have recently been exploring deployment options and think will roll with Capistrano...

    Anyway this was my build script I ended up using temporarily with people's advice...

    • Let's assume my app lives in "C:\app"
    • Let's assume this build.xml file lives in "C:\app"
    • Let's assume my app also contains a git repo "C:\app.git"
    • Delete any build & deploy directories "C:\app\build" and "C:\app\deploy" that may exist from a previous build
    • Make directories "C:\app\build" and "C:\app\deploy", will hold the git checkout and final code to deploy
    • Excuting the git checkout as suggested checks out code from git and puts it into "C:\app\build"
    • There are certain directories like docs I don't want to go out so I copy files I want to deploy to "C:\app\deploy"

    • The problem I had with Phing is the scp part, needed ssh2 dll in PHP which I didn't have nor did I want to spend time trying to compile source for it.

    • So all in all I achieved what I originally wanted with Phing but after spending an evening with Capistrano I'm converted

    == build.xml ==

    <?xml version="1.0" encoding="UTF-8"?>
    
    <project description="" name="MyProject" default="build" basedir=".">
    
        <property file="build.properties" />
        <tstamp>
        <format property="build.time" pattern="%Y%m%d_%H%I" />
        </tstamp>
    
        <!-- ============================================  -->
        <!-- Target: prepare                                 -->
        <!-- ============================================  -->
        <target name="prepare">
        <echo msg="Deleting old build and deploy dirs" />
        <delete dir="./build/" includeemptydirs="true" failonerror="true" />
        <delete dir="./deploy/" includeemptydirs="true" failonerror="true" />
        </target>
    
        <!-- ============================================  -->
        <!-- Target: create                                -->
        <!-- ============================================  -->
        <target name="create" depends="prepare">
        <echo msg="Creating fresh build and deploy directories" />
        <mkdir dir="./build/" />
        <mkdir dir="./deploy/" />
        </target>
    
        <!-- ============================================  -->
        <!-- Target: gitclone                              -->
        <!-- ============================================  -->
        <target name="gitcheckout" depends="create">
        <echo msg="Checking out latest code" />
        <exec command="git checkout-index --prefix ./build/ -a"></exec>
        </target>
    
        <!-- ============================================  -->
        <!-- Target: preparedeploy                         -->
        <!-- ============================================  -->
        <target name="preparedeploy" depends="gitcheckout">
        <echo msg="Preparing deploy" />
        <copy todir="./deploy/" >
            <fileset dir=".">
            <include name="cgi-bin/**" />
            <include name="htdocs/**" />
            </fileset>
        </copy>
        <mkdir dir="./deploy/logs" />
        </target>
    
        <!-- ============================================  -->
        <!-- Target: cleanup                                 -->
        <!-- ============================================  -->
        <target name="cleanup" depends="preparedeploy">
        <echo msg="Deleting build dir" />
        <delete dir="./build/" includeemptydirs="true" failonerror="true" />
        </target>
    
        <!-- ============================================  -->
        <!-- Target: build                                 -->
        <!-- ============================================  -->
        <target name="build" depends="cleanup, preparedeploy, gitcheckout, create, prepare">
        <echo msg="Starting build ${build.time}" />
        </target>
    
    </project>