From ed6dad5dee1173bb3a35fbc451642501482c4bf2 Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Thu, 7 Aug 2025 16:30:12 -0300 Subject: [PATCH 01/12] Use github-scripts to assess file changes and use diff-validate on preview-builds for other repos --- .github/workflows/preview-build.yml | 79 +++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index 8e867b2d3..d38165946 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -117,10 +117,10 @@ jobs: outputs: any_modified: ${{ steps.check-files.outputs.any_modified }} all_changed_files: ${{ steps.check-files.outputs.all_changed_files }} - added_files: ${{ steps.check-files.outputs.added_files }} - modified_files: ${{ steps.check-files.outputs.modified_files }} - deleted_files: ${{ steps.check-files.outputs.deleted_files }} - renamed_files: ${{ steps.check-files.outputs.renamed_files }} + added_files: ${{ steps.check-modified-file-detail.outputs.added_files }} + modified_files: ${{ steps.check-modified-file-detail.outputs.modified_files }} + deleted_files: ${{ steps.check-modified-file-detail.outputs.deleted_files }} + renamed_files: ${{ steps.check-modified-file-detail.outputs.renamed_files }} steps: - name: Checkout if: contains(fromJSON('["push", "merge_group", "workflow_dispatch"]'), github.event_name) @@ -139,6 +139,62 @@ jobs: .github/** README.md + - name: Get modified file detail + if: contains(fromJSON('["merge_group", "pull_request", "pull_request_target"]'), github.event_name) + id: check-modified-file-detail + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + env: + PATH_PATTERN: "${{ inputs.path-pattern != '' && inputs.path-pattern || '**' }}" + IGNORE_PATTERNS: | + ${{ inputs.path-pattern-ignore }} + .github/** + README.md + with: + script: | + const glob = require('@actions/glob'); + const pathPattern = process.env.PATH_PATTERN; + const ignorePatterns = process.env.IGNORE_PATTERNS; + const ignoreGlobber = await glob.create(ignorePatterns); + const ignoredPaths = new Set(await ignoreGlobber.glob()); + + const { owner, repo } = context.repo; + const pull_number = context.payload.pull_request.number; + + const files = await github.paginate(github.rest.pulls.listFiles, { + owner, + repo, + pull_number, + }); + + const filteredFiles = allFiles.filter(file => !ignoredPaths.has(file.filename)); + + const added = []; + const modified = []; + const deleted = []; + const renamed = []; + + for (const file of filteredFiles) { + switch (file.status) { + case 'added': + added.push(file.filename); + break; + case 'modified': + modified.push(file.filename); + break; + case 'removed': + deleted.push(file.filename); + break; + case 'renamed': + renamed.push(`${file.previous_filename}:${file.filename}`); + break; + } + } + + core.setOutput('added_files', added.join(' ')); + core.setOutput('modified_files', modified.join(' ')); + core.setOutput('deleted_files', deleted.join(' ')); + core.setOutput('renamed_files', renamed.join(' ')); + build: if: github.event.repository.fork == false # Skip running the job on the fork itself (It still runs on PRs on the upstream from forks) runs-on: ubuntu-latest @@ -256,6 +312,21 @@ jobs: run: | dotnet run --project src/tooling/docs-builder -- diff validate + - name: 'Validate redirect rules' + if: > + env.MATCH == 'true' + && ( + github.repository != 'elastic/docs-builder' + && ( + steps.deployment.outputs.result + || ( + needs.check.outputs.any_modified == 'true' + && github.event_name == 'merge_group' + ) + ) + ) + uses: elastic/docs-builder/actions/diff-validate@main + # we run our artifact directly, please use the prebuild # elastic/docs-builder@main GitHub Action for all other repositories! - name: Build documentation From 5dcba0d3b3591c2dd3174ffef79db8067eb8a926 Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Thu, 7 Aug 2025 16:35:07 -0300 Subject: [PATCH 02/12] Remove redundant glob declaration --- .github/workflows/preview-build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index d38165946..9b5f322c2 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -151,7 +151,6 @@ jobs: README.md with: script: | - const glob = require('@actions/glob'); const pathPattern = process.env.PATH_PATTERN; const ignorePatterns = process.env.IGNORE_PATTERNS; const ignoreGlobber = await glob.create(ignorePatterns); From d6b219bcd868627dbcf7144e81eca42958b22af8 Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Thu, 7 Aug 2025 16:36:45 -0300 Subject: [PATCH 03/12] Typo --- .github/workflows/preview-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index 9b5f322c2..ac37d700f 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -159,7 +159,7 @@ jobs: const { owner, repo } = context.repo; const pull_number = context.payload.pull_request.number; - const files = await github.paginate(github.rest.pulls.listFiles, { + const allFiles = await github.paginate(github.rest.pulls.listFiles, { owner, repo, pull_number, From 99963dcb8dbce16349ad21dcb757c4ceedc67c31 Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Thu, 7 Aug 2025 16:49:44 -0300 Subject: [PATCH 04/12] Add note regarding validation in docs --- docs/contribute/redirects.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/contribute/redirects.md b/docs/contribute/redirects.md index 086d3a811..a0bcaa021 100644 --- a/docs/contribute/redirects.md +++ b/docs/contribute/redirects.md @@ -16,7 +16,11 @@ For API redirects, consult with the documentation engineering team on Slack (#el For elastic.co/guide redirects, open a [web team request](http://ela.st/web-request). -## File location. +## Validation + +Running `docs-builder diff validate` will give you feedback on whether all necessary redirect rules are in place after your changes. It will also run on pull requests. + +## File location Redirects are configured at the content set-level. The configuration file should be located next to your `docset.yml` file: From 708da6628016afce21e56782e073ec14c2313164 Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Mon, 11 Aug 2025 17:17:47 -0300 Subject: [PATCH 05/12] do not merge: should not complain of missing env --- .github/workflows/preview-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index ac37d700f..9b2a9bb24 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -315,7 +315,7 @@ jobs: if: > env.MATCH == 'true' && ( - github.repository != 'elastic/docs-builder' + github.repository == 'elastic/docs-builder' && ( steps.deployment.outputs.result || ( From 54a5c8c739b27f92b127f0262057230c432adf03 Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Mon, 11 Aug 2025 17:33:27 -0300 Subject: [PATCH 06/12] oh --- actions/diff-validate/action.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/actions/diff-validate/action.yml b/actions/diff-validate/action.yml index cd655efd7..5e277aa63 100644 --- a/actions/diff-validate/action.yml +++ b/actions/diff-validate/action.yml @@ -2,9 +2,8 @@ name: 'Validate Redirect Rules' description: 'Validates consistency of the documentation changes in relation to redirect rules' runs: - using: "composite" - steps: - - name: Validate Redirect Rules - uses: elastic/docs-builder@main - with: - command: "diff validate" + using: 'docker' + image: "docker://ghcr.io/elastic/docs-builder:edge" + args: + - "diff" + - "validate" From 2429a73dc38f7788430135c8eb17f8885dc95447 Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Mon, 11 Aug 2025 18:08:18 -0300 Subject: [PATCH 07/12] send command to docs-builder --- src/tooling/docs-builder/Program.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/tooling/docs-builder/Program.cs b/src/tooling/docs-builder/Program.cs index ddef08cd4..e0e64c494 100644 --- a/src/tooling/docs-builder/Program.cs +++ b/src/tooling/docs-builder/Program.cs @@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis; using Actions.Core.Extensions; +using Actions.Core.Services; using ConsoleAppFramework; using Documentation.Builder.Cli; using Elastic.Documentation.Diagnostics; @@ -35,6 +36,11 @@ app.Add("inbound-links"); app.Add("diff"); +var githubActions = ConsoleApp.ServiceProvider!.GetService(); +var command = githubActions?.GetInput("COMMAND"); +if (!string.IsNullOrEmpty(command)) + args = command.Split(' '); + await app.RunAsync(args).ConfigureAwait(false); From fe960e87225f7e605405924384c8cf105fbf45d6 Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Mon, 11 Aug 2025 18:13:32 -0300 Subject: [PATCH 08/12] Sending commands via action --- action.yml | 3 +++ actions/diff-validate/action.yml | 11 ++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/action.yml b/action.yml index c19381672..2d72c3efb 100644 --- a/action.yml +++ b/action.yml @@ -15,6 +15,9 @@ inputs: metadata-only: description: 'Only generate documentation metadata files' required: false + command: + description: 'The builder command to run' + required: false outputs: landing-page-path: description: 'Path to the landing page of the documentation' diff --git a/actions/diff-validate/action.yml b/actions/diff-validate/action.yml index 5e277aa63..f0e9c2d47 100644 --- a/actions/diff-validate/action.yml +++ b/actions/diff-validate/action.yml @@ -2,8 +2,9 @@ name: 'Validate Redirect Rules' description: 'Validates consistency of the documentation changes in relation to redirect rules' runs: - using: 'docker' - image: "docker://ghcr.io/elastic/docs-builder:edge" - args: - - "diff" - - "validate" + using: "composite" + steps: + - name: Validate Redirect Rules + uses: elastic/docs-builder@main + with: + command: "diff validate" \ No newline at end of file From 1abae527f3baace1835db704c06a2ef59e218fcc Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Mon, 11 Aug 2025 18:14:13 -0300 Subject: [PATCH 09/12] fix --- actions/diff-validate/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/diff-validate/action.yml b/actions/diff-validate/action.yml index f0e9c2d47..cd655efd7 100644 --- a/actions/diff-validate/action.yml +++ b/actions/diff-validate/action.yml @@ -7,4 +7,4 @@ runs: - name: Validate Redirect Rules uses: elastic/docs-builder@main with: - command: "diff validate" \ No newline at end of file + command: "diff validate" From 27e026c3484548b06626d057cdcdeb855caa45ba Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Mon, 11 Aug 2025 18:18:38 -0300 Subject: [PATCH 10/12] testing --- .github/workflows/preview-build.yml | 2 +- actions/diff-validate/action.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index 9b2a9bb24..1cf644f91 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -324,7 +324,7 @@ jobs: ) ) ) - uses: elastic/docs-builder/actions/diff-validate@main + uses: elastic/docs-builder/actions/diff-validate@fix/diff-validate-ci-double-check # we run our artifact directly, please use the prebuild # elastic/docs-builder@main GitHub Action for all other repositories! diff --git a/actions/diff-validate/action.yml b/actions/diff-validate/action.yml index cd655efd7..7cfae9b26 100644 --- a/actions/diff-validate/action.yml +++ b/actions/diff-validate/action.yml @@ -5,6 +5,6 @@ runs: using: "composite" steps: - name: Validate Redirect Rules - uses: elastic/docs-builder@main + uses: elastic/docs-builder@fix/diff-validate-ci-double-check with: command: "diff validate" From e9f4a63dda615d83ec19a701140860bdf13be6ee Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Mon, 11 Aug 2025 18:23:39 -0300 Subject: [PATCH 11/12] testing --- src/tooling/docs-builder/Program.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tooling/docs-builder/Program.cs b/src/tooling/docs-builder/Program.cs index e0e64c494..78ced529c 100644 --- a/src/tooling/docs-builder/Program.cs +++ b/src/tooling/docs-builder/Program.cs @@ -38,9 +38,11 @@ var githubActions = ConsoleApp.ServiceProvider!.GetService(); var command = githubActions?.GetInput("COMMAND"); + if (!string.IsNullOrEmpty(command)) args = command.Split(' '); - +Console.WriteLine(args); +Console.WriteLine(command); await app.RunAsync(args).ConfigureAwait(false); From e2e8637ab615cc0c4c32afb4582792c22591616f Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Mon, 11 Aug 2025 18:28:11 -0300 Subject: [PATCH 12/12] testing --- action.yml | 3 --- actions/diff-validate/action.yml | 11 +++++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/action.yml b/action.yml index 2d72c3efb..c19381672 100644 --- a/action.yml +++ b/action.yml @@ -15,9 +15,6 @@ inputs: metadata-only: description: 'Only generate documentation metadata files' required: false - command: - description: 'The builder command to run' - required: false outputs: landing-page-path: description: 'Path to the landing page of the documentation' diff --git a/actions/diff-validate/action.yml b/actions/diff-validate/action.yml index 7cfae9b26..56bfdc561 100644 --- a/actions/diff-validate/action.yml +++ b/actions/diff-validate/action.yml @@ -2,9 +2,8 @@ name: 'Validate Redirect Rules' description: 'Validates consistency of the documentation changes in relation to redirect rules' runs: - using: "composite" - steps: - - name: Validate Redirect Rules - uses: elastic/docs-builder@fix/diff-validate-ci-double-check - with: - command: "diff validate" + using: 'docker' + image: "docker://ghcr.io/elastic/docs-builder:edge" + args: + - "diff" + - "validate" \ No newline at end of file