|
1 | | -using HostApi; |
| 1 | +using System.Runtime.InteropServices; |
| 2 | +using HostApi; |
2 | 3 | using JetBrains.TeamCity.ServiceMessages.Write.Special; |
3 | 4 | using NuGet.Versioning; |
4 | 5 | using static Tools; |
|
16 | 17 | return 1; |
17 | 18 | } |
18 | 19 |
|
| 20 | +const string defaultNuGetSource = "https://api.nuget.org/v3/index.json"; |
19 | 21 | var configuration = GetProperty("configuration", "Release"); |
20 | 22 | var apiKey = GetProperty("apiKey", ""); |
21 | 23 | var integrationTests = bool.Parse(GetProperty("integrationTests", UnderTeamCity.ToString())); |
|
67 | 69 |
|
68 | 70 | foreach (var package in packages) |
69 | 71 | { |
70 | | - var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages", package.Id, packageVersion.ToString()); |
71 | | - if (Directory.Exists(path)) |
| 72 | + var nuGetPackagePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages", package.Id, packageVersion.ToString()); |
| 73 | + if (Directory.Exists(nuGetPackagePath)) |
72 | 74 | { |
73 | | - Directory.Delete(path, true); |
| 75 | + Directory.Delete(nuGetPackagePath, true); |
| 76 | + } |
| 77 | + |
| 78 | + var packageOutput = Path.GetDirectoryName(package.Package); |
| 79 | + if (Directory.Exists(packageOutput)) |
| 80 | + { |
| 81 | + Directory.Delete(packageOutput, true); |
74 | 82 | } |
75 | 83 | } |
76 | 84 |
|
77 | 85 | var buildProps = new[] {("version", packageVersion.ToString())}; |
78 | | -Succeed(new DotNetBuild() |
| 86 | +Succeed(new MSBuild() |
| 87 | + .WithProject(Path.Combine(currentDir, "CSharpInteractive", "CSharpInteractive.Tool.csproj")) |
| 88 | + .WithRestore(true) |
| 89 | + .WithTarget("Rebuild;GetDependencyTargetPaths") |
| 90 | + .WithProps(buildProps) |
| 91 | + .Build()); |
| 92 | + |
| 93 | +Succeed(new DotNetPack() |
79 | 94 | .WithProject(solutionFile) |
80 | 95 | .WithConfiguration(configuration) |
81 | 96 | .WithProps(buildProps) |
82 | 97 | .Build()); |
83 | 98 |
|
84 | | -var reportDir = Path.Combine(currentDir, ".reports"); |
85 | | -if (Directory.Exists(reportDir)) |
| 99 | +foreach (var package in packages) |
86 | 100 | { |
87 | | - Directory.Delete(reportDir, true); |
| 101 | + if (!File.Exists(package.Package)) |
| 102 | + { |
| 103 | + Error($"The NuGet package {package.Package} was not found."); |
| 104 | + return 1; |
| 105 | + } |
| 106 | + |
| 107 | + GetService<ITeamCityWriter>().PublishArtifact($"{package.Package} => ."); |
88 | 108 | } |
89 | 109 |
|
90 | | -var test = |
91 | | - new DotNetTest() |
92 | | - .WithProject(solutionFile) |
93 | | - .WithConfiguration(configuration) |
94 | | - .WithNoBuild(true) |
95 | | - .WithProps(buildProps) |
96 | | - .WithFilter("Integration!=true&Docker!=true"); |
| 110 | +var test = new DotNetTest() |
| 111 | + .WithProject(solutionFile) |
| 112 | + .WithConfiguration(configuration) |
| 113 | + .WithProps(buildProps) |
| 114 | + .WithFilter("Integration!=true&Docker!=true"); |
97 | 115 |
|
98 | 116 | var coveragePercentage = 0; |
99 | 117 | var skipTests = bool.Parse(GetProperty("skipTests", "false")); |
|
103 | 121 | } |
104 | 122 | else |
105 | 123 | { |
| 124 | + var reportDir = Path.Combine(currentDir, ".reports"); |
106 | 125 | var dotCoverSnapshot = Path.Combine(reportDir, "dotCover.dcvr"); |
107 | 126 | Succeed( |
108 | 127 | test |
|
138 | 157 | } |
139 | 158 | } |
140 | 159 |
|
141 | | -foreach (var package in packages) |
142 | | -{ |
143 | | - var packageOutput = Path.GetDirectoryName(package.Package); |
144 | | - if (Directory.Exists(packageOutput)) |
145 | | - { |
146 | | - Directory.Delete(packageOutput, true); |
147 | | - } |
148 | | - |
149 | | - Succeed(new DotNetPack() |
150 | | - .WithConfiguration(configuration) |
151 | | - .WithProps(buildProps) |
152 | | - .WithProject(package.Project) |
153 | | - .Build()); |
154 | | - |
155 | | - if (!File.Exists(package.Package)) |
156 | | - { |
157 | | - Error($"The NuGet package {package.Package} was not found."); |
158 | | - return 1; |
159 | | - } |
160 | | - |
161 | | - GetService<ITeamCityWriter>().PublishArtifact($"{package.Package} => ."); |
162 | | -} |
163 | | - |
164 | 160 | var uninstallTool = new DotNetCustom("tool", "uninstall", toolPackageId, "-g") |
165 | 161 | .WithShortName("Uninstalling tool"); |
166 | 162 |
|
167 | | -if (uninstallTool.Run(output => WriteLine(output.Line)) != 0) |
| 163 | +if (uninstallTool.Run(_ => { } ) != 0) |
168 | 164 | { |
169 | 165 | Warning($"{uninstallTool} failed."); |
170 | 166 | } |
171 | 167 |
|
| 168 | +if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) |
| 169 | +{ |
| 170 | + var toolsDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".dotnet", "tools"); |
| 171 | + var pathEnvVar = Environment.GetEnvironmentVariable("PATH"); |
| 172 | + Info($"Prev PATH={pathEnvVar}"); |
| 173 | + pathEnvVar = $"{pathEnvVar}:{toolsDir}"; |
| 174 | + Info($"New PATH={pathEnvVar}"); |
| 175 | + Environment.SetEnvironmentVariable("PATH", pathEnvVar); |
| 176 | +} |
| 177 | + |
172 | 178 | var installTool = new DotNetCustom("tool", "install", toolPackageId, "-g", "--version", packageVersion.ToString(), "--add-source", Path.Combine(outputDir, "CSharpInteractive.Tool")) |
173 | 179 | .WithShortName("Installing tool"); |
174 | 180 |
|
|
179 | 185 |
|
180 | 186 | Succeed(new DotNetCustom("csi", "/?").Run(), "Checking tool"); |
181 | 187 |
|
182 | | -var uninstallTemplates = new DotNetCustom("new", "-u", templatesPackageId) |
| 188 | +var uninstallTemplates = new DotNetCustom("new", "uninstall", templatesPackageId) |
183 | 189 | .WithShortName("Uninstalling template"); |
184 | 190 |
|
185 | 191 | if (uninstallTemplates.Run(output => WriteLine(output.Line)) != 0) |
186 | 192 | { |
187 | 193 | Warning($"{uninstallTemplates} failed."); |
188 | 194 | } |
189 | 195 |
|
190 | | -var installTemplates = new DotNetCustom("new", "-i", $"{templatesPackageId}::{packageVersion.ToString()}", "--nuget-source", templateOutputDir) |
| 196 | +var installTemplates = new DotNetCustom("new", "install", $"{templatesPackageId}::{packageVersion.ToString()}", "--nuget-source", templateOutputDir) |
191 | 197 | .WithShortName("Installing template"); |
192 | 198 |
|
193 | 199 | Succeed(installTemplates.Run(), installTemplates.ShortName); |
194 | 200 |
|
195 | 201 | foreach (var framework in frameworks) |
196 | 202 | { |
197 | | - var buildProjectDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()[..8]); |
| 203 | + var buildProjectDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()[..4]); |
198 | 204 | Directory.CreateDirectory(buildProjectDir); |
199 | 205 | var sampleProjectName = $"sample project for {framework}"; |
200 | 206 | try |
201 | 207 | { |
202 | 208 | var sampleProjectDir = Path.Combine("Samples", "DemoProject", "MySampleLib", "MySampleLib.Tests"); |
203 | | - Succeed(new DotNetCustom("new", "build", $"--package-version={packageVersion}", "-T", framework, "--no-restore").WithWorkingDirectory(buildProjectDir).Run(), $"Creating a new {sampleProjectName}"); |
204 | | - Succeed(new DotNetBuild().WithProject(buildProjectDir).AddSources(Path.Combine(outputDir, "CSharpInteractive")).WithShortName($"Building the {sampleProjectName}").Build()); |
| 209 | + Succeed(new DotNetNew("build", $"--package-version={packageVersion}", "-T", framework, "--no-restore").WithWorkingDirectory(buildProjectDir).Run(), $"Creating a new {sampleProjectName}"); |
| 210 | + Succeed(new DotNetBuild().WithProject(buildProjectDir).WithSources(defaultNuGetSource, Path.Combine(outputDir, "CSharpInteractive")).WithShortName($"Building the {sampleProjectName}").Build()); |
205 | 211 | Succeed(new DotNetRun().WithProject(buildProjectDir).WithNoBuild(true).WithWorkingDirectory(sampleProjectDir).Run(), $"Running a build for the {sampleProjectName}"); |
206 | 212 | Succeed(new DotNetCustom("csi", Path.Combine(buildProjectDir, "Program.csx")).WithWorkingDirectory(sampleProjectDir).Run(), $"Running a build as a C# script for the {sampleProjectName}"); |
207 | 213 | } |
|
213 | 219 |
|
214 | 220 | if (!string.IsNullOrWhiteSpace(apiKey) && packageVersion.Release != "dev" && packageVersion.Release != "dev") |
215 | 221 | { |
216 | | - var push = new DotNetNuGetPush().WithApiKey(apiKey).WithSources("https://api.nuget.org/v3/index.json"); |
| 222 | + var push = new DotNetNuGetPush().WithApiKey(apiKey).WithSources(defaultNuGetSource); |
217 | 223 | foreach (var package in packages.Where(i => i.Publish)) |
218 | 224 | { |
219 | 225 | Succeed(push.WithPackage(package.Package).Run(), $"Pushing {Path.GetFileName(package.Package)}"); |
|
0 commit comments