Skip to content

Commit 755ba56

Browse files
authored
Add a new job to handle push event matching (#1279)
* Add a new job to handle push event matching Introduce a "match" job to process push event-specific logic and outputs, ensuring proper handling of event types. This includes conditional steps for different event contexts and prepares outputs for downstream "build" job dependencies. * revert assembler.yml * PR feedback * add pr target temporarily * remove type filters * Remove pull request target * fix duplicate id * fix env vars * reverse checks to see the other path * update variable * update variable * debug * temporarily add docs-builder to assembler * cleanup * Add docs-builder as skipped reference so it publishes from 'main' * move back to pull_request_target
1 parent 13242b1 commit 755ba56

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

.github/workflows/preview-build.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ on:
1010
branches:
1111
- main
1212
- master
13+
# TODO remove these need to be added to individual repositories
14+
- '\d+.\d+.\d+'
15+
- '\d+.\d+'
16+
- '\d+.x'
17+
tags:
18+
- 'v?\d+.\d+.\d+'
19+
- 'v?\d+.\d+'
1320
workflow_call:
1421
inputs:
1522
strict:
@@ -44,6 +51,39 @@ permissions:
4451
pull-requests: read
4552

4653
jobs:
54+
match:
55+
if: github.event.repository.fork == false # Skip running the job on the fork itself (It still runs on PRs on the upstream from forks)
56+
concurrency:
57+
group: ${{ github.workflow }}-${{ github.event.pull_request.head.ref || github.ref }}
58+
cancel-in-progress: ${{ startsWith(github.event_name, 'pull_request') }}
59+
runs-on: ubuntu-latest
60+
outputs:
61+
content-source-match: ${{ steps.event-check.outputs.content-source-match != '' && steps.event-check.outputs.content-source-match || steps.match.outputs.content-source-match }}
62+
content-source-name: ${{ steps.event-check.outputs.content-source-name != '' && steps.event-check.outputs.content-source-name || steps.match.outputs.content-source-name }}
63+
steps:
64+
- name: Not a push event
65+
id: event-check
66+
if: contains(fromJSON('["merge_group", "pull_request", "pull_request_target"]'), github.event_name)
67+
# ensure we emit static output to simplify our checks in the build step
68+
run: |
69+
echo "content-source-match=true" >> $GITHUB_OUTPUT
70+
echo "content-source-name=next" >> $GITHUB_OUTPUT
71+
- name: Match for push events
72+
id: match
73+
if: contains(fromJSON('["push"]'), github.event_name)
74+
uses: elastic/docs-builder/actions/assembler-match@main
75+
with:
76+
ref_name: ${{ github.ref_name }}
77+
repository: ${{ github.repository }}
78+
- name: Debug
79+
if: contains(fromJSON('["merge_group", "pull_request", "pull_request_target"]'), github.event_name)
80+
run: |
81+
echo "Non sensitive data, echo'ing here temporarily to validate this job before connecting it further into the build job"
82+
echo "content-source-match=${{ steps.event-check.outputs.content-source-match != '' && steps.event-check.outputs.content-source-match || steps.match.outputs.content-source-match }}"
83+
echo "content-source-name=${{ steps.event-check.outputs.content-source-name != '' && steps.event-check.outputs.content-source-name || steps.match.outputs.content-source-name }}"
84+
echo "ref=${{ github.ref_name }}"
85+
echo "repo=${{ github.repository }}"
86+
4787
build:
4888
if: github.event.repository.fork == false # Skip running the job on the fork itself (It still runs on PRs on the upstream from forks)
4989
concurrency:
@@ -52,6 +92,7 @@ jobs:
5292
runs-on: ubuntu-latest
5393
env:
5494
GITHUB_PR_REF_NAME: ${{ github.event.pull_request.head.ref }}
95+
needs: [ match ]
5596
steps:
5697

5798
- name: Checkout

docs-builder.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tooling", "tooling", "{73AB
8989
EndProject
9090
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "authoring", "authoring", "{059E787F-85C1-43BE-9DD6-CE319E106383}"
9191
EndProject
92-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assembler-filter", "assembler-filter", "{FB1C1954-D8E2-4745-BA62-04DD82FB4792}"
92+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assembler-match", "assembler-match", "{FB1C1954-D8E2-4745-BA62-04DD82FB4792}"
9393
ProjectSection(SolutionItems) = preProject
94-
actions\assembler-filter\action.yml = actions\assembler-filter\action.yml
94+
actions\assembler-match\action.yml = actions\assembler-match\action.yml
9595
EndProjectSection
9696
EndProject
9797
Global

src/tooling/docs-assembler/AssembleSources.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private AssembleSources(AssembleContext assembleContext, Checkout[] checkouts)
6565
UriResolver = new PublishEnvironmentUriResolver(TocTopLevelMappings, assembleContext.Environment);
6666
var crossLinkResolver = new CrossLinkResolver(crossLinkFetcher, UriResolver);
6767
AssembleSets = checkouts
68-
.Where(c => !c.Repository.Skip)
68+
.Where(c => c.Repository is { Skip: false })
6969
.Select(c => new AssemblerDocumentationSet(NullLoggerFactory.Instance, assembleContext, c, crossLinkResolver, TreeCollector))
7070
.ToDictionary(s => s.Checkout.Repository.Name, s => s)
7171
.ToFrozenDictionary();

src/tooling/docs-assembler/Sourcing/RepositorySourcesFetcher.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ private bool TryUpdateSource(string name, string branch, string relativePath, ID
142142
return true;
143143
}
144144

145-
private string CheckoutFromScratch(Repository repository, string name, string branch, string relativePath,
146-
IDirectoryInfo checkoutFolder)
145+
private string CheckoutFromScratch(Repository repository, string name, string branch, string relativePath, IDirectoryInfo checkoutFolder)
147146
{
148147
_logger.LogInformation("Checkout: {Name}\t{Branch}\t{RelativePath}", name, branch, relativePath);
149148
switch (repository.CheckoutStrategy)

src/tooling/docs-assembler/assembler.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,5 @@ references:
101101
opentelemetry:
102102
search-ui:
103103
integration-docs:
104+
docs-builder:
105+
skip: true

0 commit comments

Comments
 (0)