Refactor, and drop the need to manually run the Chocolatey task.

This commit is contained in:
Matt Burke
2013-11-20 03:03:55 -05:00
parent f7038b9a00
commit ab29f1e541
2 changed files with 91 additions and 94 deletions
+91 -90
View File
@@ -2,40 +2,69 @@
<Project ToolsVersion="4.0" DefaultTargets="Help" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- The owner of the GitHub repository -->
<GitHubUser>git-tfs</GitHubUser>
<!-- The name of the GitHub repository -->
<GitHubProject>git-tfs</GitHubProject>
<!-- Where to push the release tag. -->
<OriginUrl>https://github.com/$(GitHubUser)/$(GitHubProject).git</OriginUrl>
<!-- Where the solution lives, relative to this file. -->
<SolutionDir>.</SolutionDir>
<!-- Where git-tfs.exe and its dependencies are built. -->
<BuildDir>$(SolutionDir)/GitTfs/bin/Release</BuildDir>
<!-- The file that includes the AssemblyVersionAttribute. -->
<VersionFilePath>$(SolutionDir)\Version.cs</VersionFilePath>
<!-- If we support VS2008, we need to build as x86. Otherwise, build for any platform. -->
<TargetPlatform>AnyCPU</TargetPlatform>
<TargetPlatform Condition="Exists('$(SolutionDir)/GitTfs.Vs2008/GitTfs.Vs2008.csproj')">x86</TargetPlatform>
<!-- The file that includes the AssemblyVersionAttribute. -->
<VersionFilePath>$(SolutionDir)\Version.cs</VersionFilePath>
<!-- Where git-tfs.exe and its dependencies are built. -->
<BuildDir>$(SolutionDir)/GitTfs/bin/Release</BuildDir>
<!-- The name of the output zip file. -->
<PackagedDir>$(SolutionDir)/Releases</PackagedDir>
<PackageFile>GitTfs-$(Version).zip</PackageFile>
<Archive>$(PackagedDir)/$(PackageFile)</Archive>
<!-- Where to push the release tag. -->
<GitHubOwner>git-tfs</GitHubOwner>
<GitHubRepository>git-tfs</GitHubRepository>
<OriginUrl>https://github.com/$(GitHubOwner)/$(GitHubRepository).git</OriginUrl>
<!-- The API doesn't provide this, but it follows a pattern that we can mimic. -->
<DownloadUrl>https://github.com/git-tfs/git-tfs/releases/download/v$(Version)/$(PackageFile)</DownloadUrl>
<!-- A directory to use when changing the download button on the website. -->
<WebSiteDir>.\git-tfs.github.com</WebSiteDir>
<WebSiteDir>$(PackagedDir)/git-tfs.github.com</WebSiteDir>
<DownloadButton>_includes/download_button.html</DownloadButton>
<WebSiteRepository>https://github.com/$(GitHubOwner)/git-tfs.github.com.git</WebSiteRepository>
</PropertyGroup>
<!-- Internal. -->
<Target Name="VersionRequired">
<Error Text="You must specify a version number! (/p:Version=X.Y.Z)" Condition="'$(Version)' == ''" />
</Target>
<!-- Try to load the oauth token -->
<Import Project="Auth.targets" Condition="Exists('Auth.targets')" />
<!-- Internal. -->
<Target Name="AuthTokenRequired">
<Error Text="You must set a github.com auth token in auth.targets (see auth.targets.example)" Condition="'$(GitHubAuthToken)' == ''" />
</Target>
<!-- The contents of the zip. -->
<ItemGroup>
<ReleaseFiles Include="$(SolutionDir)\README.md" />
<ReleaseFiles Include="$(SolutionDir)\LICENSE" />
<ReleaseFiles Include="$(SolutionDir)\NOTICE" />
<ReleaseFiles Include="$(BuildDir)\git-tfs.exe" />
<ReleaseFiles Include="$(BuildDir)\*.config" />
<ReleaseFiles Include="$(BuildDir)\*.dll" Exclude="$(BuildDir)\Microsoft.*.dll" />
<ReleaseFiles Include="$(BuildDir)\NativeBinaries\**\*.dll" />
</ItemGroup>
<!-- The zip. -->
<ItemGroup>
<ArchiveFile Include="$(Archive)">
<ContentType>application/zip</ContentType>
</ArchiveFile>
</ItemGroup>
<!-- Load nuget, so we can get dependencies. (Dependencies are not checked in to git.) -->
<PropertyGroup>
<PackagesConfig>$(SolutionDir)/.nuget/packages.config</PackagesConfig>
@@ -62,7 +91,26 @@
</Target>
<!-- Public: Build the release and put it on github.com -->
<Target Name="Release" DependsOnTargets="UpdateVersion; Build; TagSource; PushSource; Package; GitHubRelease;">
<Target Name="Release" DependsOnTargets="EverythingRequired; UpdateVersion; Build; TagSource; PushSource; Package; ReleaseOnGitHub; UpdateWebSite; Chocolatey">
</Target>
<!-- Internal: If we don't have all the information we need, bail early. -->
<Target Name="EverythingRequired" DependsOnTargets="VersionRequired; AuthTokenRequired">
</Target>
<!-- Internal: Called by Release to set the new version. -->
<Target Name="UpdateVersion" DependsOnTargets="UpdateAssemblyVersionAttribute; UpdateVersionInReadme">
<Exec Command="git commit -m v$(Version) $(VersionFilePath) README.md" />
</Target>
<!-- Internal. -->
<Target Name="UpdateAssemblyVersionAttribute" DependsOnTargets="VersionRequired">
<WriteLinesToFile File="$(VersionFilePath)" Lines="partial class GitTfsProperties ; { ; public const string Version = %22$(Version)%22%3B ; }" Overwrite="true" Encoding="ASCII"/>
</Target>
<!-- Internal. -->
<Target Name="UpdateVersionInReadme" DependsOnTargets="VersionRequired">
<FileUpdate Files="README.md" Regex="The most recent version is __.*__\." ReplacementText="The most recent version is __$(Version)__." />
</Target>
<!-- Internal: Called by release to compile git-tfs.exe -->
@@ -70,43 +118,40 @@
<MSBuild Projects="GitTfs.sln" Targets="Rebuild" Properties="Configuration=Release;Platform=$(TargetPlatform);WarningLevel=0" />
</Target>
<!-- The contents of the zip. -->
<ItemGroup>
<ReleaseFiles Include="$(SolutionDir)\README.md" />
<ReleaseFiles Include="$(SolutionDir)\LICENSE" />
<ReleaseFiles Include="$(SolutionDir)\NOTICE" />
<ReleaseFiles Include="$(BuildDir)\git-tfs.exe" />
<ReleaseFiles Include="$(BuildDir)\*.config" />
<ReleaseFiles Include="$(BuildDir)\*.dll" Exclude="$(BuildDir)\Microsoft.*.dll" />
<ReleaseFiles Include="$(BuildDir)\NativeBinaries\**\*.dll" />
</ItemGroup>
<!-- Internal: Called by Release to create the zip. -->
<Target Name="Package" DependsOnTargets="MSBuildCommunityTasks">
<Zip Files="@(ReleaseFiles)" ZipFileName="$(Archive)" WorkingDirectory="$(BuildDir)" />
</Target>
<!-- Internal: Called by Release to set the new version. -->
<Target Name="UpdateVersion">
<Error Text="You should specify a version number!" Condition="'$(Version)' == ''" />
<WriteLinesToFile File="$(VersionFilePath)" Lines="partial class GitTfsProperties ; { ; public const string Version = %22$(Version)%22%3B ; }" Overwrite="true" Encoding="ASCII"/>
<Exec Command="git add $(VersionFilePath)" />
<FileUpdate Files="README.md" Regex="The most recent version is __.*__\." ReplacementText="The most recent version is __$(Version)__." />
<Exec Command="git add README.md" />
<Exec Command="git commit -m v$(Version)" />
</Target>
<!-- Internal: Called by Release to tag the git-tfs repository. -->
<Target Name="TagSource">
<Target Name="TagSource" DependsOnTargets="VersionRequired">
<Exec Command="git tag v$(Version)" />
</Target>
<!-- Internal: Called by Release to push the release tag to github.com -->
<Target Name="PushSource">
<Target Name="PushSource" DependsOnTargets="VersionRequired">
<Exec Command="git push $(OriginUrl) master v$(Version)" />
</Target>
<!-- Public: Build and upload a chocolatey package. -->
<!-- Internal: Called by Release to create the zip. -->
<Target Name="Package" DependsOnTargets="VersionRequired; MSBuildCommunityTasks">
<Zip Files="@(ReleaseFiles)" ZipFileName="$(Archive)" WorkingDirectory="$(BuildDir)" />
</Target>
<!-- Internal: Create a release on github.com -->
<Target Name="ReleaseOnGitHub" DependsOnTargets="VersionRequired; AuthTokenRequired; MSBuildCommunityTasks">
<CreateRelease Repository="$(GitHubOwner)/$(GitHubRepository)" TagName="v$(Version)" Files="@(ArchiveFile)" OauthToken="$(GitHubAuthToken)" ReleaseNotesFile="$(ReleaseNotes)" />
</Target>
<!-- Internal: Update the "download" button on git-tfs.com -->
<Target Name="UpdateWebSite" DependsOnTargets="VersionRequired; ClonePagesRepository">
<Exec WorkingDirectory="$(WebSiteDir)" Command="git checkout master" />
<WriteLinesToFile File="$(WebSiteDir)/$(DownloadButton)" Lines="&lt;a href=%22$(DownloadUrl)%22 class=%22download-button%22&gt;Download v$(Version)&lt;/a&gt;" Overwrite="true" Encoding="ASCII"/>
<Exec WorkingDirectory="$(WebSiteDir)" Command="git commit -m %22v$(Version)%22 $(DownloadButton)" />
<Exec WorkingDirectory="$(WebSiteDir)" Command="git push $(WebSiteRepository) master" />
</Target>
<!-- Internal. -->
<Target Name="ClonePagesRepository" Condition="!Exists($(WebSiteDir))">
<Exec Command="git clone $(WebSiteRepository) $(WebSiteDir)" />
</Target>
<!-- Internal: Build and upload a chocolatey package. -->
<Target Name="Chocolatey" DependsOnTargets="CleanChocolateyTempDir; PushChocolateyPackage">
</Target>
@@ -130,11 +175,6 @@
<ChocolateyInstallScript Include="$(ChocolateyBuildDir)/tools/chocolateyInstall.ps1" />
</ItemGroup>
<!-- Internal: Exits with error when required chocolatey properties are not defined. -->
<Target Name="ChocolateyProperties">
<Error Text="You should specify a version number! (/p:Version=X.Y.Z)" Condition="'$(Version)' == ''" />
</Target>
<!-- Internal. -->
<Target Name="CleanChocolateyTempDir">
<RemoveDir Directories="$(ChocolateyBuildDir)" />
@@ -146,7 +186,7 @@
</Target>
<!-- Internal: Generate a nuspec file for the chocolatey package. -->
<Target Name="ChocolateyNuspec" DependsOnTargets="ChocolateyProperties; MSBuildCommunityTasks; ChocolateyTempDir">
<Target Name="ChocolateyNuspec" DependsOnTargets="VersionRequired; MSBuildCommunityTasks; ChocolateyTempDir">
<TemplateFile
Template="$(ChocolateyTemplateDir)\gittfs.nuspec"
OutputFilename="%(ChocolateyNuspec.FullPath)"
@@ -154,7 +194,7 @@
</Target>
<!-- Internal: Generate an install script for the chocolatey package. -->
<Target Name="ChocolateyInstallScript" DependsOnTargets="ChocolateyProperties; MSBuildCommunityTasks; ChocolateyTempDir">
<Target Name="ChocolateyInstallScript" DependsOnTargets="VersionRequired; MSBuildCommunityTasks; ChocolateyTempDir">
<TemplateFile
Template="$(ChocolateyTemplateDir)\chocolateyInstall.ps1"
OutputFilename="%(ChocolateyInstallScript.FullPath)"
@@ -170,43 +210,4 @@
<Target Name="PushChocolateyPackage" DependsOnTargets="BuildChocolateyPackage">
<Exec Command="cpush $(ChocolateyNupkg)" />
</Target>
<!-- The zip. -->
<ItemGroup>
<ArchiveFile Include="$(Archive)">
<ContentType>application/zip</ContentType>
</ArchiveFile>
</ItemGroup>
<!-- Internal: Called by Release to create the release record on github.com and update the web site -->
<Target Name="GitHubRelease" DependsOnTargets="GitHubCreateRelease; UpdateWebSite;">
</Target>
<!-- Try to load the oauth token -->
<Import Project="Auth.targets" Condition="Exists('Auth.targets')" />
<!-- Internal: Create a release on github.com -->
<Target Name="GitHubCreateRelease" DependsOnTargets="MSBuildCommunityTasks">
<Error Text="You must set a github.com auth token in auth.targets (see auth.targets.example)" Condition="'$(GitHubAuthToken)' == ''" />
<CreateRelease Repository="$(GitHubUser)/$(GitHubProject)" TagName="v$(Version)" Files="@(ArchiveFile)" OauthToken="$(GitHubAuthToken)" ReleaseNotesFile="$(ReleaseNotes)" >
<Output TaskParameter="IdRelease" PropertyName="IdRelease" />
</CreateRelease>
<Message Text="Id : $(IdRelease)"/>
<Error Text="Fail to create a release!" Condition="'$(IdRelease)' == '0'" />
</Target>
<!-- Internal: Update the "download" button on git-tfs.com -->
<Target Name="UpdateWebSite">
<Exec Command="git clone https://github.com/$(GitHubUser)/git-tfs.github.com.git" />
<WriteLinesToFile File="$(WebSiteDir)\_includes\download_button.html" Lines="&lt;a href=%22$(DownloadUrl)%22 class=%22download-button%22&gt;Download v$(Version)&lt;/a&gt;" Overwrite="true" Encoding="ASCII"/>
<Exec WorkingDirectory="$(WebSiteDir)" Command="git commit -a -m %22v$(Version)%22" />
<Exec WorkingDirectory="$(WebSiteDir)" Command="git push origin master" />
<CallTarget Targets="_CleanWebsiteFolder;" />
<OnError ExecuteTargets="_CleanWebsiteFolder" />
</Target>
<!-- Internal: Remove the website folder. -->
<Target Name="_CleanWebsiteFolder">
<RemoveDir Directories="$(WebSiteDir)" />
</Target>
</Project>
-4
View File
@@ -14,7 +14,3 @@ Normally, you should do this:
3. Build the release and include the version (e.g. X.Y.Z) and the name of a changelog file (optional).
msbuild Release.proj /t:Release /p:Version=X.Y.Z /p:ReleaseNotes="ReleaseNoteFile.md"
4. Build the chocolatey package. (For this to work, you need to [set an API key](https://github.com/chocolatey/chocolatey/wiki/CommandsPush#note-to-use-this-command-you-must-have-your-api-key-saved-for-chocolateyorg-or-the-source-you-want-to-push-to).)
msbuild Release.proj /t:Chocolatey /p:Version=X.Y.Z