Fix UpdateVersionsRepo to always write the files correctly.
We were only building nupkgs on windows, which meant if a non-windows machine was the last leg to finish, we were writing a blank file to the versions repo. Fix #4399
This commit is contained in:
parent
70c65160f6
commit
21471aa956
10 changed files with 30 additions and 187 deletions
|
@ -17,4 +17,9 @@
|
||||||
<PlatformAbstractionsVersion>1.0.3</PlatformAbstractionsVersion>
|
<PlatformAbstractionsVersion>1.0.3</PlatformAbstractionsVersion>
|
||||||
<DependencyModelVersion>1.0.3</DependencyModelVersion>
|
<DependencyModelVersion>1.0.3</DependencyModelVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<!-- infrastructure and test only dependencies -->
|
||||||
|
<PropertyGroup>
|
||||||
|
<VersionToolsVersion>1.0.27-prerelease-01402-01</VersionToolsVersion>
|
||||||
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
<Project ToolsVersion="14.0" DefaultTargets="Layout" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="14.0" DefaultTargets="Layout" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<PackagingBuildBasePath>$(CompilationDirectory)/forPackaging</PackagingBuildBasePath>
|
<PackagingBuildBasePath>$(CompilationDirectory)/forPackaging</PackagingBuildBasePath>
|
||||||
<NupkgOutputDirectory>$(PackagesDirectory)</NupkgOutputDirectory>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Target Name="SetupProjectsToPack"
|
<Target Name="SetupProjectsToPack"
|
||||||
|
@ -16,11 +15,10 @@
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="GenerateNugetPackages"
|
<Target Name="GenerateNugetPackages"
|
||||||
DependsOnTargets="Init; SetupProjectsToPack"
|
DependsOnTargets="Init; SetupProjectsToPack">
|
||||||
Condition=" '$(OS)' == 'Windows_NT' ">
|
|
||||||
|
|
||||||
<DotNetPack NoBuild="True"
|
<DotNetPack NoBuild="True"
|
||||||
Output="$(NupkgOutputDirectory)"
|
Output="$(PackagesDirectory)"
|
||||||
ProjectPath="%(ProjectsToPack.Identity)/%(ProjectsToPack.ProjectName).csproj"
|
ProjectPath="%(ProjectsToPack.Identity)/%(ProjectsToPack.ProjectName).csproj"
|
||||||
ToolPath="$(Stage0Directory)"
|
ToolPath="$(Stage0Directory)"
|
||||||
VersionSuffix="$(VersionSuffix)"
|
VersionSuffix="$(VersionSuffix)"
|
||||||
|
@ -28,8 +26,7 @@
|
||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<Target Name="BuildProjectsForNuGetPackages"
|
<Target Name="BuildProjectsForNuGetPackages"
|
||||||
DependsOnTargets="Init; SetupProjectsToPack"
|
DependsOnTargets="Init; SetupProjectsToPack">
|
||||||
Condition=" '$(OS)' == 'Windows_NT' ">
|
|
||||||
|
|
||||||
<MakeDir Directories="$(PackagingBuildBasePath)" />
|
<MakeDir Directories="$(PackagingBuildBasePath)" />
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
Channel="$(Channel)"
|
Channel="$(Channel)"
|
||||||
CommitHash="$(CommitHash)" />
|
CommitHash="$(CommitHash)" />
|
||||||
|
|
||||||
<UpdateVersionsRepo BranchName="$(BranchName)" />
|
<UpdateVersionsRepo BranchName="$(BranchName)"
|
||||||
|
PackagesDirectory="$(PackagesDirectory)"
|
||||||
|
GitHubPassword="$(GITHUB_PASSWORD)" />
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using Microsoft.Build.Framework;
|
using Microsoft.Build.Framework;
|
||||||
using Microsoft.Build.Utilities;
|
using Microsoft.Build.Utilities;
|
||||||
|
using Microsoft.DotNet.VersionTools.Automation;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Build
|
namespace Microsoft.DotNet.Cli.Build
|
||||||
{
|
{
|
||||||
|
@ -11,15 +12,21 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
[Required]
|
[Required]
|
||||||
public string BranchName { get; set; }
|
public string BranchName { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string PackagesDirectory { get; set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public string GitHubPassword { get; set; }
|
||||||
|
|
||||||
public override bool Execute()
|
public override bool Execute()
|
||||||
{
|
{
|
||||||
string githubAuthToken = EnvVars.EnsureVariable("GITHUB_PASSWORD");
|
string versionsRepoPath = $"build-info/dotnet/cli/{BranchName}";
|
||||||
string nupkgFilePath = Dirs.Packages;
|
|
||||||
string branchName = BranchName;
|
|
||||||
string versionsRepoPath = $"build-info/dotnet/cli/{branchName}/Latest";
|
|
||||||
|
|
||||||
VersionRepoUpdater repoUpdater = new VersionRepoUpdater(githubAuthToken);
|
GitHubAuth auth = new GitHubAuth(GitHubPassword);
|
||||||
repoUpdater.UpdatePublishedVersions(nupkgFilePath, versionsRepoPath).Wait();
|
GitHubVersionsRepoUpdater repoUpdater = new GitHubVersionsRepoUpdater(auth);
|
||||||
|
repoUpdater.UpdateBuildInfoAsync(
|
||||||
|
new [] { PackagesDirectory },
|
||||||
|
versionsRepoPath).Wait();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,5 +30,6 @@
|
||||||
led to an error. This is tracked as NuGet issue : https://github.com/NuGet/Home/issues/4213 -->
|
led to an error. This is tracked as NuGet issue : https://github.com/NuGet/Home/issues/4213 -->
|
||||||
<PackageReference Include="Microsoft.Build.Framework" Version="$(CLI_MSBuild_Version)" />
|
<PackageReference Include="Microsoft.Build.Framework" Version="$(CLI_MSBuild_Version)" />
|
||||||
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" />
|
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" />
|
||||||
</ItemGroup>
|
<PackageReference Include="Microsoft.DotNet.VersionTools" Version="$(VersionToolsVersion)" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -1,20 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using Microsoft.DotNet.PlatformAbstractions;
|
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Build
|
|
||||||
{
|
|
||||||
public static class Dirs
|
|
||||||
{
|
|
||||||
public static readonly string RepoRoot = Directory.GetCurrentDirectory();
|
|
||||||
public static readonly string Output = Path.Combine(
|
|
||||||
RepoRoot,
|
|
||||||
"artifacts",
|
|
||||||
RuntimeEnvironment.GetRuntimeIdentifier());
|
|
||||||
public static readonly string Packages = Path.Combine(Output, "packages");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,142 +0,0 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Http;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Build
|
|
||||||
{
|
|
||||||
public class VersionRepoUpdater
|
|
||||||
{
|
|
||||||
private static Regex s_nugetFileRegex = new Regex("^(?<id>.*?)\\.(?<version>([0-9]+\\.)?[0-9]+\\.[0-9]+(-(?<prerelease>[A-z0-9-]+))?)(?<symbols>\\.symbols)?\\.nupkg$");
|
|
||||||
|
|
||||||
private string _gitHubAuthToken;
|
|
||||||
private string _gitHubUser;
|
|
||||||
private string _gitHubEmail;
|
|
||||||
private string _versionsRepoOwner;
|
|
||||||
private string _versionsRepo;
|
|
||||||
|
|
||||||
public VersionRepoUpdater(
|
|
||||||
string gitHubAuthToken,
|
|
||||||
string gitHubUser = null,
|
|
||||||
string gitHubEmail = null,
|
|
||||||
string versionRepoOwner = null,
|
|
||||||
string versionsRepo = null)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(gitHubAuthToken))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(gitHubAuthToken));
|
|
||||||
}
|
|
||||||
|
|
||||||
_gitHubAuthToken = gitHubAuthToken;
|
|
||||||
_gitHubUser = gitHubUser ?? "dotnet-bot";
|
|
||||||
_gitHubEmail = gitHubEmail ?? "dotnet-bot@microsoft.com";
|
|
||||||
_versionsRepoOwner = versionRepoOwner ?? "dotnet";
|
|
||||||
_versionsRepo = versionsRepo ?? "versions";
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task UpdatePublishedVersions(string nupkgFilePath, string versionsRepoPath)
|
|
||||||
{
|
|
||||||
List<NuGetPackageInfo> publishedPackages = GetPackageInfo(nupkgFilePath);
|
|
||||||
|
|
||||||
string packageInfoFileContent = string.Join(
|
|
||||||
Environment.NewLine,
|
|
||||||
publishedPackages
|
|
||||||
.OrderBy(t => t.Id)
|
|
||||||
.Select(t => $"{t.Id} {t.Version}"));
|
|
||||||
|
|
||||||
string prereleaseVersion = publishedPackages
|
|
||||||
.Where(t => !string.IsNullOrEmpty(t.Prerelease))
|
|
||||||
.Select(t => t.Prerelease)
|
|
||||||
.FirstOrDefault();
|
|
||||||
|
|
||||||
string packageInfoFilePath = $"{versionsRepoPath}_Packages.txt";
|
|
||||||
string message = $"Adding package info to {packageInfoFilePath} for {prereleaseVersion}";
|
|
||||||
|
|
||||||
await UpdateGitHubFile(packageInfoFilePath, packageInfoFileContent, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<NuGetPackageInfo> GetPackageInfo(string nupkgFilePath)
|
|
||||||
{
|
|
||||||
List<NuGetPackageInfo> packages = new List<NuGetPackageInfo>();
|
|
||||||
|
|
||||||
foreach (string filePath in Directory.GetFiles(nupkgFilePath, "*.nupkg"))
|
|
||||||
{
|
|
||||||
Match match = s_nugetFileRegex.Match(Path.GetFileName(filePath));
|
|
||||||
|
|
||||||
// only look for non-symbols packages
|
|
||||||
if (string.IsNullOrEmpty(match.Groups["symbols"].Value))
|
|
||||||
{
|
|
||||||
packages.Add(new NuGetPackageInfo()
|
|
||||||
{
|
|
||||||
Id = match.Groups["id"].Value,
|
|
||||||
Version = match.Groups["version"].Value,
|
|
||||||
Prerelease = match.Groups["prerelease"].Value,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return packages;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task UpdateGitHubFile(string path, string newFileContent, string commitMessage)
|
|
||||||
{
|
|
||||||
using (HttpClient client = new HttpClient())
|
|
||||||
{
|
|
||||||
client.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3+json");
|
|
||||||
client.DefaultRequestHeaders.Add("Authorization", $"token {_gitHubAuthToken}");
|
|
||||||
client.DefaultRequestHeaders.Add("User-Agent", _gitHubUser);
|
|
||||||
|
|
||||||
string fileUrl = $"https://api.github.com/repos/{_versionsRepoOwner}/{_versionsRepo}/contents/{path}";
|
|
||||||
|
|
||||||
Console.WriteLine($"Getting the 'sha' of the current contents of file '{_versionsRepoOwner}/{_versionsRepo}/{path}'");
|
|
||||||
|
|
||||||
string currentFile = await client.GetStringAsync(fileUrl);
|
|
||||||
string currentSha = JObject.Parse(currentFile)["sha"].ToString();
|
|
||||||
|
|
||||||
Console.WriteLine($"Got 'sha' value of '{currentSha}'");
|
|
||||||
|
|
||||||
Console.WriteLine($"Request to update file '{_versionsRepoOwner}/{_versionsRepo}/{path}' contents to:");
|
|
||||||
Console.WriteLine(newFileContent);
|
|
||||||
|
|
||||||
string updateFileBody = $@"{{
|
|
||||||
""message"": ""{commitMessage}"",
|
|
||||||
""committer"": {{
|
|
||||||
""name"": ""{_gitHubUser}"",
|
|
||||||
""email"": ""{_gitHubEmail}""
|
|
||||||
}},
|
|
||||||
""content"": ""{ToBase64(newFileContent)}"",
|
|
||||||
""sha"": ""{currentSha}""
|
|
||||||
}}";
|
|
||||||
|
|
||||||
Console.WriteLine("Sending request...");
|
|
||||||
StringContent content = new StringContent(updateFileBody);
|
|
||||||
|
|
||||||
using (HttpResponseMessage response = await client.PutAsync(fileUrl, content))
|
|
||||||
{
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
Console.WriteLine("Updated the file successfully...");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string ToBase64(string value)
|
|
||||||
{
|
|
||||||
return Convert.ToBase64String(Encoding.UTF8.GetBytes(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class NuGetPackageInfo
|
|
||||||
{
|
|
||||||
public string Id { get; set; }
|
|
||||||
public string Version { get; set; }
|
|
||||||
public string Prerelease { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.0" />
|
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.0" />
|
||||||
<PackageReference Include="Microsoft.DotNet.VersionTools" Version="1.0.27-prerelease-01316-08" />
|
<PackageReference Include="Microsoft.DotNet.VersionTools" Version="$(VersionToolsVersion)" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>$(SdkVersion)</Version>
|
<Version>$(SdkVersion)</Version>
|
||||||
<TargetFrameworks>netstandard1.5;net46</TargetFrameworks>
|
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">netstandard1.5;net46</TargetFrameworks>
|
||||||
|
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.5</TargetFrameworks>
|
||||||
<WarningsAsErrors>true</WarningsAsErrors>
|
<WarningsAsErrors>true</WarningsAsErrors>
|
||||||
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>
|
||||||
<SignAssembly>true</SignAssembly>
|
<SignAssembly>true</SignAssembly>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Description>Microsoft.DotNet.TestFramework Class Library</Description>
|
<Description>Microsoft.DotNet.TestFramework Class Library</Description>
|
||||||
<VersionPrefix>$(CliVersionPrefix)</VersionPrefix>
|
<VersionPrefix>$(CliVersionPrefix)</VersionPrefix>
|
||||||
<TargetFrameworks>netstandard1.5;net46</TargetFrameworks>
|
<TargetFramework>netstandard1.5</TargetFramework>
|
||||||
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>
|
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>
|
||||||
<SignAssembly>true</SignAssembly>
|
<SignAssembly>true</SignAssembly>
|
||||||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
||||||
|
@ -14,12 +14,4 @@
|
||||||
<ProjectReference Include="..\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" />
|
<ProjectReference Include="..\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' != 'net46' ">
|
|
||||||
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.0.1" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
|
|
||||||
<Reference Include="System" />
|
|
||||||
<Reference Include="Microsoft.CSharp" />
|
|
||||||
</ItemGroup>
|
|
||||||
</Project>
|
</Project>
|
Loading…
Reference in a new issue