Showing posts with label NAnt. Show all posts
Showing posts with label NAnt. Show all posts

July 18, 2012

Build Process Overview

The build process is an art (ofcoruse an engineering process) of getting a shippable / deployable artifacts for any software product. The steps to create the installable component / artifact from the code base would remain the same irrespective of the Product Technology, Packaging Software, Build automation Tools and Source Control Software (TFS, Subversion, Seapine Surround etc.) used.
The build process is categorized into five main stages as described below

Key Point: Intimate the stake holders through an automated email on success or failure of the build, at any stage.

1.       Preparing the Build Environment

a.   Clean the Build Working directory (BuildScripts, Product / Installer source code, previous artifacts etc.
b.   Checkout the version header files (usually assembly info files), update it with the latest build number and check-in back to Source Control. This can be done with some 3rd party tool or even with a small in house tool
c.   Label the branch or create a snapshot branch
d.   Get the Product / Installer source from source control system based on the label or snapshot branch created in the previous step.

2.       Actual Build Process

a.   Compile the Product source
b.   For more than one installer, which requires independent Staging area, repeat the step 2b.
                             i.    Form the Staging area
                             ii.   Compile the installers / merge modules
                  [Note: Staging Area is the deployment structure with recently compiled assemblies and misc files in an organized folder structure.]

3.       Post Build Process

a.   Consolidate the logs to a common location
b.   Copy the reference merge modules / assemblies to the Artifacts folder and check-in
                             i.     Checkout the files / folder
                             ii.    Copy the reference merge modules / assemblies to the Artifacts folder
                             iii.   Check-in them back.
c.   Copy the Installers to Artifacts folder
d.   Compress the Artifacts, if required (7z works well for command line compression)
e.   Copy the Artifacts, Source Code etc to common release area for permanent archival and ftp the same if required.

4.      Deploying on Sandbox machine

             a.  Rever to the existing snapshot of the Sandbox machine
             b.  Copy the installer to the Sandbox machine
             c.  Install & Configure

5.      Running Automated Test Suite

             a.  Invoke the Automated Test Suite. On need basis, one or more Virtualized Images can be 
                  used for running / verifying the automation suite.

September 16, 2011

NAnt - Surround SCM Tasks from NAnt Contrib

sscmget -- Gets files from a Surround SCM repository.

Usage:   Get all files and repositories from repository 'Mainline/Widget' recursively from the 'Widget 1.0' branch to the working directory setup for user 'administrator'. This call forces the file retrieval from the server even if the local file is current and overwrites any local files that are writable with the server copy.
<sscmget
    serverconnect="localhost:4900"
    serverlogin="administrator:"
    file="/"
    branch="Widget 1.0"
    repository="Mainline/Widget"
   recursive="true"
    force="true"
    overwrite="true"
/>
Source: http://nantcontrib.sourceforge.net/release/0.85/help/tasks/sscmget.html

sscmlabel -- Creates file or repository labels for a Surround SCM repository.

Usage: Label version 4 of the file 'Mainline/Widget/Widget.java' in the 'Widget 1.0' branch with 'Release 1.0.1' and the given comment. An existing 'Release 1.0.1' label on this file to be moved to version 4 of the file.
<sscmlabel
    serverconnect="localhost:4900"
    serverlogin="administrator:"
    branch="Widget 1.0"
    repository="Mainline/Widget"
    file="readme.txt"
    label="Release 1.0.1"
    overwritelabel=" true"
     comment=" This labels the final build for the release of Widget 1.0.1."
    version=" 4"
/>
Source: http://nantcontrib.sourceforge.net/release/0.85/help/tasks/sscmlabel.html

 sscmcheckin -- Checks in files in Surround SCM repository.

Usage: Check in file 'Mainline/Widget/Widget.java' from the 'Widget 1.0' branch from the working directory setup for user 'administrator' with comment 'I made some changes'. Set the 'Release 1.1.1' label to this new version, even if the label already exists on an earlier version.
<sscmcheckin
    serverconnect="localhost:4900"
    serverlogin="administrator:"
    file="Widget.java"
    branch="Widget 1.0"
    repository="Mainline/Widget"
    comment="I made some changes"
    label="Release 1.1.1"
    overwritelabel="true"
/>
Source: http://nantcontrib.sourceforge.net/release/0.85/help/tasks/sscmcheckin.html

sscmcheckout -- Checks out files from a Surround SCM repository.

Usage:   Check Out version 1 of the file 'Mainline/Widget/Widget.java' exclusively from the 'Widget 1.0' branch to the working directory setup for user 'administrator'. Writable local files are not overwritten, even if they are out of date.
<sscmcheckout
    serverconnect="localhost:4900"
    serverlogin="administrator:"
    quiet="true"
    file="Widget.java"
    branch="Widget 1.0"
    repository="Mainline/Widget"
    overwrite="false"
    writable="true"
    version="1"
    exclusive="true"
/>
Source: http://nantcontrib.sourceforge.net/release/0.85/help/tasks/sscmcheckout.html
 
In addition there are 2 more tasks for Surround SCM sscmfreeze and sscmunfreeze.
 Note: that All the task in this section are provided by NAnt contrib
 

NAnt - Some userful Tasks


1) xmlpeek -- Extracts text from an XML file at the location specified by an XPath expression

Usage: xml file used is for the given example is
<? xml version="1.0" encoding="utf-8”?>
<configuration xmlns="http://www.gordic.cz/shared/project-config/v_1.0.0.0">
    <appSettings>
        <add key="server" value="testhost.somecompany.com" />
    </appSettings>
</configuration>

Using xmlpeek to extract the value of add node where key =’server’

<xmlpeek
    file="App.config"
    xpath="/x:configuration/x:appSettings/x:add[@key ='server']/@value"
    property="configuration.server">
        <namespaces>
<namespace prefix="x" uri="http://www.gordic.cz/shared/project-config/v_1.0.0.0" />
        </namespaces>
</xmlpeek>


2) xmlpoke -- Replaces text in an XML file at the location specified by an XPath expression.

Usage: the xml file is same as above

Xmlpoke will change the value of the value property of add to the value provided which is productionhost.somecompany.com

<xmlpoke
    file="App.config"
    xpath="/configuration/appSettings/add[@key = 'server']/@value"
    value="productionhost.somecompany.com" />

3) asminfo -- Generates an AssemblyInfo.cs file using the attributes given.

Usage: 
<asminfo output="AssemblyInfo.cs" language="CSharp">
    <imports>
        <import namespace="System" />
        <import namespace="System.Reflection" />
        <import namespace="System.EnterpriseServices" />
        <import namespace="System.Runtime.InteropServices" />
    </imports>
    <attributes>
        <attribute type="ComVisibleAttribute" value="false" />
        <attribute type="CLSCompliantAttribute" value="true" />
        <attribute type="AssemblyVersionAttribute" value="1.0.0.0" />
<attribute type="AssemblyTitleAttribute" value="My fun assembly" />
<attribute type="AssemblyDescriptionAttribute" value="More fun than a barrel of monkeys" />
<attribute type="AssemblyCopyrightAttribute" value="Copyright (c) 2002, Monkeyboy, Inc." />
<attribute type="ApplicationNameAttribute" value="FunAssembly" />
    </attributes>
    <references>
        <include name="System.EnterpriseServices.dll" />
    </references>
</asminfo>

Here an AssemblyInfo.cs file is created with metadata information as provided in the attribute element of asminfo tag. The import element is used to import some namespaces in the AssemblyInfo.cs file. However reference section can be omitted as per the requirements

4) foreach -- Loops over a set of items.

Usage:  Loops over all files in the project directory.
<foreach item="File" property="filename">
    <in>
        <items>
            <include name="**" />
        </items>
    </in>
    <do>
        <echo message="${filename}" />
    </do>
</foreach>
    
Each item which it is currently looping the string value of it can be stored in ‘property’ property of the foreach tag. It can be very useful for some special requirements. Other use of this task is mentioned in the Link mentioned below.


5) scripts -- Executes the code contained within the task. This code can include custom extension function definitions. Once the script task has executed those custom functions will be available for use in the build file.

Usage: 
<script language="C#" prefix="test" >
     <code>
         <![CDATA[
              [Function("test-func")]
              public static string Testfunc(  ) {
                  return "some result !!!!!!!!";
              }
         ]]>
     </code>
</script>
<echo message='${test::test-func()}'/>

The various scripts which can be used are VB, C#, JS, JSHARP.
The reuse of the function in the NAnt script is also shown.



6) choose(NAnt contrib) : Executes an alternate set of tasks depending on conditions that are individually set on each group of tasks. Similar to if- else if.

Usage: 
<choose>
    <when test="${build.config == 'Debug'}">
        <!-- compile app in debug configuration -->
        ...
    </when>
    <when test="${build.config == 'Release'}">
        <!-- compile app in release configuration -->
        ...
    </when>
    <otherwise>
<fail>Build configuration '${build.config}' is not supported!</fail>
    </otherwise>
</choose>

Source: http://nantcontrib.sourceforge.net/release/0.85/help/tasks/choose.html