Skip to content

Commit

Permalink
[wasm] Fix "bump-chrome-pr.env" update. (#98480)
Browse files Browse the repository at this point in the history
* Fix "bump-chrome-pr.env" update.

* Fix: do not overwrite the .env file (emptying it) when there was no update.
  • Loading branch information
ilonatommy authored Feb 15, 2024
1 parent 72c488e commit 9636262
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
11 changes: 3 additions & 8 deletions eng/testing/bump-chrome-version.proj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<UsingTask AssemblyFile="$(WasmBuildTasksAssemblyPath)" TaskName="Microsoft.WebAssembly.Build.Tasks.UpdateChromeVersions" />
<PropertyGroup>
<ChromeVersionsPath>$(RepositoryEngineeringDir)testing\ChromeVersions.props</ChromeVersionsPath>
<EnvVarsForPRPath>$(RepositoryEngineeringDir)testing\bump-chrome-pr.env</EnvVarsForPRPath>
</PropertyGroup>

<Target Name="UpdateChromeVersion">
Expand All @@ -13,19 +14,13 @@
Channel="$(ChromeChannel)"
MaxMajorVersionsToCheck="1"
IntermediateOutputPath="$(ArtifactsObjDir)"
ChromeVersionsPath="$(ChromeVersionsPath)">
ChromeVersionsPath="$(ChromeVersionsPath)"
EnvVarsForPRPath="$(EnvVarsForPRPath)">
<Output TaskParameter="VersionsChanged" PropertyName="VersionsChanged" />
</UpdateChromeVersions>

<ItemGroup>
<!-- ensure newline at the end -->
<EnvVarForPR Include="CHROME_LINUX_VER=$(linux_ChromeVersion)" />
<EnvVarForPR Include="CHROME_WIN_VER=$(win_ChromeVersion)" />
</ItemGroup>

<Message Text="No major changes: skipping version props update." Importance="High" Condition="'$(VersionsChanged)' != 'true'"/>
<Message Text="Version props got updated" Importance="High" Condition="'$(VersionsChanged)' == 'true'"/>

</Target>

<Import Project="..\..\Directory.Build.targets" />
Expand Down
29 changes: 29 additions & 0 deletions src/tasks/WasmBuildTasks/UpdateChromeVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public partial class UpdateChromeVersions : MBU.Task
[Required, NotNull]
public string ChromeVersionsPath { get; set; } = string.Empty;

[Required, NotNull]
public string EnvVarsForPRPath { get; set; } = string.Empty;

public int MaxMajorVersionsToCheck { get; set; } = 2;

// start at the branch position found in all.json, and try to
Expand All @@ -70,15 +73,21 @@ private async Task<bool> ExecuteInternalAsync()
XmlDocument chromeVersionsXmlDoc = new XmlDocument();
chromeVersionsXmlDoc.Load(ChromeVersionsPath);
var osInfo = OSIdentifiers.Zip(OSPrefixes, (num, str) => new { Identifier = num, Prefix = str });
List<ChromeVersionSpec> versions = new();
foreach (var info in osInfo)
{
(ChromeVersionSpec version, string baseUrl) = await FindVersionFromChromiumDash(info.Prefix, info.Identifier).ConfigureAwait(false);
versions.Add(version);
bool hasMajorChanges = AreVersionsChanged(chromeVersionsXmlDoc, version, baseUrl);
if (hasMajorChanges)
{
VersionsChanged = UpdateChromeVersionsFile(chromeVersionsXmlDoc, version, baseUrl);
}
}
if (VersionsChanged)
{
UpdateEnvVarsForPRFile(versions);
}
return !Log.HasLoggedErrors;
}
catch (LogAsErrorException laee)
Expand Down Expand Up @@ -137,6 +146,26 @@ private bool UpdateChromeVersionsFile(XmlDocument xmlDoc, ChromeVersionSpec vers
return true;
}

private void UpdateEnvVarsForPRFile(List<ChromeVersionSpec> versions)
{
using StreamWriter writer = new StreamWriter(EnvVarsForPRPath);
foreach (var version in versions)
{
if (string.Equals(version.os, "Linux", StringComparison.OrdinalIgnoreCase))
{
writer.WriteLine($"CHROME_LINUX_VER={version.version}");
}
else if (string.Equals(version.os, "Windows", StringComparison.OrdinalIgnoreCase))
{
writer.WriteLine($"CHROME_WIN_VER={version.version}");
}
else
{
throw new Exception($"UpdateEnvVarsForPRFile task was used with unknown OS: {version.os}");
}
}
}

private static void UpdateNodeValue(XmlDocument xmlDoc, string nodeName, string newValue)
{
XmlNode? node = xmlDoc.SelectSingleNode($"/Project/PropertyGroup/{nodeName}");
Expand Down

0 comments on commit 9636262

Please sign in to comment.