Skip to content

Commit 00d28c0

Browse files
committed
Used GitVersion to generate versions (next version is based on existing tags). Replaced Directory.Build.props with GlobalAssemblyInfo.cs
1 parent 549ca4a commit 00d28c0

File tree

8 files changed

+58
-66
lines changed

8 files changed

+58
-66
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ packages
225225
*.lock.json
226226

227227
# Cake
228-
tools/
228+
tools/*
229+
!tools/packages.config
230+
231+
229232
.vs/
230233
artifacts/

Directory.Build.props

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<Project>
22
<PropertyGroup>
3-
<VersionPrefix>1.1.0</VersionPrefix>
4-
<!-- VersionSuffix is computed in build.cake depending of the type of the build -->
5-
<VersionSuffix>dev.0+sha.0</VersionSuffix>
6-
73
<Description>A Slack wrapper for direct interaction with their APIs.</Description>
84
<Copyright>Inumedia - Copyright © 2018</Copyright>
95
<AssemblyProduct>SlackAPI</AssemblyProduct>
@@ -15,5 +11,9 @@
1511
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
1612
<RepositoryType>git</RepositoryType>
1713
<RepositoryUrl>https://github.com/Inumedia/SlackAPI</RepositoryUrl>
14+
15+
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
16+
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
17+
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
1818
</PropertyGroup>
1919
</Project>

GlobalAssemblyInfo.cs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using System.Reflection;
2+
3+
[assembly: AssemblyVersion("1.1.0.0")]
4+
[assembly: AssemblyFileVersion("1.1.0.0")]
5+
[assembly: AssemblyInformationalVersion("1.1.0.0")]

SlackAPI.Tests/SlackAPI.Tests.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
</None>
3131
</ItemGroup>
3232

33+
<ItemGroup>
34+
<Compile Include="..\GlobalAssemblyInfo.cs">
35+
<Link>Properties\GlobalAssemblyInfo.cs</Link>
36+
</Compile>
37+
</ItemGroup>
38+
3339
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
3440
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
3541
</PropertyGroup>

SlackAPI.sln

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlackAPI", "SlackAPI\SlackA
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlackAPI.Tests", "SlackAPI.Tests\SlackAPI.Tests.csproj", "{DEFA9559-0F8F-4C38-9644-67A080EDC46D}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution items", "Solution items", "{532C9828-A2CC-4281-950A-248B06D42E9C}"
11+
ProjectSection(SolutionItems) = preProject
12+
appveyor.yml = appveyor.yml
13+
build.cake = build.cake
14+
Directory.Build.props = Directory.Build.props
15+
GlobalAssemblyInfo.cs = GlobalAssemblyInfo.cs
16+
README.md = README.md
17+
EndProjectSection
18+
EndProject
1019
Global
1120
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1221
Debug|Any CPU = Debug|Any CPU

SlackAPI/SlackAPI.csproj

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
2828
</ItemGroup>
2929

30+
<ItemGroup>
31+
<Compile Include="..\GlobalAssemblyInfo.cs">
32+
<Link>Properties\GlobalAssemblyInfo.cs</Link>
33+
</Compile>
34+
</ItemGroup>
35+
3036
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
3137
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
3238
</PropertyGroup>

build.cake

+20-61
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#tool "nuget:?package=GitVersion.CommandLine"
2-
#addin "Cake.FileHelpers"
1+
#tool "nuget:?package=GitVersion.CommandLine&version=5.1.3"
2+
#addin "Cake.FileHelpers&version=3.2.1"
3+
#addin "Cake.Incubator&version=5.1.0"
34

45
using System.Text.RegularExpressions;
56

@@ -11,7 +12,7 @@ var testProject = File("./SlackAPI.Tests/SlackApi.Tests.csproj");
1112
var testConfig = File("./SlackAPI.Tests/Configuration/config.json");
1213
var projects = new[] { project, testProject };
1314
var artifactsDirectory = "./artifacts";
14-
var versionSuffix = string.Empty;
15+
GitVersion gitVersion = null;
1516
var isReleaseBuild = false;
1617

1718
Task("Clean")
@@ -24,67 +25,26 @@ Task("Clean")
2425
Task("Configure")
2526
.Does(() =>
2627
{
27-
var buildNumber = 0;
28-
if (AppVeyor.IsRunningOnAppVeyor)
29-
{
30-
isReleaseBuild = AppVeyor.Environment.Repository.Branch == "master" && AppVeyor.Environment.Repository.Tag.IsTag;
31-
buildNumber = AppVeyor.Environment.Build.Number;
32-
Information("Build number is '{0}' (CI build)", buildNumber);
33-
}
34-
else
35-
{
36-
buildNumber = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
37-
Information("Build number is '{0}' (local build)", buildNumber);
38-
}
39-
40-
// If the build is a tag on master, generate a clean version (1.0.0)
41-
// following SemVer 1.0.0 rules. NuGet supports only SemVer 1.0.0
42-
// In other cases, generate a prerelease version (1.0.0-branch.123+sha.abcdefg)
43-
// following SevVer 2.0.0 rules. MyGet supports SemVer 2.0.0
44-
if (isReleaseBuild)
45-
{
46-
versionSuffix = "\"\"";
47-
}
48-
else
49-
{
50-
var gitVersion = GitVersion();
51-
var gitBranch = (AppVeyor.IsRunningOnAppVeyor
52-
? AppVeyor.Environment.Repository.Branch
53-
: gitVersion.BranchName);
54-
gitBranch = Regex.Replace(gitBranch, @"[/\-_]", string.Empty);
55-
gitBranch = gitBranch.Substring(0, Math.Min(10, gitBranch.Length));
56-
57-
Information("Current git branch is '{0}' (normalized)", gitBranch);
58-
59-
var gitCommitId = (AppVeyor.IsRunningOnAppVeyor
60-
? AppVeyor.Environment.Repository.Commit.Id
61-
: gitVersion.Sha)
62-
.Substring(0, 8);
63-
64-
Information("Current git sha is '{0}' (normalized)", gitCommitId);
65-
66-
var isPullRequest = AppVeyor.IsRunningOnAppVeyor && AppVeyor.Environment.PullRequest.IsPullRequest;
67-
if (isPullRequest)
68-
{
69-
gitBranch = "PR";
70-
}
28+
gitVersion = GitVersion();
7129

72-
Information("Is Pull Request: '{0}'", isPullRequest);
30+
GitVersion(new GitVersionSettings {
31+
UpdateAssemblyInfo = true,
32+
UpdateAssemblyInfoFilePath = "GlobalAssemblyInfo.cs"
33+
});
7334

35+
isReleaseBuild = AppVeyor.IsRunningOnAppVeyor
36+
? AppVeyor.Environment.Repository.Branch == "master"
37+
: false;
7438

75-
versionSuffix = $"{gitBranch}.{buildNumber}+sha.{gitCommitId}";
76-
}
39+
Information("Is release build: '{0}'", isReleaseBuild);
40+
Information("GitVersion details:\n{0}", gitVersion.Dump());
7741

78-
var versionPrefix = XmlPeek("./Directory.Build.props", "/Project/PropertyGroup/VersionPrefix");
79-
var version = isReleaseBuild ? $"{versionPrefix}-release.{buildNumber}" : string.Join("-", versionPrefix, versionSuffix);
8042
if (AppVeyor.IsRunningOnAppVeyor)
8143
{
82-
// Update AppVeyor build version so it will match the build version in assemblies and package
83-
AppVeyor.UpdateBuildVersion(version);
44+
var buildVersion = gitVersion.SemVer + ".ci." + AppVeyor.Environment.Build.Number;
45+
Information("Using build version: {0}", buildVersion);
46+
AppVeyor.UpdateBuildVersion(buildVersion);
8447
}
85-
86-
Information("Using version '{0}'", version);
87-
Information("Release type build (skip symbols): {0}", isReleaseBuild);
8848
});
8949

9050

@@ -98,8 +58,7 @@ Task("Build")
9858
project,
9959
new DotNetCoreBuildSettings
10060
{
101-
Configuration = configuration,
102-
VersionSuffix = versionSuffix
61+
Configuration = configuration
10362
}
10463
);
10564
}
@@ -186,9 +145,9 @@ Task("Package")
186145
{
187146
Configuration = configuration,
188147
OutputDirectory = artifactsDirectory,
189-
VersionSuffix = versionSuffix,
190148
IncludeSymbols = !isReleaseBuild,
191-
IncludeSource = !isReleaseBuild
149+
IncludeSource = !isReleaseBuild,
150+
ArgumentCustomization = args => args.Append("/p:Version=\"" + gitVersion.NuGetVersion + "\"")
192151
}
193152
);
194153

tools/packages.config

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Cake" version="0.37.0" />
4+
</packages>

0 commit comments

Comments
 (0)