Skip to content

Commit

Permalink
Merge pull request #8121 from dotnet/v3
Browse files Browse the repository at this point in the history
πŸš€πŸš€πŸš€
  • Loading branch information
AngryBerryMS authored Aug 3, 2022
2 parents 6b4d8ac + 7128b63 commit f5a62ad
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 16 deletions.
6 changes: 4 additions & 2 deletions azure-pipelines-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ jobs:
PULL_REQUEST_NUMBER : $(System.PullRequest.PullRequestNumber)
APPINSIGHTS_INSTRUMENTATIONKEY: 5226e0d0-086f-4cab-a491-1d00fde9eb09
MICROSOFT_GRAPH_CLIENT_CERTIFICATE: $(Docfx-MS-Graph-Client-Cert-PubDev)
OUTPUT_DETAILED_PR_COMMENT: $(output-detailed-pr-comment)

- job: WarmUp
timeoutInMinutes: 180
Expand Down Expand Up @@ -189,6 +190,7 @@ jobs:
AZURE_DEVOPS_TOKEN: $(vsoTestToken)
APPINSIGHTS_INSTRUMENTATIONKEY: 5226e0d0-086f-4cab-a491-1d00fde9eb09
PULL_REQUEST_NUMBER : $(System.PullRequest.PullRequestNumber)
OUTPUT_DETAILED_PR_COMMENT: $(output-detailed-pr-comment)

parameters:
- name: agents
Expand Down Expand Up @@ -231,8 +233,8 @@ parameters:
params: https://github.com/Azure/azure-docs-rest-apis --timeout 130 --error-level Warning
powerapps-docs-web-api-ref-pr:
params: https://github.com/MicrosoftDocs/powerapps-docs-web-api-ref-pr --timeout 25
# mc-docs-pr:
# params: https://github.com/MicrosoftDocs/mc-docs-pr --timeout 70
mc-docs-pr:
params: https://github.com/MicrosoftDocs/mc-docs-pr --timeout 70
dynamics365smb-devitpro:
params: https://github.com/MicrosoftDocs/dynamics365smb-devitpro --timeout 15
test:
Expand Down
20 changes: 13 additions & 7 deletions docs/specs/git.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@ outputs:
# Specify invalid author in YAML header should log warning
noDryRun: true
usePhysicalInput: true
inputs:
docs/index.md: |
---
author: invalid_user
---
# git-test
docfx.yml:
repos:
https://github.com/testowner/testrepo-with-invalid-user#main:
- files:
.openpublishing.publish.config.json: |
{
"docsets_to_publish": [ { "build_source_folder": "." } ]
}
docs/index.md: |
---
author: invalid_user
---
# git-test
docfx.yml:
cache:
github-users.json: |
{
Expand Down
3 changes: 3 additions & 0 deletions docs/specs/ops.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ outputs:
{ "files": [{ "redirect_url": "/" }] }
---
# document_id of files redirected to relative path
os: windows
repos:
https://github.com/ops/redirect-2:
- files:
Expand All @@ -165,6 +166,8 @@ repos:
outputs:
ce/basics/teams-integration.json: |
{ "document_id": "b1c6c9d3-40a8-a21d-98e8-a3cbf54eaeb4" }
.errors.log: |
{ "message_severity":"info","code":"dangling-redirection-files","message":"There are some dangling redirection files: .openpublishing.redirection.json, ce\\.openpublishing.redirection.json"}
---
# redirect_document_id is false
# document_id should be different
Expand Down
45 changes: 45 additions & 0 deletions docs/specs/redirection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1153,3 +1153,48 @@ outputs:
.errors.log: |
{"message_severity":"suggestion","code":"redirect-url-invalid","message":"Can't redirect document ID for redirected file 'original.md' because redirect URL 'folder/a' is invalid or is in a different docset. Specify a redirect_url in the same docset, or set redirect_document_id to false in .openpublishing.redirection.json.","file":"redirections.json"}
---
# dangling redirection files
os: windows
repos:
https://github.com/redirection/multiple-redirection-files:
- files:
.openpublishing.publish.config.json: |
{
"docsets_to_publish": [{"build_source_folder":"a"}],
"redirection_files": [
".openpublishing.redirection.test.json",
"a/.openpublishing.redirection.test.json"
],
}
a/docfx.yml:
.openpublishing.redirection.json: |
{
"redirections": [
{"source_path": "a.md", "redirect_url": "/aa"},
{"source_path": "b.md", "redirect_url": "/bb"}]
}
.openpublishing.redirection.test.json: |
{
"redirections": [{"source_path": "c.md", "redirect_url": "/cc"}]
}
a/.openpublishing.redirection.test.json: |
{
"redirections": [
{"source_path": "a.md", "redirect_url": "/aa"},
{"source_path": "b.md", "redirect_url": "/bb"}]
}
a/b/.openpublishing.redirection.json: |
{
"redirections": [
{"source_path": "a.md", "redirect_url": "/aa"},
{"source_path": "b.md", "redirect_url": "/bb"}]
}
a/b/.openpublishing.redirection.test.json: |
{
"redirections": [
{"source_path": "a.md", "redirect_url": "/aa"},
{"source_path": "b.md", "redirect_url": "/bb"}]
}
outputs:
.errors.log: |
{"message_severity":"info","code":"dangling-redirection-files","message":"There are some dangling redirection files: a\\b\\.openpublishing.redirection.json, a\\b\\.openpublishing.redirection.test.json"}
6 changes: 6 additions & 0 deletions src/docfx/Errors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ public static Error SourcePathConflict(SourceInfo<string> source)
/// Behavior: βœ”οΈ Message: βœ”οΈ
public static Error RedirectionPathSyntaxError(SourceInfo<string> source)
=> new(ErrorLevel.Warning, "redirection-path-syntax-error", $"Redirection path syntax is incorrect. 'source_path' should start without '/' and 'source_path_from_root' should start with '/'.", source);

/// <summary>
/// Check whether there are any dangling redirection files in a repository.
/// </summary>
public static Error DanglingRedirectionFiles(IEnumerable<string> danglingRedirectionFiles)
=> new(ErrorLevel.Info, "dangling-redirection-files", $"There are some dangling redirection files: {string.Join(", ", danglingRedirectionFiles)}");
}

public static class Toc
Expand Down
21 changes: 21 additions & 0 deletions src/docfx/build/redirection/RedirectionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal class RedirectionProvider
private readonly Package _docsetPackage;
private readonly Watch<(Dictionary<FilePath, string> urls, HashSet<PathString> paths, RedirectionItem[] items)> _redirects;
private readonly Watch<(Dictionary<FilePath, FilePath> renames, Dictionary<FilePath, (FilePath, SourceInfo?)> redirects)> _history;
private readonly HashSet<PathString> _autoScannedRedirectionFiles;

public IEnumerable<FilePath> Files => _redirects.Value.urls.Keys;

Expand All @@ -41,6 +42,7 @@ public RedirectionProvider(

_redirects = new(LoadRedirections);
_history = new(LoadHistory);
_autoScannedRedirectionFiles = AutoScanRedirectionFiles();
}

public bool TryGetValue(PathString file, [NotNullWhen(true)] out FilePath? actualPath)
Expand Down Expand Up @@ -158,6 +160,7 @@ private RedirectionItem[] LoadRedirectionModel()

foreach (var fullPath in ProbeRedirectionFiles())
{
_autoScannedRedirectionFiles.Remove(fullPath);
if (_docsetPackage.Exists(fullPath))
{
GenerateRedirectionRules(fullPath, results);
Expand All @@ -167,9 +170,16 @@ private RedirectionItem[] LoadRedirectionModel()

foreach (var fullPath in ProbeSubRedirectionFiles())
{
_autoScannedRedirectionFiles.Remove(fullPath);
GenerateRedirectionRules(fullPath, results);
}

if (_autoScannedRedirectionFiles.Count != 0)
{
_errors.Add(Errors.Redirection.DanglingRedirectionFiles(
_autoScannedRedirectionFiles.Select(file => Path.GetRelativePath(_buildOptions.Repository?.Path ?? ".", file))));
}

return results.OrderBy(item => item.RedirectUrl.Source).ToArray();
}

Expand Down Expand Up @@ -285,6 +295,17 @@ private IEnumerable<PathString> ProbeSubRedirectionFiles()
}
}

private HashSet<PathString> AutoScanRedirectionFiles()
{
var redirectionFilesSet = new HashSet<PathString>();
if (_buildOptions.Repository is not null)
{
var files = Directory.EnumerateFiles(_buildOptions.Repository.Path, "*.openpublishing.redirection*.json", SearchOption.AllDirectories);
redirectionFilesSet = files.Select(file => new PathString(file)).ToHashSet();
}
return redirectionFilesSet;
}

private (Dictionary<FilePath, FilePath>, Dictionary<FilePath, (FilePath, SourceInfo?)>) LoadHistory()
{
using (Progress.Start("Loading redirection history"))
Expand Down
2 changes: 2 additions & 0 deletions src/docfx/cli/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ internal class CommandLineOptions

public bool Force { get; init; }

public bool GitInit { get; init; }

public bool NoCache { get; init; }

public bool NoRestore { get; init; }
Expand Down
1 change: 1 addition & 0 deletions src/docfx/cli/Docfx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private static Command NewCommand()
new[] { "-o", "--output" }, "Output directory in which to place built artifacts."));
command.AddOption(new Option<bool>(
"--force", "Forces content to be generated even if it would change existing files."));
command.AddOption(new Option<bool>("--git-init", "Initialize the docset as a git directory."));
command.AddArgument(new Argument<string>("templateName", "Docset template name") { Arity = ArgumentArity.ZeroOrOne });
return command;
}
Expand Down
7 changes: 6 additions & 1 deletion src/docfx/cli/New.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ private static bool CreateFromTemplate(string templateName, CommandLineOptions o
}
else
{
Directory.CreateDirectory(Path.GetDirectoryName(targetFullPath) ?? ".");
var directory = Path.GetDirectoryName(targetFullPath) ?? ".";
Directory.CreateDirectory(directory);
if (options.GitInit)
{
GitUtility.Init(directory);
}
File.Copy(file, targetFullPath, overwrite: options.Force);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/docfx/docfx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.20.0" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.20.0" />
<PackageReference Include="Microsoft.ChakraCore" Version="1.11.24" />
<PackageReference Include="Microsoft.DocAsCode.ECMAHelper" Version="1.2.2013.68" />
<PackageReference Include="Microsoft.DocAsCode.ECMAHelper" Version="1.2.2031.72" />
<PackageReference Include="Microsoft.DocAsCode.MAML2Yaml.Lib" Version="1.1.2004.11" Aliases="maml" />
<PackageReference Include="Microsoft.Docs.MetadataService.Models" Version="0.3.6" />
<PackageReference Include="Microsoft.Graph" Version="4.25.0" />
Expand Down
12 changes: 9 additions & 3 deletions test/docfx.RegressionTest/RegressionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal static class RegressionTest
private const string TestDiskRoot = "D:/";

private static readonly string s_testDataRoot = Path.Join(TestDiskRoot, "docfx.TestData");
private static readonly bool s_outputDetailedPrComment = bool.TryParse(Environment.GetEnvironmentVariable("OUTPUT_DETAILED_PR_COMMENT"), out var flag) && flag;
private static readonly string? s_githubToken = Environment.GetEnvironmentVariable("DOCS_GITHUB_TOKEN");
private static readonly string? s_azureDevopsToken = Environment.GetEnvironmentVariable("AZURE_DEVOPS_TOKEN");
private static readonly string? s_buildReason = Environment.GetEnvironmentVariable("BUILD_REASON");
Expand Down Expand Up @@ -512,21 +513,26 @@ private static void SendPullRequestComments(RegressionTestResult testResult)
body.Append($", {testResult.PeakMemory / 1000 / 1000}MB");
body.Append(")</summary>\n\n");

if (!string.IsNullOrEmpty(testResult.CrashMessage))
if (s_outputDetailedPrComment && !string.IsNullOrEmpty(testResult.CrashMessage))
{
body.Append($"```\n{testResult.CrashMessage}\n\n```");
}

if (!string.IsNullOrEmpty(testResult.Diff))
if (s_outputDetailedPrComment && !string.IsNullOrEmpty(testResult.Diff))
{
body.Append($"```diff\n{testResult.Diff}\n\n```");
}

if (isTimeout && !string.IsNullOrEmpty(testResult.HotMethods))
if (s_outputDetailedPrComment && isTimeout && !string.IsNullOrEmpty(testResult.HotMethods))
{
body.Append($"```csharp\n{testResult.HotMethods}\n\n```");
}

if (!s_outputDetailedPrComment)
{
body.Append($"```\nView more details on Azure Pipelines.\n\n```");
}

body.Append("\n\n</details>");

if (int.TryParse(Environment.GetEnvironmentVariable("PULL_REQUEST_NUMBER") ?? "", out var prNumber))
Expand Down
4 changes: 4 additions & 0 deletions test/docfx.SpecTest/DocfxTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ private static (string docsetPath, string appDataPath, string outputPath, Dictio

TestUtility.CreateFiles(cachePath, spec.Cache, variables);
TestUtility.CreateFiles(statePath, spec.State, variables);
if (spec.Repos.Count == 0 && !GitUtility.IsGitRepository(docsetPath))
{
GitUtility.Init(docsetPath);
}
if (package is LocalPackage)
{
TestUtility.CreateFiles(docsetPath, spec.Inputs, variables);
Expand Down
4 changes: 2 additions & 2 deletions test/docfx.Test/cli/NewTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static void Create_Build_Docset(string templateName)
{
var path = Path.Combine("new-test", Guid.NewGuid().ToString("N"));

Assert.Equal(0, Docfx.Run(new[] { "new", templateName, "-o", path }));
Assert.Equal(0, Docfx.Run(new[] { "new", templateName, "--git-init", "-o", path }));
Assert.Equal(0, Docfx.Run(new[] { "build", path }));
}

Expand All @@ -35,7 +35,7 @@ public static void Create_Build_Serve_Docset(string templateName)
{
var path = Path.Combine("new-test", Guid.NewGuid().ToString("N"));

Assert.Equal(0, Docfx.Run(new[] { "new", templateName, "-o", path }));
Assert.Equal(0, Docfx.Run(new[] { "new", templateName, "--git-init", "-o", path }));
Assert.Equal(0, Docfx.Run(new[] { "build", path }));

var exception = new Exception();
Expand Down

0 comments on commit f5a62ad

Please sign in to comment.