diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index 8e867b2d3..ac37d700f 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,61 @@ 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 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 allFiles = 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 +311,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 diff --git a/actions/diff-validate/action.yml b/actions/diff-validate/action.yml index cd655efd7..e3b7fe159 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" 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: