Skip to content

Commit 2002601

Browse files
[build] Enhance docs-fetch command
1 parent 19e9071 commit 2002601

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

.github/workflows/generate-changelog.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
ref: master
2121

2222
- name: Fetch changelog
23-
run: ./build.cmd docs-fetch --depth 1 --preview
23+
run: ./build.cmd docs-fetch --depth 1 --preview --force-clone
2424
env:
2525
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2626

@@ -32,4 +32,4 @@ jobs:
3232
FOLDER: docs/_changelog
3333
GIT_CONFIG_NAME: Andrey Akinshin
3434
GIT_CONFIG_EMAIL: [email protected]
35-
CLEAN: true
35+
CLEAN: true

build/BenchmarkDotNet.Build/Options/KnownOptions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ public static class KnownOptions
2929
Aliases = new[] { "-d" }
3030
};
3131

32+
public static readonly BoolOption ForceClone = new("--force-clone")
33+
{
34+
Description = "Forces re-cloning of the changelog repository, deleting any existing directory.",
35+
Aliases = new[] { "-f" }
36+
};
37+
3238
public static readonly BoolOption Help = new("--help")
3339
{
3440
Description = "Prints help information",

build/BenchmarkDotNet.Build/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,14 @@ public HelpInfo GetHelp()
172172
$"* Last changelog footer (if {KnownOptions.Stable.CommandLineName} is specified)\n" +
173173
$"* All changelog details in docs/_changelog\n" +
174174
$" (This dir is a cloned version of this repo from branch {Repo.ChangelogBranch})",
175-
Options = [KnownOptions.DocsPreview, KnownOptions.DocsDepth],
175+
Options = [KnownOptions.DocsPreview, KnownOptions.DocsDepth, KnownOptions.ForceClone],
176176
EnvironmentVariables = [EnvVar.GitHubToken],
177177
Examples =
178178
[
179179
new Example(Name)
180180
.WithArgument(KnownOptions.DocsDepth, "3")
181181
.WithArgument(KnownOptions.DocsPreview)
182+
.WithArgument(KnownOptions.ForceClone)
182183
]
183184
};
184185
}

build/BenchmarkDotNet.Build/Runners/Changelog/ChangelogBuilder.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class ChangelogBuilder
1717
private readonly BuildContext context;
1818
private readonly bool preview;
1919
private readonly string depth;
20+
private readonly bool forceClone;
2021

2122
/// <summary>
2223
/// Directory with original changelog part files from branch 'docs-changelog'
@@ -33,6 +34,7 @@ public ChangelogBuilder(BuildContext context)
3334
this.context = context;
3435
preview = KnownOptions.DocsPreview.Resolve(context);
3536
depth = KnownOptions.DocsDepth.Resolve(context);
37+
forceClone = KnownOptions.ForceClone.Resolve(context);
3638

3739
var docsDirectory = context.RootDirectory.Combine("docs");
3840
SrcDirectory = docsDirectory.Combine("_changelog");
@@ -43,7 +45,7 @@ public void Fetch()
4345
{
4446
EnvVar.GitHubToken.AssertHasValue();
4547

46-
EnsureSrcDirectoryExist();
48+
EnsureSrcDirectoryExist(forceClone);
4749

4850
var history = context.VersionHistory;
4951
var stableVersionCount = history.StableVersions.Length;
@@ -224,14 +226,31 @@ private void GenerateToc()
224226
context.GenerateFile(DocfxDirectory.CombineWithFilePath("toc.yml"), content);
225227
}
226228

227-
private void EnsureSrcDirectoryExist(bool forceClean = false)
229+
private void EnsureSrcDirectoryExist(bool forceClone = false)
228230
{
229-
if (context.DirectoryExists(SrcDirectory) && forceClean)
231+
void Log(string message) => context.Information($"[Changelog] {message}");
232+
233+
Log($"Preparing git sub-repository for changelog branch '{Repo.ChangelogBranch}'. " +
234+
$"Target directory: '{SrcDirectory}'.");
235+
if (context.DirectoryExists(SrcDirectory) && forceClone)
236+
{
237+
Log($"Directory '{SrcDirectory}' already exists and forceClean is specified. " +
238+
$"Deleting the current directory...");
230239
context.DeleteDirectory(
231240
SrcDirectory,
232241
new DeleteDirectorySettings { Force = true, Recursive = true });
242+
Log($"Directory '{SrcDirectory}' deleted successfully.");
243+
}
233244

234245
if (!context.DirectoryExists(SrcDirectory))
246+
{
247+
Log($"Cloning branch '{Repo.ChangelogBranch}' from '{Repo.HttpsGitUrl}' to '{SrcDirectory}'.");
235248
context.GitRunner.Clone(SrcDirectory, Repo.HttpsGitUrl, Repo.ChangelogBranch);
249+
Log($"Clone completed: '{Repo.ChangelogBranch}' -> '{SrcDirectory}'.");
250+
}
251+
else
252+
{
253+
Log($"Directory '{SrcDirectory}' already exists. Skipping clone.");
254+
}
236255
}
237256
}

0 commit comments

Comments
 (0)