Skip to content

[Demo, do not merge] CI Redirect Messages Demo #1698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions .github/workflows/preview-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -138,6 +138,48 @@ jobs:
${{ inputs.path-pattern-ignore != '' && inputs.path-pattern-ignore || '' }}
.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
with:
script: |
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 added = [];
const modified = [];
const deleted = [];
const renamed = [];
const all_changed = [];

for (const file of files) {
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)
Expand Down
3 changes: 1 addition & 2 deletions docs/_docset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ toc:
- file: index.md
- file: locally.md
- file: on-the-web.md
- file: move.md
- file: redirects.md
- file: move-new.md
- file: cumulative-docs.md
- file: branching-strategy.md
- file: add-repo.md
Expand Down
File renamed without changes.
165 changes: 0 additions & 165 deletions docs/contribute/redirects.md

This file was deleted.

10 changes: 4 additions & 6 deletions src/tooling/docs-builder/Cli/DiffCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,18 @@ public async Task<int> ValidateRedirects([Argument] string? path = null, Cancel
}

IRepositoryTracker tracker = runningOnCi ? new IntegrationGitRepositoryTracker(path) : new LocalGitRepositoryTracker(collector, root, path);
var changed = tracker.GetChangedFiles() as GitChange[] ?? [];
var changed = tracker.GetChangedFiles();

if (changed.Length > 0)
_log.LogInformation($"Found {changed.Length} changes to files related to documentation in the current branch.");
if (changed.Any())
_log.LogInformation($"Found {changed.Count()} changes to files related to documentation in the current branch.");

foreach (var notFound in changed.DistinctBy(c => c.FilePath).Where(c => c.ChangeType is GitChangeType.Deleted or GitChangeType.Renamed
&& !redirects.ContainsKey(c is RenamedGitChange renamed ? renamed.OldFilePath : c.FilePath)))
{
if (notFound is RenamedGitChange renamed)
{
collector.EmitError(redirectFileInfo.Name,
runningOnCi
? $"A file was renamed to '{renamed.NewFilePath}' but it has no redirect configuration set."
: $"File '{renamed.OldFilePath}' was renamed to '{renamed.NewFilePath}' but it has no redirect configuration set.");
$"File '{renamed.OldFilePath}' was renamed to '{renamed.NewFilePath}' but it has no redirect configuration set.");
}
else if (notFound.ChangeType is GitChangeType.Deleted)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using Microsoft.Extensions.Logging;

namespace Documentation.Builder.Tracking;

public class IntegrationGitRepositoryTracker(string lookupPath) : IRepositoryTracker
Expand Down Expand Up @@ -33,8 +35,12 @@ public IEnumerable<GitChange> GetChangedFiles()
var renamedFiles = Environment.GetEnvironmentVariable("RENAMED_FILES");
if (!string.IsNullOrEmpty(renamedFiles))
{
foreach (var file in renamedFiles.Split(' ', StringSplitOptions.RemoveEmptyEntries).Where(f => f.StartsWith(LookupPath)))
yield return new RenamedGitChange(string.Empty, file, GitChangeType.Renamed);
foreach (var pair in renamedFiles.Split(' ', StringSplitOptions.RemoveEmptyEntries).Where(f => f.StartsWith(LookupPath)))
{
var parts = pair.Split(':');
if (parts.Length == 2)
yield return new RenamedGitChange(parts[0], parts[1], GitChangeType.Renamed);
}
}
}
}
Loading