From dec7afc2126028a61704a45589dad2791005a3a4 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 18 Mar 2025 11:52:55 +0100 Subject: [PATCH 1/3] Revert "Remove tj-actions usage, eventhough we had it pinned as gitref (#753)" This reverts commit 6eff5ea61d8b6c3c0d9a0562407a8e83e6fa115f. --- .github/workflows/preview-build.yml | 15 ++++++++---- .../Sourcing/RepositorySourcesFetcher.cs | 24 +++++++++---------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.yml index e477c5a72..4737d580c 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -57,8 +57,15 @@ jobs: with: ref: ${{ github.event.pull_request.head.sha || github.ref }} + - name: Get changed files + if: contains(fromJSON('["merge_group", "pull_request", "pull_request_target"]'), github.event_name) + id: check-files + uses: tj-actions/changed-files@d6e91a2266cdb9d62096cebf1e8546899c6aa18f # v45.0.6 + with: + files: ${{ inputs.path-pattern != '' && inputs.path-pattern || '**' }} + - name: Checkout - if: startsWith(github.event_name, 'pull_request') + if: startsWith(github.event_name, 'pull_request') && steps.check-files.outputs.any_modified == 'true' uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha || github.ref }} @@ -70,7 +77,7 @@ jobs: tool-cache: false - name: Create Deployment - if: github.event_name == 'push' || startsWith(github.event_name, 'pull_request') + if: github.event_name == 'push' || (steps.check-files.outputs.any_modified == 'true' && startsWith(github.event_name, 'pull_request')) uses: actions/github-script@v7 id: deployment env: @@ -137,7 +144,7 @@ jobs: dotnet run --project src/docs-builder -- --strict --path-prefix "${PATH_PREFIX}" - name: Build documentation - if: github.repository != 'elastic/docs-builder' && (steps.deployment.outputs.result || github.event_name == 'merge_group') + if: github.repository != 'elastic/docs-builder' && (steps.deployment.outputs.result || (steps.check-files.outputs.any_modified == 'true' && github.event_name == 'merge_group')) uses: elastic/docs-builder@main id: docs-build continue-on-error: ${{ fromJSON(inputs.continue-on-error != '' && inputs.continue-on-error || 'false') }} @@ -147,7 +154,7 @@ jobs: metadata-only: ${{ fromJSON(inputs.metadata-only != '' && inputs.metadata-only || 'true') }} - name: 'Validate Inbound Links' - if: ${{ !cancelled() && steps.docs-build.outputs.skip != 'true' && (steps.deployment.outputs.result || github.event_name == 'merge_group') }} + if: ${{ !cancelled() && steps.docs-build.outputs.skip != 'true' && (steps.deployment.outputs.result || (steps.check-files.outputs.any_modified == 'true' && github.event_name == 'merge_group')) }} uses: elastic/docs-builder/actions/validate-inbound-local@main - uses: elastic/docs-builder/.github/actions/aws-auth@main diff --git a/src/docs-assembler/Sourcing/RepositorySourcesFetcher.cs b/src/docs-assembler/Sourcing/RepositorySourcesFetcher.cs index 80aa4b515..f7fc5d827 100644 --- a/src/docs-assembler/Sourcing/RepositorySourcesFetcher.cs +++ b/src/docs-assembler/Sourcing/RepositorySourcesFetcher.cs @@ -89,7 +89,7 @@ private Checkout CloneOrUpdateRepository(Repository repository, string name, Con { _logger.LogInformation("Pull: {Name}\t{Repository}\t{RelativePath}", name, repository, relativePath); // --allow-unrelated-histories due to shallow clones not finding a common ancestor - ExecIn(checkoutFolder, "git", "pull", "--depth", "1", "--allow-unrelated-histories", "--no-ff"); + ExecIn(name, checkoutFolder, "git", "pull", "--depth", "1", "--allow-unrelated-histories", "--no-ff"); head = Capture(checkoutFolder, "git", "rev-parse", "HEAD"); } else @@ -97,20 +97,20 @@ private Checkout CloneOrUpdateRepository(Repository repository, string name, Con _logger.LogInformation("Checkout: {Name}\t{Repository}\t{RelativePath}", name, repository, relativePath); if (repository.CheckoutStrategy == "full") { - Exec("git", "clone", repository.Origin, checkoutFolder.FullName, + Exec(name, "git", "clone", repository.Origin, checkoutFolder.FullName, "--depth", "1", "--single-branch", "--branch", repository.CurrentBranch ); } else if (repository.CheckoutStrategy == "partial") { - Exec( + Exec(name, "git", "clone", "--filter=blob:none", "--no-checkout", repository.Origin, checkoutFolder.FullName ); - ExecIn(checkoutFolder, "git", "sparse-checkout", "set", "--cone"); - ExecIn(checkoutFolder, "git", "checkout", repository.CurrentBranch); - ExecIn(checkoutFolder, "git", "sparse-checkout", "set", "docs"); + ExecIn(name, checkoutFolder, "git", "sparse-checkout", "set", "--cone"); + ExecIn(name, checkoutFolder, "git", "checkout", repository.CurrentBranch); + ExecIn(name, checkoutFolder, "git", "sparse-checkout", "set", "docs"); head = Capture(checkoutFolder, "git", "rev-parse", "HEAD"); } } @@ -125,17 +125,17 @@ private Checkout CloneOrUpdateRepository(Repository repository, string name, Con }; } - private void Exec(string binary, params string[] args) => ExecIn(null, binary, args); + private void Exec(string name, string binary, params string[] args) => ExecIn(name, null, binary, args); - private void ExecIn(IDirectoryInfo? workingDirectory, string binary, params string[] args) + private void ExecIn(string name, IDirectoryInfo? workingDirectory, string binary, params string[] args) { - var arguments = new ExecArguments(binary, args) + var arguments = new StartArguments(binary, args) { WorkingDirectory = workingDirectory?.FullName }; - var result = Proc.Exec(arguments); - if (result != 0) - context.Collector.EmitError("", $"Exit code: {result} while executing {binary} {string.Join(" ", args)} in {workingDirectory}"); + var result = Proc.StartRedirected(arguments, new ConsoleLineHandler(_logger, name)); + if (result.ExitCode != 0) + context.Collector.EmitError("", $"Exit code: {result.ExitCode} while executing {binary} {string.Join(" ", args)} in {workingDirectory}"); } private string Capture(IDirectoryInfo? workingDirectory, string binary, params string[] args) From 9698a5023edef5b1edbadc7a71ef3e63735fa8a0 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 18 Mar 2025 11:54:12 +0100 Subject: [PATCH 2/3] Don't revert changes here --- .../Sourcing/RepositorySourcesFetcher.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/docs-assembler/Sourcing/RepositorySourcesFetcher.cs b/src/docs-assembler/Sourcing/RepositorySourcesFetcher.cs index f7fc5d827..80aa4b515 100644 --- a/src/docs-assembler/Sourcing/RepositorySourcesFetcher.cs +++ b/src/docs-assembler/Sourcing/RepositorySourcesFetcher.cs @@ -89,7 +89,7 @@ private Checkout CloneOrUpdateRepository(Repository repository, string name, Con { _logger.LogInformation("Pull: {Name}\t{Repository}\t{RelativePath}", name, repository, relativePath); // --allow-unrelated-histories due to shallow clones not finding a common ancestor - ExecIn(name, checkoutFolder, "git", "pull", "--depth", "1", "--allow-unrelated-histories", "--no-ff"); + ExecIn(checkoutFolder, "git", "pull", "--depth", "1", "--allow-unrelated-histories", "--no-ff"); head = Capture(checkoutFolder, "git", "rev-parse", "HEAD"); } else @@ -97,20 +97,20 @@ private Checkout CloneOrUpdateRepository(Repository repository, string name, Con _logger.LogInformation("Checkout: {Name}\t{Repository}\t{RelativePath}", name, repository, relativePath); if (repository.CheckoutStrategy == "full") { - Exec(name, "git", "clone", repository.Origin, checkoutFolder.FullName, + Exec("git", "clone", repository.Origin, checkoutFolder.FullName, "--depth", "1", "--single-branch", "--branch", repository.CurrentBranch ); } else if (repository.CheckoutStrategy == "partial") { - Exec(name, + Exec( "git", "clone", "--filter=blob:none", "--no-checkout", repository.Origin, checkoutFolder.FullName ); - ExecIn(name, checkoutFolder, "git", "sparse-checkout", "set", "--cone"); - ExecIn(name, checkoutFolder, "git", "checkout", repository.CurrentBranch); - ExecIn(name, checkoutFolder, "git", "sparse-checkout", "set", "docs"); + ExecIn(checkoutFolder, "git", "sparse-checkout", "set", "--cone"); + ExecIn(checkoutFolder, "git", "checkout", repository.CurrentBranch); + ExecIn(checkoutFolder, "git", "sparse-checkout", "set", "docs"); head = Capture(checkoutFolder, "git", "rev-parse", "HEAD"); } } @@ -125,17 +125,17 @@ private Checkout CloneOrUpdateRepository(Repository repository, string name, Con }; } - private void Exec(string name, string binary, params string[] args) => ExecIn(name, null, binary, args); + private void Exec(string binary, params string[] args) => ExecIn(null, binary, args); - private void ExecIn(string name, IDirectoryInfo? workingDirectory, string binary, params string[] args) + private void ExecIn(IDirectoryInfo? workingDirectory, string binary, params string[] args) { - var arguments = new StartArguments(binary, args) + var arguments = new ExecArguments(binary, args) { WorkingDirectory = workingDirectory?.FullName }; - var result = Proc.StartRedirected(arguments, new ConsoleLineHandler(_logger, name)); - if (result.ExitCode != 0) - context.Collector.EmitError("", $"Exit code: {result.ExitCode} while executing {binary} {string.Join(" ", args)} in {workingDirectory}"); + var result = Proc.Exec(arguments); + if (result != 0) + context.Collector.EmitError("", $"Exit code: {result} while executing {binary} {string.Join(" ", args)} in {workingDirectory}"); } private string Capture(IDirectoryInfo? workingDirectory, string binary, params string[] args) From 9e5a40d1b22f18195759b493acaa527e71abf849 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Tue, 18 Mar 2025 11:55:45 +0100 Subject: [PATCH 3/3] Use latest commit --- .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 4737d580c..b4ae43baa 100644 --- a/.github/workflows/preview-build.yml +++ b/.github/workflows/preview-build.yml @@ -60,7 +60,7 @@ jobs: - name: Get changed files if: contains(fromJSON('["merge_group", "pull_request", "pull_request_target"]'), github.event_name) id: check-files - uses: tj-actions/changed-files@d6e91a2266cdb9d62096cebf1e8546899c6aa18f # v45.0.6 + uses: tj-actions/changed-files@2f7c5bfce28377bc069a65ba478de0a74aa0ca32 # v46.0.1 with: files: ${{ inputs.path-pattern != '' && inputs.path-pattern || '**' }}