From ed6dad5dee1173bb3a35fbc451642501482c4bf2 Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Thu, 7 Aug 2025 16:30:12 -0300 Subject: [PATCH 1/6] 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 2/6] 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 3/6] 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 4/6] 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 52f7a71d5d4e6278b5671a580ab1dd0a3b43fadb Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Mon, 11 Aug 2025 18:35:43 -0300 Subject: [PATCH 5/6] Adjust diff-validate action --- 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..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@main - with: - command: "diff validate" + using: 'docker' + image: "docker://ghcr.io/elastic/docs-builder:edge" + args: + - "diff" + - "validate" \ No newline at end of file From c3bf5031602b601416d6809b3d4c6950c8a58cbb Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Mon, 11 Aug 2025 18:36:57 -0300 Subject: [PATCH 6/6] typo --- 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 56bfdc561..e3b7fe159 100644 --- a/actions/diff-validate/action.yml +++ b/actions/diff-validate/action.yml @@ -6,4 +6,4 @@ runs: image: "docker://ghcr.io/elastic/docs-builder:edge" args: - "diff" - - "validate" \ No newline at end of file + - "validate"