Skip to content

Commit

Permalink
Allow running jobs against base branches other than main
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Sep 9, 2024
1 parent 138a3c5 commit d3c33d6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
15 changes: 8 additions & 7 deletions Runner/Helpers/RuntimeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
""");
Expand All @@ -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
Expand All @@ -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}");
Expand All @@ -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
Expand Down
12 changes: 8 additions & 4 deletions Runner/JobBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ public abstract class JobBase
public readonly ConcurrentQueue<Task> 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);

Expand Down Expand Up @@ -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"]}) ...");

Expand Down
6 changes: 3 additions & 3 deletions Runner/Jobs/RebaseJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<REDACTED>", StringComparison.OrdinalIgnoreCase));
Expand Down

0 comments on commit d3c33d6

Please sign in to comment.