Skip to content

Commit 53e9e30

Browse files
authored
Assembler match: print each content source explicitly (#1286)
1 parent ece1dea commit 53e9e30

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

actions/assembler-match/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ outputs:
1818
description: 'true/false indicating the branch matches a content-source'
1919
content-source-name:
2020
description: "The name of the content source that matches (current/next) or empty"
21+
content-source-next:
22+
description: "true/false indicating the branch acts as the next content source"
23+
content-source-current:
24+
description: "true/false indicating the branch acts as the current content source"
2125

2226
runs:
2327
using: 'docker'

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

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,29 @@ private static TRepository RepositoryDefaults<TRepository>(TRepository r, string
8181

8282
/// Returns whether the <paramref name="branchOrTag"/> is configured as an integration branch or tag for the given
8383
/// <paramref name="repository"/>.
84-
public ContentSource? Match(string repository, string branchOrTag)
84+
public ContentSourceMatch Match(string repository, string branchOrTag)
8585
{
8686
var repositoryName = repository.Split('/').Last();
87+
var match = new ContentSourceMatch(null, null);
8788
if (ReferenceRepositories.TryGetValue(repositoryName, out var r))
8889
{
8990
if (r.GetBranch(ContentSource.Current) == branchOrTag)
90-
return ContentSource.Current;
91+
match = match with { Current = ContentSource.Current };
9192
if (r.GetBranch(ContentSource.Next) == branchOrTag)
92-
return ContentSource.Next;
93-
return null;
93+
match = match with { Next = ContentSource.Next };
94+
return match;
9495
}
9596

96-
if (repositoryName == NarrativeRepository.RepositoryName)
97-
{
98-
if (Narrative.GetBranch(ContentSource.Current) == branchOrTag)
99-
return ContentSource.Current;
100-
if (Narrative.GetBranch(ContentSource.Next) == branchOrTag)
101-
return ContentSource.Next;
102-
}
97+
if (repositoryName != NarrativeRepository.RepositoryName)
98+
return match;
10399

104-
return null;
100+
if (Narrative.GetBranch(ContentSource.Current) == branchOrTag)
101+
match = match with { Current = ContentSource.Current };
102+
if (Narrative.GetBranch(ContentSource.Next) == branchOrTag)
103+
match = match with { Next = ContentSource.Next };
104+
105+
return match;
105106
}
107+
108+
public record ContentSourceMatch(ContentSource? Current, ContentSource? Next);
106109
}

src/tooling/docs-assembler/Cli/ContentSourceCommands.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,25 @@ public async Task<int> Match([Argument] string? repository = null, [Argument] st
5555
AllowIndexing = false
5656
};
5757
var matches = assembleContext.Configuration.Match(repo, refName);
58-
if (matches == null)
58+
if (matches is { Current: null, Next: null })
5959
{
6060
logger.LogInformation("'{Repository}' '{BranchOrTag}' combination not found in configuration.", repo, refName);
6161
await githubActionsService.SetOutputAsync("content-source-match", "false");
6262
await githubActionsService.SetOutputAsync("content-source-name", "");
6363
}
6464
else
6565
{
66-
var name = matches.Value.ToStringFast(true);
67-
logger.LogInformation("'{Repository}' '{BranchOrTag}' is configured as '{Matches}' content-source", repo, refName, name);
66+
if (matches.Current is { } current)
67+
logger.LogInformation("'{Repository}' '{BranchOrTag}' is configured as '{Matches}' content-source", repo, refName, current.ToStringFast(true));
68+
if (matches.Next is { } next)
69+
logger.LogInformation("'{Repository}' '{BranchOrTag}' is configured as '{Matches}' content-source", repo, refName, next.ToStringFast(true));
6870

6971
await githubActionsService.SetOutputAsync("content-source-match", "true");
72+
await githubActionsService.SetOutputAsync("content-source-next", matches.Next is not null ? "true" : "false");
73+
await githubActionsService.SetOutputAsync("content-source-current", matches.Current is not null ? "true" : "false");
74+
75+
//TODO remove once we've merged our changes to the github action and its workflow usage to no longer use this output
76+
var name = (matches.Current ?? matches.Next)!.Value.ToStringFast(true);
7077
await githubActionsService.SetOutputAsync("content-source-name", name);
7178
}
7279

0 commit comments

Comments
 (0)