Skip to content
This repository has been archived by the owner on Aug 5, 2019. It is now read-only.

SimpleGitVersion with CodeCake

Alexandre Da Silva edited this page Jan 7, 2016 · 3 revisions

Thanks to SimpleGitVersion.Cake, SimpleGitVersion can be used easily in CodeCake! It supports both MSBuild and DNX projects. For more informations on CodeCake, see: https://github.com/SimpleGitVersion/CodeCake/wiki

Install

MSBuild project

Simply add a reference to SimpleGitVersion.Core and SimpleGitVersion.Cake

DNX project

In project.json, add a dependency to SimpleGitVersion.Cake

Snippets

Here are some snippets to do classical tasks.

Get informations on the repository

MSBuild projects

var gitInfo = Cake.GetSimpleRepositoryInfo();

DNX projects

var gitInfo = dnxSolution.RepositoryInfo;

Check if the repository can be published

MSBuild projects

string configuration = null;

Task( "Check-Repository" )
    .Does( () =>
    {
        var gitInfo = Cake.GetSimpleRepositoryInfo();
        if( !gitInfo.IsValid ) throw new Exception( "Repository is not ready to be published." );
        configuration = gitInfo.IsValidRelease && gitInfo.PreReleaseName.Length == 0 ? "Release" : "Debug";
    } );

DNX projects

string configuration = null;

Task( "Check-Repository" )
    .Does( () =>
    {
        var gitInfo = dnxSolution.RepositoryInfo;
        if( !gitInfo.IsValid ) throw new Exception( "Repository is not ready to be published." );     
        configuration = gitInfo.IsValidRelease && gitInfo.PreReleaseName.Length == 0 ? "Release" : "Debug";
    } );

Set the version of a DNX project

For example, it can be executed after the repository check.

Task( "Set-ProjectVersion" )
    .IsDependentOn( "Check-Repository" )
    .Does( () =>
    {
        if( dnxSolution.UpdateProjectFiles( true ) > 0 )
        {
            Cake.DNURestore( c =>
            {
                c.Quiet = true;
                c.ProjectPaths.UnionWith( dnxSolution.Projects.Select( p => p.ProjectFilePath ) );
            } );
        }
    } );

Push your packages on different feeds according to the version

For example, if the version is a valid release, or a CI build.

Task( "Push-Packages" )
    .Does( () =>
    {
        if( gitInfo.IsValid )
        {
            if( gitInfo.IsValidRelease )
            {
				PushToReleaseFeed();
            }
            else
            {
                Debug.Assert( gitInfo.IsValidCIBuild );
				PushToCIFeed();
            }
        }
        else
        {
            Cake.Information( "Push-Packages step is skipped since Git repository info is not valid." );
        }
    } );