Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge eng/ from main on assets push #8020

Merged
merged 13 commits into from
Apr 6, 2024
43 changes: 39 additions & 4 deletions tools/test-proxy/Azure.Sdk.Tools.TestProxy/Store/GitStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,46 @@ public async Task Push(string pathToAssetsJson) {
string branchGuid = Guid.NewGuid().ToString().Substring(0, 8);
string gitUserName = GetGitOwnerName(config);
string gitUserEmail = GetGitOwnerEmail(config);
string assetMessage = "Automatic asset update from test-proxy.";
string configurationString = $"-c user.name=\"{gitUserName}\" -c user.email=\"{gitUserEmail}\"";

GitHandler.Run($"branch {branchGuid}", config);
GitHandler.Run($"checkout {branchGuid}", config);

/*
* This code works by generating a patch file for SPECIFICALLY the eng folder from main.
weshaggard marked this conversation as resolved.
Show resolved Hide resolved
* Given that these changes appear as "new" changes, they just look like normal file additions.
* This totally eliminates the possibility of weird historical merge if main has code that we don't expect.
* Under azure-sdk-assets, we should never see this, but we have already seen it with specific integration
* test tags under azure-sdk-assets-integration. By keeping it as "patch", the soft RESET on unsuccessful
* push action will properly put their repo into the expected "ready to push" state that a failed
* merge would NOT.
*/
var engPatchLocation = Path.Combine(config.AssetsRepoLocation, "changes.patch");
GitHandler.Run($"diff --output=changes.patch --no-color --binary --no-prefix HEAD main -- eng/", config);
scbedd marked this conversation as resolved.
Show resolved Hide resolved
if (GitHandler.TryRun($"apply --check --directory=eng/ changes.patch", config.AssetsRepoLocation.ToString(), out var engPatchResult))
{
GitHandler.Run($"apply --directory=eng/ changes.patch", config);
}
if (File.Exists(engPatchLocation)) {
File.Delete(engPatchLocation);
}

GitHandler.Run($"diff --output=changes.patch --no-color --binary --no-prefix HEAD main -- .gitignore", config);
if (GitHandler.TryRun($"apply --check changes.patch", config.AssetsRepoLocation.ToString(), out var applyResult))
{
GitHandler.Run($"apply changes.patch", config);
}
if (File.Exists(engPatchLocation))
{
File.Delete(engPatchLocation);
}

// add all the recording changes and commit them
GitHandler.Run($"add -A .", config);
GitHandler.Run($"-c user.name=\"{gitUserName}\" -c user.email=\"{gitUserEmail}\" commit --no-gpg-sign -m \"Automatic asset update from test-proxy.\"", config);
// Get the first 10 digits of the commit SHA. The generatedTagName will be the
GitHandler.Run($"{configurationString} commit --no-gpg-sign -m \"{assetMessage}\"", config);

// Get the first 10 digits of the combined SHA. The generatedTagName will be the
// config.TagPrefix_<SHA>
if (GitHandler.TryRun("rev-parse --short=10 HEAD", config.AssetsRepoLocation.ToString(), out CommandResult SHAResult))
{
Expand Down Expand Up @@ -547,11 +582,11 @@ public string ResolveCheckoutPaths(GitAssetsConfiguration config)

if (combinedPath.ToLower() == AssetsJsonFileName)
{
return "./";
return "./ eng/";
}
else
{
return combinedPath.Substring(0, combinedPath.Length - (AssetsJsonFileName.Length + 1));
return combinedPath.Substring(0, combinedPath.Length - (AssetsJsonFileName.Length + 1)) + " eng/";
}
}
#endregion
Expand Down
Loading