Skip to content

Commit 2400635

Browse files
authored
docs: generate and update gh-pages using github workflow (#422)
1 parent ddaddfc commit 2400635

File tree

3 files changed

+117
-73
lines changed

3 files changed

+117
-73
lines changed

.github/workflows/docs.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'docs/**'
9+
- 'src/*/PublicAPI.*.txt'
10+
- '.github/workflows/docs.yml'
11+
12+
pull_request:
13+
paths:
14+
- 'docs/**'
15+
- 'src/*/PublicAPI.*.txt'
16+
- '.github/workflows/docs.yml'
17+
18+
jobs:
19+
generate_docs:
20+
runs-on: windows-latest
21+
22+
steps:
23+
- uses: actions/checkout@v2
24+
- name: Setup .NET 5
25+
uses: actions/setup-dotnet@v1
26+
with:
27+
dotnet-version: '5.0.x'
28+
- name: Run docs generation
29+
run: ./docs/generate.ps1
30+
31+
- name: Publish docs to GH Pages
32+
if: github.event_name == 'push'
33+
run: ./docs/push.ps1 -a ${{ github.token }}

docs/generate.ps1

100644100755
Lines changed: 79 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,79 @@
1-
#requires -version 5
2-
param(
3-
[switch]$Serve,
4-
[switch]$Install,
5-
[switch]$NoBuild
6-
)
7-
$ErrorActionPreference = 'Stop'
8-
Set-StrictMode -Version 2
9-
10-
Import-Module -Force -Scope Local "$PSScriptRoot/../src/common.psm1"
11-
12-
Push-Location "$PSScriptRoot/../"
13-
14-
try {
15-
16-
if (-not $NoBuild) {
17-
exec dotnet build "$PSScriptRoot/samples/samples.sln"
18-
}
19-
20-
$buildRoot = "$PSScriptRoot/../.build/docs"
21-
$targetDir = "$buildRoot/gh-pages"
22-
mkdir -p $buildRoot -ErrorAction Ignore | Out-Null
23-
24-
exec git worktree prune 2>&1 | out-null
25-
if (-not (git worktree list --porcelain | Select-String 'gh-pages')) {
26-
exec git fetch --quiet -u origin gh-pages:gh-pages
27-
exec git worktree add $targetDir gh-pages 2>&1 | out-null
28-
}
29-
30-
$docfxVersion = '2.51.0'
31-
$docfxRoot = "$buildRoot/packages/docfx.console/$docfxVersion"
32-
$docfx = "$docfxRoot/tools/docfx.exe"
33-
if (-not (Test-Path $docfx)) {
34-
mkdir -p $docfxRoot -ErrorAction Ignore | Out-Null
35-
$temp = (New-TemporaryFile).FullName + ".zip"
36-
Invoke-WebRequest "https://www.nuget.org/api/v2/package/docfx.console/$docfxVersion" -O $temp
37-
Expand-Archive $temp -DestinationPath $docfxRoot
38-
Remove-Item $temp
39-
if ($Install) {
40-
exit 1
41-
}
42-
}
43-
44-
Push-Location $targetDir
45-
exec git rm --quiet --force -r .
46-
Pop-Location
47-
48-
if (-not $NoBuild) {
49-
exec dotnet build -c Release
50-
}
51-
52-
[string[]] $arguments = @()
53-
try {
54-
if ($Serve) {
55-
$arguments += '--serve'
56-
}
57-
exec $docfx docs/docfx.json @arguments
58-
}
59-
finally {
60-
Push-Location $targetDir
61-
exec git config core.safecrlf false # suppress warning about CRLF
62-
exec git add ./ 2>&1 | Out-Null
63-
Pop-Location
64-
}
65-
}
66-
finally {
67-
Pop-Location
68-
}
1+
#!/usr/bin/env pwsh
2+
param(
3+
[switch]$Serve,
4+
[switch]$Install,
5+
[switch]$NoBuild
6+
)
7+
$ErrorActionPreference = 'Stop'
8+
Set-StrictMode -Version 2
9+
10+
if (-not (Test-Path variable:\IsCoreCLR)) {
11+
$IsWindows = $true
12+
}
13+
14+
Import-Module -Force -Scope Local "$PSScriptRoot/../src/common.psm1"
15+
16+
Push-Location "$PSScriptRoot/../"
17+
18+
try {
19+
20+
if (-not $NoBuild) {
21+
exec dotnet build "$PSScriptRoot/samples/samples.sln"
22+
}
23+
24+
$buildRoot = "$PSScriptRoot/../.build/docs"
25+
$targetDir = "$buildRoot/gh-pages"
26+
mkdir -p $buildRoot -ErrorAction Ignore | Out-Null
27+
28+
exec git worktree prune 2>&1 | out-null
29+
if (-not (git worktree list --porcelain | Select-String 'gh-pages')) {
30+
exec git fetch --quiet -u origin gh-pages:gh-pages
31+
exec git worktree add $targetDir gh-pages 2>&1 | out-null
32+
}
33+
34+
$docfxVersion = '2.56.6'
35+
$docfxRoot = "$buildRoot/packages/docfx.console/$docfxVersion"
36+
$docfx = "$docfxRoot/tools/docfx.exe"
37+
if (-not (Test-Path $docfx)) {
38+
mkdir -p $docfxRoot -ErrorAction Ignore | Out-Null
39+
$temp = (New-TemporaryFile).FullName + ".zip"
40+
Invoke-WebRequest "https://www.nuget.org/api/v2/package/docfx.console/$docfxVersion" -O $temp
41+
Expand-Archive $temp -DestinationPath $docfxRoot
42+
Remove-Item $temp
43+
if ($Install) {
44+
exit 1
45+
}
46+
}
47+
48+
Push-Location $targetDir
49+
exec git reset --hard
50+
exec git rm --quiet --force -r .
51+
Pop-Location
52+
53+
if (-not $NoBuild) {
54+
exec dotnet build -c Release
55+
}
56+
57+
[string[]] $arguments = @()
58+
try {
59+
if ($Serve) {
60+
$arguments += '--serve'
61+
}
62+
63+
if ($IsWindows) {
64+
exec $docfx docs/docfx.json @arguments
65+
}
66+
else {
67+
exec mono $docfx docs/docfx.json @arguments
68+
}
69+
}
70+
finally {
71+
Push-Location $targetDir
72+
exec git config core.safecrlf false # suppress warning about CRLF
73+
exec git add ./ 2>&1 | Out-Null
74+
Pop-Location
75+
}
76+
}
77+
finally {
78+
Pop-Location
79+
}

docs/push.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ $workdir = "$PSScriptRoot/../.build/docs/gh-pages"
1414
Push-Location $workdir
1515
try {
1616

17-
if ($env:TF_BUILD) {
17+
if ($env:CI) {
1818
exec git config --global credential.helper store
19-
Add-Content "$HOME\.git-credentials" "https://$($ApiToken):x-oauth-basic@github.com`n"
20-
exec git config --global user.email 'azuredevops@microsoft.com'
21-
exec git config --global user.name 'Azure Pipelines'
22-
$SourceCommit = $env:BUILD_SOURCEVERSION
19+
Add-Content "$HOME\.git-credentials" "https://x-access-token:${ApiToken}@github.com`n"
20+
exec git config --global user.email '[email protected].com'
21+
exec git config --global user.name "GitHub Workflow (${env:GITHUB_ACTOR})"
22+
$SourceCommit = $env:GITHUB_SHA
2323
}
2424

2525
if (-not $SourceCommit) {

0 commit comments

Comments
 (0)