Skip to content

Commit 91be63e

Browse files
committed
switched docs to running on Statiq
1 parent 008c482 commit 91be63e

22 files changed

+295
-18
lines changed

.build/statiq-docs.cake

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// DISABLE WYAM
3+
///////////////////////////////////////////////////////////////////////////////
4+
5+
BuildParameters.Tasks.PreviewDocumentationTask.WithCriteria(() => false, "Favor Statiq over Wyam");
6+
BuildParameters.Tasks.PublishDocumentationTask.WithCriteria(() => false, "Favor Statiq over Wyam");
7+
BuildParameters.Tasks.ForcePublishDocumentationTask.WithCriteria(() => false, "Favor Statiq over Wyam");
8+
9+
///////////////////////////////////////////////////////////////////////////////
10+
// TASK DEFINITIONS
11+
///////////////////////////////////////////////////////////////////////////////
12+
13+
// No Clean task, we re-use the one provided in Wyam.cake
14+
15+
BuildParameters.Tasks.PublishDocumentationTask = Task("Publish-StatiqDocs")
16+
.IsDependentOn("Clean-Documentation")
17+
.WithCriteria(() => BuildParameters.ShouldGenerateDocumentation, "Statiq documentation has been disabled")
18+
.WithCriteria(() => DirectoryExists(BuildParameters.WyamRootDirectoryPath), "Statiq documentation directory is missing")
19+
.Does(() => {
20+
// ensure submodules are in place
21+
var gitTool = Context.Tools.Resolve("git");
22+
if (gitTool == null)
23+
{
24+
gitTool = Context.Tools.Resolve("git.exe");
25+
}
26+
if (gitTool == null)
27+
{
28+
throw new FileNotFoundException("git/git.exe could not be found!");
29+
}
30+
31+
var exitCode = Context.StartProcess(
32+
gitTool,
33+
new ProcessSettings {
34+
Arguments = "submodule update --init --recursive",
35+
}
36+
);
37+
38+
// Check to see if any documentation has changed
39+
var sourceCommit = GitLogTip("./");
40+
Information("Source Commit Sha: {0}", sourceCommit.Sha);
41+
var filesChanged = GitDiff("./", sourceCommit.Sha);
42+
Information("Number of changed files: {0}", filesChanged.Count);
43+
var docFileChanged = false;
44+
45+
var wyamDocsFolderDirectoryName = BuildParameters.WyamRootDirectoryPath.GetDirectoryName();
46+
47+
var pathsToTestAgainst = new List<string>() {
48+
string.Format("{0}{1}", wyamDocsFolderDirectoryName, "/input/")
49+
};
50+
51+
if (BuildParameters.ShouldDocumentSourceFiles)
52+
{
53+
// BuildParameters.WyamSourceFiles can not be used - the wyam globs are different from globs in GetFiles().
54+
pathsToTestAgainst.Add(string.Format("{0}{1}", BuildParameters.SourceDirectoryPath.FullPath, '/'));
55+
}
56+
57+
Verbose("Comparing all file-changes to the following paths:");
58+
foreach(var p in pathsToTestAgainst)
59+
{
60+
Verbose(" - "+p);
61+
}
62+
63+
foreach (var file in filesChanged)
64+
{
65+
Verbose("Changed File OldPath: {0}, Path: {1}", file.OldPath, file.Path);
66+
if (pathsToTestAgainst.Any(x => file.OldPath.Contains(x) || file.Path.Contains(x)))
67+
{
68+
docFileChanged = true;
69+
break;
70+
}
71+
}
72+
73+
if (docFileChanged)
74+
{
75+
Information("Detected that documentation files have changed, so running Statiq...");
76+
77+
Statiq();
78+
PublishStatiqDocs();
79+
}
80+
else
81+
{
82+
Information("No documentation has changed, so no need to generate documentation");
83+
}
84+
}
85+
)
86+
.OnError(exception =>
87+
{
88+
Error(exception.Message);
89+
Information("Publish-StatiqDocs Task failed, but continuing with next Task...");
90+
publishingError = true;
91+
});
92+
93+
BuildParameters.Tasks.PreviewDocumentationTask = Task("Preview-StatiqDocs")
94+
.WithCriteria(() => DirectoryExists(BuildParameters.WyamRootDirectoryPath), "Statiq documentation directory is missing")
95+
.Does(() => {
96+
Statiq("preview");
97+
});
98+
99+
100+
BuildParameters.Tasks.ForcePublishDocumentationTask = Task("Force-Publish-StatiqDocs")
101+
.IsDependentOn("Clean-Documentation")
102+
.WithCriteria(() => DirectoryExists(BuildParameters.WyamRootDirectoryPath), "Statiq documentation directory is missing")
103+
.Does(() => {
104+
Statiq();
105+
PublishStatiqDocs();
106+
}
107+
);
108+
109+
public void PublishStatiqDocs()
110+
{
111+
var canPublishToGitHub =
112+
!string.IsNullOrEmpty(BuildParameters.Wyam.AccessToken) &&
113+
!string.IsNullOrEmpty(BuildParameters.Wyam.DeployBranch) &&
114+
!string.IsNullOrEmpty(BuildParameters.RepositoryOwner) &&
115+
!string.IsNullOrEmpty(BuildParameters.RepositoryName);
116+
117+
if (!canPublishToGitHub)
118+
{
119+
Warning("Unable to publish documentation, as not all Statiq configuration is present");
120+
return;
121+
}
122+
123+
Statiq("deploy");
124+
}
125+
126+
// TODO: Do we need Cake.Statiq ?
127+
public void Statiq(string command = "", IDictionary<string, string> additionalSetting = null)
128+
{
129+
var statiqProj = BuildParameters.WyamRootDirectoryPath.CombineWithFilePath("Docs.csproj").FullPath; // TODO: Configurable!
130+
var settings = new Dictionary<string, string>
131+
{
132+
{ "Host", BuildParameters.WebHost },
133+
{ "LinkRoot", BuildParameters.WebLinkRoot },
134+
{ "BaseEditUrl", BuildParameters.WebBaseEditUrl },
135+
{ "Title", BuildParameters.Title },
136+
{ "IncludeGlobalNamespace", "false" },
137+
{ "STATIQ_DEPLOY_OWNER", BuildParameters.RepositoryOwner },
138+
{ "STATIQ_DEPLOY_REPO_NAME", BuildParameters.RepositoryName }
139+
};
140+
141+
if (BuildParameters.ShouldDocumentSourceFiles)
142+
{
143+
settings.Add("SourceFiles", BuildParameters.WyamSourceFiles);
144+
}
145+
146+
if(additionalSetting != null)
147+
{
148+
settings = new[]{settings, additionalSetting}.SelectMany(x => x).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
149+
}
150+
151+
if((command.EqualsIgnoreCase("preview") || command.EqualsIgnoreCase("serve")) && !string.IsNullOrEmpty(BuildParameters.WebLinkRoot))
152+
{
153+
command += $" --virtual-dir={BuildParameters.WebLinkRoot}";
154+
}
155+
156+
// TODO: Read log-level from Env/commandline?
157+
158+
DotNetCoreRun(statiqProj, new DotNetCoreRunSettings
159+
{
160+
EnvironmentVariables = settings,
161+
ArgumentCustomization = args=>args
162+
.Append(" -- ")
163+
.Append(command)
164+
.Append($"--root=\"{BuildParameters.WyamRootDirectoryPath}\""),
165+
});
166+
}
167+
168+
169+
///////////////////////////////////////////////////////////////////////////////
170+
// BAKE STATIQ IN Cake.Recipe
171+
///////////////////////////////////////////////////////////////////////////////
172+
173+
BuildParameters.Tasks.PreviewTask.IsDependentOn("Preview-StatiqDocs");
174+
BuildParameters.Tasks.PublishDocsTask.IsDependentOn("Force-Publish-StatiqDocs");
175+
BuildParameters.Tasks.ContinuousIntegrationTask.IsDependentOn("Publish-StatiqDocs");

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
WYAM_ACCESS_TOKEN: ${{ secrets.WYAM_ACCESS_TOKEN }}
4242
WYAM_DEPLOY_BRANCH: "gh-pages"
4343
WYAM_DEPLOY_REMOTE: ${{ github.event.repository.html_url }}
44+
STATIQ_DEPLOY_OWNER: "cake-contrib"
4445

4546
steps:
4647
- name: Checkout the repository

.github/workflows/publishDocs.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ on:
44
workflow_dispatch:
55

66
env:
7-
WYAM_ACCESS_TOKEN: ${{ secrets.API_TOKEN }}
8-
# secrets.GITHUB_TOKEN has no permissions to push, sadly.
9-
WYAM_DEPLOY_BRANCH: 'gh-pages'
10-
WYAM_DEPLOY_REMOTE: "${{ github.event.repository.html_url }}"
7+
STATIQ_DEPLOY_OWNER: "cake-contrib"
8+
WYAM_ACCESS_TOKEN: ${{ secrets.WYAM_ACCESS_TOKEN }}
9+
WYAM_DEPLOY_BRANCH: "gh-pages"
10+
WYAM_DEPLOY_REMOTE: ${{ github.event.repository.html_url }}
1111

1212
jobs:
1313
cake:
@@ -20,16 +20,19 @@ jobs:
2020
- name: Fetch all tags and branches
2121
run: git fetch --prune --unshallow
2222

23+
- uses: actions/[email protected]
24+
with:
25+
dotnet-version: 7.0.x
26+
2327
- name: Cache Tools
2428
uses: actions/cache@v3
2529
with:
2630
path: tools
2731
key: ${{ runner.os }}-doc-tools-${{ hashFiles('recipe.cake') }}
2832

29-
- name: Publishing documentaiton
33+
- name: Publishing documentation
3034
uses: cake-build/cake-action@v1
3135
with:
3236
script-path: recipe.cake
33-
target: Force-Publish-Documentation
34-
verbosity: Diagnostic
37+
target: PublishDocs
3538
cake-version: tool-manifest

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,5 @@ docs/input/tasks/*
5252
# Wyam related
5353
config.wyam.*
5454
.idea/
55+
docs/cache/
56+
docs/output/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "docs/theme"]
2+
path = docs/theme
3+
url = https://github.com/statiqdev/Docable.git

docs/Docs.csproj

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net7.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<LanguageVersion>latest</LanguageVersion>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Statiq.Docs" Version="1.0.0-beta.14" />
13+
</ItemGroup>
14+
15+
</Project>

docs/Program.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
await Bootstrapper
2+
.Factory
3+
.CreateDocs(args)
4+
.DeployToGitHubPagesBranch(
5+
Config.FromSetting<string>("STATIQ_DEPLOY_OWNER"),
6+
Config.FromSetting<string>("WYAM_DEPLOY_REMOTE"),
7+
Config.FromSetting<string>("WYAM_ACCESS_TOKEN"),
8+
Config.FromSetting<string>("WYAM_DEPLOY_BRANCH")
9+
)
10+
.RunAsync();

docs/input/assets/favicons/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# FAVICON package
2+
3+
This was all generated by using https://realfavicongenerator.net/ with
4+
https://github.com/cake-contrib/graphics/blob/3344c5e09d33dedb984edf8a362d8a3d32f7acd4/png/addin/cake-contrib-addin-large.png as the source.
20.1 KB
Loading
57.2 KB
Loading

0 commit comments

Comments
 (0)