Skip to content

Commit

Permalink
Include version and git commit hash in grunt and pass it into msbuild.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseldredge committed Jan 3, 2014
1 parent 6421f6a commit 0b54947
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 42 deletions.
50 changes: 45 additions & 5 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ module.exports = function (grunt) {
// load all grunt tasks
require('load-grunt-tasks')(grunt);

grunt.loadNpmTasks('grunt-preprocess');
grunt.loadNpmTasks('grunt-ember-templates');

grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
// configurable paths
yeoman: {
app: 'app',
Expand Down Expand Up @@ -102,6 +100,13 @@ module.exports = function (grunt) {
},
server: '.tmp'
},
'git-describe': {
default: {
options: {
template: '<%= pkg.version %> ({%=object%}{%=dirty%})'
}
}
},
jshint: {
options: {
jshintrc: '.jshintrc',
Expand Down Expand Up @@ -286,6 +291,11 @@ module.exports = function (grunt) {
]
},
preprocess: {
options: {
context: {
ProductVersion: '<%= pkg.versionWithCommit %>'
}
},
serve: {
options: {
context: {
Expand All @@ -302,7 +312,7 @@ module.exports = function (grunt) {
}
},
src : [
'<%= yeoman.dist %>/index.html',
'<%= yeoman.dist %>/index.html',
]
}
},
Expand Down Expand Up @@ -333,6 +343,25 @@ module.exports = function (grunt) {
src: [".tmp/amd/**/*.amd.js"],
dest: ".tmp/js/amd-combined.js"
},
},
exec: {
msbuild: {
cmd: function() {
var prog = 'c:\\Program\ Files\ (x86)\\MSBuild\\12.0\\Bin\\MSBuild.exe';

if (!grunt.file.exists(prog)) {
grunt.fail.warn("Visual Studio 2013 MSBuild not found at " + prog);
}

var args = [
prog,
'/p:TestsEnabled=False',
'/p:VersionPrefix=' + grunt.config.get('pkg.version'),
'/p:VersionControlInfo=' + grunt.config.get('pkg.versionWithCommit'),
]
return '"' + args.join('" "') + '"';
}
}
}
});

Expand All @@ -342,6 +371,7 @@ module.exports = function (grunt) {
}

grunt.task.run([
'setVersionWithCommit',
'clean:server',
'concurrent:server',
'autoprefixer',
Expand All @@ -362,7 +392,16 @@ module.exports = function (grunt) {
'mocha'
]);

grunt.registerTask('setVersionWithCommit', function() {
grunt.event.once('git-describe', function (rev) {
grunt.config('pkg.versionWithCommit', rev.toString());

});
grunt.task.run('git-describe');
});

grunt.registerTask('build', [
'setVersionWithCommit',
'clean:dist',
'concurrent:dist',
'preprocess:dist',
Expand All @@ -375,7 +414,8 @@ module.exports = function (grunt) {
'uglify',
'copy:dist',
'rev',
'usemin'
'usemin',
'exec:msbuild'
]);

grunt.registerTask('default', [
Expand Down
46 changes: 16 additions & 30 deletions IntegratedBuild.proj
Original file line number Diff line number Diff line change
@@ -1,37 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VersionPrefix>1.0.0</VersionPrefix>
</PropertyGroup>

<PropertyGroup>
<SolutionDir>$(MSBuildProjectDirectory)\source\</SolutionDir>
<DistDir>$(MSBuildProjectDirectory)\dist\</DistDir>

<VersionControlInfo Condition=" '$(TRAVIS)' == 'true' ">$(TRAVIS_COMMIT) ($(TRAVIS_BRANCH))</VersionControlInfo>
<VersionControlInfo Condition=" '$(VersionControlInfo)' == '' ">(unknown version control revision)</VersionControlInfo>

<BuildNumber Condition=" '$(TRAVIS)' == 'true' ">$(TRAVIS_BUILD_NUMBER)</BuildNumber>
<BuildNumber Condition=" '$(BuildNumber)' == '' ">0</BuildNumber>

<AssemblyVersion>$(VersionPrefix).$(BuildNumber)</AssemblyVersion>

<VersionSuffix Condition=" '$(TRAVIS)' == 'true' ">build$(BuildNumber)</VersionSuffix>

<PackageVersion>$(VersionPrefix)</PackageVersion>
<PackageVersion Condition=" '$(VersionSuffix)' != '' ">$(PackageVersion)-$(VersionSuffix)</PackageVersion>

<AssemblyInformationalVersion>$(PackageVersion) $(VersionControlInfo)</AssemblyInformationalVersion>

<TestsEnabled>true</TestsEnabled>
</PropertyGroup>

<ItemGroup>
<VersionInfoContent Include="[assembly: global::System.Reflection.AssemblyVersionAttribute(&quot;$(AssemblyVersion)&quot;)]"/>
<VersionInfoContent Include="[assembly: global::System.Reflection.AssemblyFileVersionAttribute(&quot;$(AssemblyVersion)&quot;)]"/>
<VersionInfoContent Include="[assembly: global::System.Reflection.AssemblyInformationalVersionAttribute(&quot;$(AssemblyInformationalVersion)&quot;)]"/>
</ItemGroup>

<Target Name="Build" DependsOnTargets="Clean;RestoreSolutionPackages;GenerateVersionInfo;Stage;IntegrationTest"/>

<Target Name="Clean">
Expand Down Expand Up @@ -85,17 +59,29 @@
</Target>

<Target Name="IntegrationTest" Condition=" '$(TestsEnabled)' == 'true' ">
<MSBuild Projects="$(MSBuildProjectDirectory)\integration-tests\test.proj" Properties="DistDir=$(DistDir);TestCase=$(TestCase)"/>
<MSBuild Projects="$(MSBuildProjectDirectory)\integration-tests\test.proj" Properties="DistDir=$(DistDir)"/>
</Target>

<Target Name="GenerateVersionInfo">
<PropertyGroup>
<VersionPrefix Condition=" '$(VersionPrefix)' == '' ">0.9</VersionPrefix>
<VersionControlInfo Condition=" '$(VersionControlInfo)' == '' ">$(VersionPrefix) (unknown version control revision)</VersionControlInfo>

<AssemblyVersion>$(VersionPrefix)</AssemblyVersion>

<AssemblyInformationalVersion>$(VersionControlInfo)</AssemblyInformationalVersion>
</PropertyGroup>

<ItemGroup>
<VersionInfoContent Include="[assembly: global::System.Reflection.AssemblyVersionAttribute(&quot;$(AssemblyVersion)&quot;)]"/>
<VersionInfoContent Include="[assembly: global::System.Reflection.AssemblyFileVersionAttribute(&quot;$(AssemblyVersion)&quot;)]"/>
<VersionInfoContent Include="[assembly: global::System.Reflection.AssemblyInformationalVersionAttribute(&quot;$(AssemblyInformationalVersion)&quot;)]"/>
</ItemGroup>

<MakeDir Directories="build/artifacts"/>
<WriteLinesToFile File="build/VersionInfo.cs" Lines="@(VersionInfoContent)" Overwrite="true"/>
<Message Text="PackageVersion: $(PackageVersion)"/>
<Message Text="AssemblyVersion: $(AssemblyVersion)"/>
<Message Text="AssemblyInformationalVersion: $(AssemblyInformationalVersion)"/>
<Copy SourceFiles="build/VersionInfo.cs" DestinationFiles="build/artifacts/VersionInfo-$(BuildNumber).cs"/>
<Message Text="To repeat this build: git checkout $(TRAVIS_COMMIT); msbuild /p:TRAVIS=true,TRAVIS_COMMIT=$(TRAVIS_COMMIT),TRAVIS_BRANCH=$(TRAVIS_BRANCH),TRAVIS_BUILD_NUMBER=$(TRAVIS_BUILD_NUMBER)"/>
</Target>

<Import Project="source/.nuget/NuGet.targets"/>
Expand Down
2 changes: 2 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
<script>
//Ember.ENV.LOG_MODULE_RESOLVER = true;
window.App = require('app')['default'].create();
window.App.version = "<!-- @echo ProductVersion -->";
console.log("Klondike Version ", window.App.version);
</script>
</body>
</html>
5 changes: 3 additions & 2 deletions app/js/views/footer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default Ember.View.extend({
export default Ember.View.extend({
templateName: 'footer',
tagName: 'footer',
contentBinding: 'App.packageIndexer.status'
contentBinding: 'App.packageIndexer.status',
versionBinding: 'App.version'
});
3 changes: 3 additions & 0 deletions app/templates/footer.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
{{/if}}
</div>
{{/with}}
<div>
Klondike Version {{view.version}}
</div>
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bower-sandbox",
"version": "0.0.0",
"name": "klondike",
"version": "1.0.1",
"dependencies": {
"sass-bootstrap": "~3.0.0",
"jquery": "~2.0.3",
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bower-sandbox",
"version": "0.0.0",
"name": "klondike",
"version": "1.0.1",
"dependencies": {},
"devDependencies": {
"grunt": "~0.4.1",
Expand Down Expand Up @@ -31,7 +31,9 @@
"grunt-ember-templates": "~0.4.18",
"grunt-concat-in-order": "~0.1.6",
"grunt-es6-module-transpiler": "~0.5.2",
"grunt-preprocess": "~3.0.1"
"grunt-preprocess": "~3.0.1",
"grunt-exec": "~0.4.3",
"grunt-git-describe": "~2.3.2"
},
"engines": {
"node": ">=0.8.0"
Expand Down
1 change: 1 addition & 0 deletions source/Klondike/Klondike.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\build\VersionInfo.cs" Condition="Exists('..\..\build\VersionInfo.cs')" />
<Compile Include="App_Start\NinjectWebCommon.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
Expand Down

0 comments on commit 0b54947

Please sign in to comment.