Skip to content

Commit

Permalink
Docs generation is now automatic
Browse files Browse the repository at this point in the history
Docs get built and published (to netlify) on commit.

Also builds docs as a downloadable PDF.

This is a combination of 6 commits.

add first github actions workflow

for docs building

Adds CI actions for building and publishing docs

Also adds a PDF variant of the docs

Fixed a bug in the asset chooser html

Reorganized a few sections

Added a new `index` document type that will list all the pages in  the current section after the conceptual content.

Generalized the git version file so that it can output key-value, json, CI commands, or environment variables!

Remove unnecessary gh docfx download

limit choco logs

Avoid nostdin

dotnet/docfx#4488

wkhtmltopdf/wkhtmltopdf#4450

Add netlify auth token

Fixes #315
  • Loading branch information
atruskie committed Feb 1, 2021
1 parent 7c07092 commit c788dbf
Show file tree
Hide file tree
Showing 40 changed files with 819 additions and 1,268 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: docs

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build-docs:

# docfx v2 is a .NET Framework project and only runs on Windows
runs-on: windows-latest

steps:
# checkout and cache lfs
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 100

- name: Create LFS file list
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id

- name: Restore LFS cache
uses: actions/cache@v2
id: lfs-cache
with:
path: .git/lfs
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}-v1

- name: Git LFS Pull
run: git lfs pull

# setup and build solution
# - name: Setup .NET
# uses: actions/setup-dotnet@v1

# - name: Restore dependencies
# run: dotnet restore

# - name: Build
# run: dotnet build --no-restore

- name: Generate docs
shell: pwsh
run: ./build/generate_docs.ps1

- name: Publish docs
shell: pwsh
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
run: ./build/publish_docs.ps1
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "docs2/theme"]
path = docs2/theme
url = https://github.com/statiqdev/CleanBlog.git
5 changes: 5 additions & 0 deletions build/ci.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


function is_CI() {
$env:CI -eq "true"
}
20 changes: 20 additions & 0 deletions build/exec.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function script:exec {
[CmdletBinding()]

param(
[Parameter(Position = 0, Mandatory = 1)][scriptblock]$cmd,
[Parameter(Position = 1, Mandatory = 0)][string]$errorMessage,

[switch]$WhatIf = $false
)
if ($WhatIf) {
$InformationPreference = 'Continue'
Write-Information "Would execute `"$cmd`""
return;
}

& $cmd
if ($LASTEXITCODE -ne 0) {
throw ("Error ($LASTEXITCODE) executing command: {0}" -f $cmd) + ($errorMessage ?? "")
}
}
64 changes: 41 additions & 23 deletions build/generate_docs.ps1
Original file line number Diff line number Diff line change
@@ -1,40 +1,58 @@
. $PSScriptRoot/exec.ps1
. $PSScriptRoot/log.ps1
$ErrorActionPreference = "Stop"

Push-Location

if ($null -eq (Get-Command docfx -ErrorAction SilentlyContinue)) {
Write-output "Installing docfx..."
#dotnet tool install -g docfx --version "3.0.0-*" --add-source https://www.myget.org/F/docfx-v3/api/v2
choco install docfx -y
Set-Location "$PSScriptRoot/../"

}
try {
if ($null -eq (Get-Command docfx -ErrorAction SilentlyContinue)) {
log "Installing docfx..." "Install tools"
#dotnet tool install -g docfx --version "3.0.0-*" --add-source https://www.myget.org/F/docfx-v3/api/v2
exec { choco install docfx wkhtmltopdf -y --limit-output --no-progress }
}

# if (-not ((docfx --version) -match "^3.0.*")) {
# Write-Error "We require docfx version 3"
# }
# if (-not ((docfx --version) -match "^3.0.*")) {
# Write-Error "We require docfx version 3"
# }

Write-Output "Extracting git version metadata"
. $PSScriptRoot/../src/git_version.ps1 | Split-String "`n", "`r" -RemoveEmptyStrings | ForEach-Object { $result = @{ } } {
$key, $value = $_ -split "="
$result.Add("AP_$key", $value )
} { $result } | ConvertTo-JSON | Out-File "$PSScriptRoot/../docs/apMetadata.json"
log "Extracting git version metadata" "Prepare metadata"
& $PSScriptRoot/../src/git_version.ps1 -json -prefix "AP_" > "$PSScriptRoot/../docs/apMetadata.json"
log "Extracting git version metadata (ENVIRONMENT VARIABLES)"
& $PSScriptRoot/../src/git_version.ps1 -env_vars -prefix "AP_" | set-content

Set-Location docs

log "[Disabled] Prepare API metadata for docs"
# metadata generation disabled due to a StackOverflowException that occurs
# if we try to build the docs after a metadata generation has been done
#exec { docfx metadata }

log "Building pdf docs" "Build PDF"
exec { docfx pdf --log verbose }

try {
Write-Output "Startign docs build"
Push-Location
Set-Location docs
log "moving pdf" "PDF"
$pdf_name = "ap_manual_${Env:AP_Version}.pdf"
Move-Item "ap_manual_pdf.pdf" $pdf_name -Force

docfx metadata
log "generating pdf xref files"
$xref_content = @"
{"references":[{"uid":"invariant_ap_manual_ref","name":"Download AP PDF","href":"$pdf_name","fullName":"PDF Download for AP.exe docs version ${Env:AP_Version}"}]}
"@
Set-Content -Encoding utf8NoBOM -Path "pdf_xrefmap.yml" -Value $xref_content

docfx build --log verbose

log "Building docs" "Build docs"
exec { docfx build --log verbose }

if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to build docs, skipping deploy"
exit 1
}
log "✅ Doc generation success"
}
catch {
Write-Output $_
Write-Error "Failed to build docs."
}
finally {
Pop-Location
finish_log
}
47 changes: 47 additions & 0 deletions build/log.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#Requires -Version 7

. $PSScriptRoot/ci.ps1

$script:current_section = $null

function script:log {
[CmdletBinding()]

param(
[Parameter(Position = 0, Mandatory = 1)][string]$message,
[Parameter(Position = 1, Mandatory = 0)][string]$section = ""
)


# $null - reset group
# "" - maintain group
# * - anything else, new group
if ($section -ne "") {
# reset group
if ((is_CI) -and $null -ne $script:current_section) {
Write-Output "::endgroup::"
}

# update state
$script:current_section = $section

# if starting a new group
if ($null -ne $section -and (is_CI)) {
# emit new section
Write-Output "::group::$script:current_section"
}
}

$tag = $null -ne $script:current_section ? "[$script:current_section] " : ""
Write-Output "${tag}$message"
}

function script:finish_log {
[CmdletBinding()]
param()

$script:current_section = $null
if ((is_CI)) {
Write-Output "::endgroup::"
}
}
17 changes: 3 additions & 14 deletions build/release_notes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ param(

$ErrorActionPreference = "Stop"
$DebugPreference = 'Continue'
. $PSScriptRoot/exec.ps1

Write-Debug "`$tag_name:$tag_name"
Write-Debug "`$output_file:$output_file"
Expand All @@ -32,18 +33,6 @@ function formatIssueList {
}
}

function script:exec {
[CmdletBinding()]

param(
[Parameter(Position = 0, Mandatory = 1)][scriptblock]$cmd,
[Parameter(Position = 1, Mandatory = 0)][string]$errorMessage = ("Error executing command: {0}" -f $cmd)
)
& $cmd
if ($lastexitcode -ne 0) {
throw $errorMessage
}
}

Write-Output "Creating release message"
# we assumed we've already tagged before describing this release
Expand All @@ -67,7 +56,7 @@ foreach ($line in $commit_summary) {

$issue_refs = ($line | Select-String "#\d+" -AllMatches).Matches.Value | Where-Object { $null -ne $_ }
$current.Issues += $issue_refs

}
$commits += $current
#Write-debug ($commits | format-table | out-string)
Expand All @@ -76,7 +65,7 @@ Write-debug ($commits.Count)
$commit_list = $commits | formatIssueList | Join-String -Separator "`n"

# get any notes from the change log
$changelog_path = "$PSScriptRoot/../CHANGELOG.md"
$changelog_path = "$PSScriptRoot/../CHANGELOG.md"
$changelog = Get-Content $changelog_path -Raw
# find notes and insertion point
$changelog_regex = "<!--manual-content-insert-here-->([\s\S]*)<!--generated-content-insert-here-->(\s)"
Expand Down
5 changes: 4 additions & 1 deletion docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ _exported

# apMetadata json is templated so we only want to store defaults and ignore future changes
apMetadata.json
ap_manual.json
ap_manual*.pdf
pdf_xrefmap.yml

verbose
verbose
2 changes: 1 addition & 1 deletion docs/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"recognisers",
"recognizers",
"visualise"
],
]
}
80 changes: 41 additions & 39 deletions docs/basics/assetChooser.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!-- Note: any line breaks in this document will cause a rendering error in the markdown document it is inserted into -->

<!-- Note: any line breaks in this document will cause a rendering error in the markdown document it is inserted into (THOUGH THE BREAK ABOVE IS NEEDED) -->
<div class="panel panel-default">
<div class="panel-body">
<form id="assetChooser" class="form">
Expand Down Expand Up @@ -115,64 +116,65 @@ <h5>Note</h5>
<h4 class="panel-title">Asset name</h4>
</div>
<div class="panel-body">
<pre id="assetName" class="well">
</pre>
<!-- This well must not be a pre! -->
<div id="assetName" class="well">Enable JavaScript to view result. Not available in PDF manual.</div>
<div id="anyWarning" class="WARN alert alert-warning">
<h5>Warning</h5>
<p>
A .NET Core runtime must be installed and
AnalysisPrograms must be invoked with a
<code>dotnet</code> prefix.
</p>
<h5>Warning</h5>
<p>A .NET Core runtime must be installed and
AnalysisPrograms must be invoked with a
<code>dotnet</code> prefix.
</p>
</div>
</div>
</div>
</form>
</div>
</div>

<!--the line break above is needed https://github.com/xoofx/markdig/issues/423 -->
<script type="application/javascript">
document.addEventListener("DOMContentLoaded", () => {
var assetName = document.querySelector("#assetName");
var osSet = document.querySelector("#osSet");
var archSet = document.querySelector("#archSet");
var debugSet = document.querySelector("#debugSet");
var anyWarning = document.querySelector("#anyWarning");
document.addEventListener('DOMContentLoaded', () => {
var assetName = document.querySelector('#assetName');
var osSet = document.querySelector('#osSet');
var archSet = document.querySelector('#archSet');
var debugSet = document.querySelector('#debugSet');
var anyWarning = document.querySelector('#anyWarning');
function calculateAsset() {
var os = osSet.querySelector("input[name=os]:checked").value;
var arch = archSet.querySelector("input[name=arch]:checked").value;
var debug = debugSet.querySelector("input[name=debug]:checked").value == "yes";
var isAny = os == "any";
var isMusl = os == "linux-musl";
var isLinux = os == "linux";
var isOsx = os == "osx";
var os = osSet.querySelector('input[name=os]:checked').value;
var arch = archSet.querySelector('input[name=arch]:checked').value;
var debug = debugSet.querySelector('input[name=debug]:checked').value == 'yes';
var isAny = os == 'any';
var isMusl = os == 'linux-musl';
var isLinux = os == 'linux';
var isOsx = os == 'osx';
if (isOsx) {
archSet.querySelector("input[value=x64]").checked = true;
archSet.querySelector('input[value=x64]').checked = true;
}
archSet.querySelector("input[value=arm]").disabled = !isLinux;
archSet.querySelector("input[value=arm64]").disabled = isOsx;
archSet.toggleAttribute("disabled", isAny || isMusl);
archSet.querySelector('input[value=arm]').disabled = !isLinux;
archSet.querySelector('input[value=arm64]').disabled = isOsx;
archSet.toggleAttribute('disabled', isAny || isMusl);
if (isAny || isMusl || isOsx) {
archSet.querySelector("input[value=x64]").checked = true;
archSet.querySelector('input[value=x64]').checked = true;
}
var isX64 = arch == "x64";
var isX64 = arch == 'x64';
var debugDisabled = isAny || isMusl || isOsx || !isX64;
debugSet.toggleAttribute("disabled", debugDisabled);
debugSet.toggleAttribute('disabled', debugDisabled);
if (debugDisabled) {
debugSet.querySelector("input[value=no]").checked = true;
debugSet.querySelector('input[value=no]').checked = true;
}
anyWarning.classList.toggle("hidden", !isAny);
anyWarning.classList.toggle('hidden', !isAny);
// update with fresh values after rules applied
os = osSet.querySelector("input[name=os]:checked").value;
arch = archSet.querySelector("input[name=arch]:checked").value;
debug = debugSet.querySelector("input[name=debug]:checked").value == "yes";
var debugBit = debug ? "_Debug" : "";
var extension = os == "win" ? ".zip" : ".tar.gz"
var name = "AP_" + os + "-" + arch + debugBit + "_vXXX.XXX.XXX.XXX" + extension;
os = osSet.querySelector('input[name=os]:checked').value;
arch = archSet.querySelector('input[name=arch]:checked').value;
debug = debugSet.querySelector('input[name=debug]:checked').value == 'yes';
var debugBit = debug ? '_Debug' : '';
var extension = os == 'win' ? '.zip' : '.tar.gz'
var name = 'AP_' + os + '-' + arch + debugBit + '_vXXX.XXX.XXX.XXX' + extension;
assetName.textContent = name;
};
var inputs = Array.from(document.querySelectorAll("#assetChooser input"));
var inputs = Array.from(document.querySelectorAll('#assetChooser input'));
inputs.forEach((input) => {
input.addEventListener("change", calculateAsset);
input.addEventListener('change', calculateAsset);
});
calculateAsset();
});
Expand Down
Loading

0 comments on commit c788dbf

Please sign in to comment.