forked from ChilliCream/graphql-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Build.Publish.cs
155 lines (133 loc) · 6.03 KB
/
Build.Publish.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Build.Evaluation;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.NuGet;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Helpers;
using static Nuke.Common.Tools.NuGet.NuGetTasks;
using Project = Microsoft.Build.Evaluation.Project;
partial class Build
{
// IEnumerable<string> ChangelogSectionNotes => ExtractChangelogSectionNotes(ChangelogFile);
[Parameter("NuGet Source for Packages")] readonly string NuGetSource = "https://api.nuget.org/v3/index.json";
[Parameter("NuGet Api Key")] readonly string NuGetApiKey;
Target Pack => _ => _
.DependsOn(PackLocal)
.Produces(PackageDirectory / "*.nupkg")
.Produces(PackageDirectory / "*.snupkg")
.Requires(() => Configuration.Equals(Release));
Target PackLocal => _ => _
.Produces(PackageDirectory / "*.nupkg")
.Produces(PackageDirectory / "*.snupkg")
.Executes(() =>
{
var projFile = File.ReadAllText(StarWarsProj);
File.WriteAllText(StarWarsProj, projFile.Replace("11.1.0", GitVersion.SemVer));
projFile = File.ReadAllText(EmptyServerProj);
File.WriteAllText(EmptyServerProj, projFile.Replace("11.1.0", GitVersion.SemVer));
projFile = File.ReadAllText(EmptyServer12Proj);
File.WriteAllText(EmptyServer12Proj, projFile.Replace("11.1.0", GitVersion.SemVer));
projFile = File.ReadAllText(EmptyAzf12Proj);
File.WriteAllText(EmptyAzf12Proj, projFile.Replace("11.1.0", GitVersion.SemVer));
})
.Executes(() =>
{
DotNetBuildSonarSolution(
PackSolutionFile,
include: file =>
!Path.GetFileNameWithoutExtension(file)
.EndsWith("tests", StringComparison.OrdinalIgnoreCase));
DotNetBuild(c => c
.SetProjectFile(PackSolutionFile)
.SetConfiguration(Configuration)
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemFileVer)
.SetInformationalVersion(GitVersion.InformationalVersion)
.SetVersion(GitVersion.SemVer));
DotNetPack(c => c
.SetProject(PackSolutionFile)
.SetConfiguration(Configuration)
.SetOutputDirectory(PackageDirectory)
.SetNoRestore(true)
.SetNoBuild(true)
.SetVersion(GitVersion.SemVer));
NuGetPack(c => c
.SetVersion(GitVersion.SemVer)
.SetOutputDirectory(PackageDirectory)
.SetConfiguration(Configuration)
.CombineWith(
t => t.SetTargetPath(StarWarsTemplateNuSpec),
t => t.SetTargetPath(EmptyServerTemplateNuSpec),
t => t.SetTargetPath(TemplatesNuSpec)));
var analyzerProject = ProjectModelTasks
.ParseSolution(SgSolutionFile)
.GetProjects("*.Analyzers")
.Single();
Project parsedProject = ProjectModelTasks.ParseProject(analyzerProject);
ProjectItem packageReference = parsedProject.Items
.Single(t =>
t.ItemType == "PackageReference" &&
t.IsImported == false &&
t.EvaluatedInclude == "StrawberryShake.CodeGeneration.CSharp");
packageReference.SetMetadataValue("Version", GitVersion.SemVer);
parsedProject.Save();
DotNetBuild(c => c
.SetProjectFile(analyzerProject)
.SetConfiguration(Configuration)
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemFileVer)
.SetInformationalVersion(GitVersion.InformationalVersion)
.SetVersion(GitVersion.SemVer));
DotNetPack(c => c
.SetProject(analyzerProject)
.SetNoBuild(InvokedTargets.Contains(Compile))
.SetConfiguration(Configuration)
.SetOutputDirectory(PackageDirectory)
.SetVersion(GitVersion.SemVer));
var analyzerTestProject = ProjectModelTasks
.ParseSolution(SgSolutionFile)
.GetProjects("*.Tests")
.Single();
parsedProject = ProjectModelTasks.ParseProject(analyzerTestProject);
packageReference = parsedProject.Items
.Single(t =>
t.ItemType == "PackageReference" &&
t.IsImported == false &&
t.EvaluatedInclude == "StrawberryShake.CodeGeneration.CSharp.Analyzers");
packageReference.SetMetadataValue("Version", GitVersion.SemVer);
parsedProject.Save();
DotNetBuild(c => c
.SetProjectFile(analyzerTestProject)
.SetConfiguration(Configuration)
.SetAssemblyVersion(GitVersion.AssemblySemVer)
.SetFileVersion(GitVersion.AssemblySemFileVer)
.SetInformationalVersion(GitVersion.InformationalVersion)
.SetVersion(GitVersion.SemVer));
});
Target Publish => _ => _
.DependsOn(Clean, Test, Pack)
.Consumes(Pack)
.Requires(() => NuGetSource)
.Requires(() => NuGetApiKey)
.Requires(() => Configuration.Equals(Release))
.Executes(() =>
{
IReadOnlyCollection<AbsolutePath> packages = PackageDirectory.GlobFiles("*.nupkg");
DotNetNuGetPush(
_ => _
.SetSource(NuGetSource)
.SetApiKey(NuGetApiKey)
.CombineWith(
packages,
(_, v) => _.SetTargetPath(v)),
degreeOfParallelism: 2,
completeOnFailure: true);
});
}