From d3c33d679c96a53c638bb15ae13d4095b617cc38 Mon Sep 17 00:00:00 2001 From: Miha Zupan Date: Mon, 9 Sep 2024 20:22:34 +0200 Subject: [PATCH] Allow running jobs against base branches other than main --- Runner/Helpers/RuntimeHelpers.cs | 15 ++++++++------- Runner/JobBase.cs | 12 ++++++++---- Runner/Jobs/RebaseJob.cs | 6 +++--- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Runner/Helpers/RuntimeHelpers.cs b/Runner/Helpers/RuntimeHelpers.cs index c1f8acb..3cb1dc4 100644 --- a/Runner/Helpers/RuntimeHelpers.cs +++ b/Runner/Helpers/RuntimeHelpers.cs @@ -21,11 +21,12 @@ public static async Task CloneRuntimeAsync(JobBase job) if (OperatingSystem.IsLinux()) { string script = UpdateMergePlaceholders( - """ + $$$""" set -e - git clone --no-tags --single-branch --progress https://github.com/dotnet/runtime runtime + git clone --no-tags --branch {{{job.BaseBranch}}} --single-branch --progress https://github.com/{{{job.BaseRepo}}} runtime cd runtime + git log -1 chmod 777 build.sh git config --global user.email build@build.foo @@ -37,7 +38,7 @@ git config --global user.name build {{MERGE_PR_BRANCHES}} - git switch main + git switch {{{job.BaseBranch}}} eng/install-native-dependencies.sh linux """); @@ -49,9 +50,9 @@ git config --global user.name build else { string script = UpdateMergePlaceholders( - """ + $$$""" git config --system core.longpaths true - git clone --no-tags --single-branch --progress https://github.com/dotnet/runtime runtime + git clone --no-tags --branch {{{job.BaseBranch}}} --single-branch --progress https://github.com/{{{job.BaseRepo}}} runtime cd runtime git log -1 git config --global user.email build@build.foo @@ -63,7 +64,7 @@ git config --global user.name build {{MERGE_PR_BRANCHES}} - git switch main + git switch {{{job.BaseBranch}}} """); await job.LogAsync($"Using runtime setup script:\n{script}"); @@ -87,7 +88,7 @@ string GetMergeScript(string name) if (name == "combineWith") { - prList.Insert(0, (job.SourceRepo, job.SourceBranch)); + prList.Insert(0, (job.PrRepo, job.PrBranch)); } return string.Join('\n', prList diff --git a/Runner/JobBase.cs b/Runner/JobBase.cs index c39221a..f87d1f3 100644 --- a/Runner/JobBase.cs +++ b/Runner/JobBase.cs @@ -34,8 +34,10 @@ public abstract class JobBase public readonly ConcurrentQueue PendingTasks = new(); public string CustomArguments => Metadata["CustomArguments"]; - public string SourceRepo => Metadata["PrRepo"]; - public string SourceBranch => Metadata["PrBranch"]; + public string BaseRepo => Metadata["BaseRepo"]; + public string BaseBranch => Metadata["BaseBranch"]; + public string PrRepo => Metadata["PrRepo"]; + public string PrBranch => Metadata["PrBranch"]; public bool TryGetFlag(string name) => CustomArguments.Contains($"-{name}", StringComparison.OrdinalIgnoreCase); @@ -108,8 +110,10 @@ public async Task RunJobAsync() await LogAsync($"{nameof(Environment.CurrentDirectory)}={Environment.CurrentDirectory}"); await LogAsync($"{nameof(RuntimeInformation.FrameworkDescription)}={RuntimeInformation.FrameworkDescription}"); await LogAsync($"{nameof(RuntimeInformation.RuntimeIdentifier)}={RuntimeInformation.RuntimeIdentifier}"); - await LogAsync($"{nameof(SourceRepo)}={SourceRepo}"); - await LogAsync($"{nameof(SourceBranch)}={SourceBranch}"); + await LogAsync($"{nameof(BaseRepo)}={BaseRepo}"); + await LogAsync($"{nameof(BaseBranch)}={BaseBranch}"); + await LogAsync($"{nameof(PrRepo)}={PrRepo}"); + await LogAsync($"{nameof(PrBranch)}={PrBranch}"); Console.WriteLine($"Starting {Metadata["JobType"]} ({Metadata["ExternalId"]}) ..."); diff --git a/Runner/Jobs/RebaseJob.cs b/Runner/Jobs/RebaseJob.cs index 3a3bb46..4007908 100644 --- a/Runner/Jobs/RebaseJob.cs +++ b/Runner/Jobs/RebaseJob.cs @@ -19,9 +19,9 @@ cd runtime git log -1 git config --global user.email mihubot@mihubot.xyz git config --global user.name MihuBot - git remote add pr https://MihuBot:{{pushToken}}@github.com/{{SourceRepo}}.git - git fetch pr {{SourceBranch}} - git checkout {{SourceBranch}} + git remote add pr https://MihuBot:{{pushToken}}@github.com/{{PrRepo}}.git + git fetch pr {{PrBranch}} + git checkout {{PrBranch}} git log -1 """, line => line.Replace(pushToken, "", StringComparison.OrdinalIgnoreCase));