Skip to content

Commit 366f9a7

Browse files
committed
Consider the new edge content source when matching branches, also always build main and master speculatively if not configured as contentsource
1 parent 15eeaa5 commit 366f9a7

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

src/Elastic.Documentation.Configuration/Assembler/AssemblyConfiguration.cs

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private static TRepository RepositoryDefaults<TRepository>(TRepository r, string
129129
/// <paramref name="repository"/>.
130130
public ContentSourceMatch Match(string repository, string branchOrTag)
131131
{
132-
var match = new ContentSourceMatch(null, null, false);
132+
var match = new ContentSourceMatch(null, null, null, false);
133133
var tokens = repository.Split('/');
134134
var repositoryName = tokens.Last();
135135
var owner = tokens.First();
@@ -141,34 +141,29 @@ public ContentSourceMatch Match(string repository, string branchOrTag)
141141
{
142142
var current = r.GetBranch(ContentSource.Current);
143143
var next = r.GetBranch(ContentSource.Next);
144+
var edge = r.GetBranch(ContentSource.Edge);
144145
var isVersionBranch = ContentSourceRegex.MatchVersionBranch().IsMatch(branchOrTag);
145146
if (current == branchOrTag)
146147
match = match with { Current = ContentSource.Current };
147148

148149
if (next == branchOrTag)
149-
match = match with
150-
{
151-
Next = ContentSource.Next
152-
};
150+
match = match with { Next = ContentSource.Next };
151+
152+
if (edge == branchOrTag)
153+
match = match with { Edge = ContentSource.Edge };
154+
153155
if (isVersionBranch && SemVersion.TryParse(branchOrTag + ".0", out var v))
154156
{
155157
// if the current branch is a version, only speculatively match if branch is actually a new version
156158
if (SemVersion.TryParse(current + ".0", out var currentVersion))
157159
{
158160
if (v >= currentVersion)
159-
match = match with
160-
{
161-
Speculative = true
162-
};
161+
match = match with { Speculative = true };
163162
}
164163
// assume we are newly onboarding the repository to current/next
165164
else
166-
match = match with
167-
{
168-
Speculative = true
169-
};
165+
match = match with { Speculative = true };
170166
}
171-
172167
return match;
173168
}
174169

@@ -177,27 +172,27 @@ public ContentSourceMatch Match(string repository, string branchOrTag)
177172
// this is an unknown new elastic repository
178173
var isVersionBranch = ContentSourceRegex.MatchVersionBranch().IsMatch(branchOrTag);
179174
if (isVersionBranch || branchOrTag == "main" || branchOrTag == "master")
180-
return match with
181-
{
182-
Speculative = true
183-
};
175+
return match with { Speculative = true };
184176
}
185177

186178
if (Narrative.GetBranch(ContentSource.Current) == branchOrTag)
187-
match = match with
188-
{
189-
Current = ContentSource.Current
190-
};
179+
match = match with { Current = ContentSource.Current };
180+
191181
if (Narrative.GetBranch(ContentSource.Next) == branchOrTag)
192-
match = match with
193-
{
194-
Next = ContentSource.Next
195-
};
182+
match = match with { Next = ContentSource.Next };
183+
184+
if (Narrative.GetBranch(ContentSource.Edge) == branchOrTag)
185+
match = match with { Edge = ContentSource.Edge };
186+
187+
// if we haven't matched anything yet, and the branch is 'main' or 'master' always build
188+
if (match is { Current: null, Next: null, Edge: null, Speculative: false}
189+
&& branchOrTag is "main" or "master")
190+
return match with { Speculative = true };
196191

197192
return match;
198193
}
199194

200-
public record ContentSourceMatch(ContentSource? Current, ContentSource? Next, bool Speculative);
195+
public record ContentSourceMatch(ContentSource? Current, ContentSource? Next, ContentSource? Edge, bool Speculative);
201196
}
202197

203198
internal static partial class ContentSourceRegex

src/services/Elastic.Documentation.Assembler/ContentSources/RepositoryBuildMatchingService.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ public async Task<bool> ShouldBuild(IDiagnosticsCollector collector, string? rep
4242
// environment does not matter to check the configuration, defaulting to dev
4343
var assembleContext = new AssembleContext(configuration, configurationContext, "dev", collector, fileSystem, fileSystem, null, null);
4444
var matches = assembleContext.Configuration.Match(repo, refName);
45-
if (matches is { Current: null, Next: null, Speculative: false })
45+
if (matches is { Current: null, Next: null, Edge: null, Speculative: false })
4646
{
4747
_logger.LogInformation("'{Repository}' '{BranchOrTag}' combination not found in configuration.", repo, refName);
4848
await githubActionsService.SetOutputAsync("content-source-match", "false");
4949
await githubActionsService.SetOutputAsync("content-source-next", "false");
50+
await githubActionsService.SetOutputAsync("content-source-edge", "false");
5051
await githubActionsService.SetOutputAsync("content-source-current", "false");
5152
await githubActionsService.SetOutputAsync("content-source-speculative", "false");
5253
return false;
@@ -60,6 +61,7 @@ public async Task<bool> ShouldBuild(IDiagnosticsCollector collector, string? rep
6061
await githubActionsService.SetOutputAsync("content-source-match", "true");
6162
await githubActionsService.SetOutputAsync("content-source-next", matches.Next is not null ? "true" : "false");
6263
await githubActionsService.SetOutputAsync("content-source-current", matches.Current is not null ? "true" : "false");
64+
await githubActionsService.SetOutputAsync("content-source-edge", matches.Edge is not null ? "true" : "false");
6365
await githubActionsService.SetOutputAsync("content-source-speculative", matches.Speculative ? "true" : "false");
6466
return true;
6567
}

0 commit comments

Comments
 (0)