Skip to content

Commit 90a1a2f

Browse files
committed
Automate deployment of generated docs
1 parent 0efbe29 commit 90a1a2f

File tree

7 files changed

+74
-17
lines changed

7 files changed

+74
-17
lines changed

.appveyor.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ branches:
99
- /^feature\/.*/
1010
build_script:
1111
- ps: .\build.ps1 -IsOfficialBuild
12-
- ps: .\docs\generate.ps1
12+
- ps: .\docs\generate.ps1 -NoBuild
13+
on_success:
14+
- ps: .\docs\push.ps1 -AppVeyor
1315
environment:
16+
access_token:
17+
secure: 7gza5cyC0Fwp5LcFPz9dGMcHXP2jxbrnu7er9R/HkdvnhzGJVADvOtfYO7+Vow5p
1418
global:
1519
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
1620
DOTNET_CLI_TELEMETRY_OPTOUT: 1
@@ -30,3 +34,13 @@ deploy:
3034
branch: master
3135
api_key:
3236
secure: KF1yGk4IHJyyfiHfFSCxJ+p5iZX+KPfCTnCihjD5iIZjasTS1lHeilpbaon4wvcM
37+
- provider: GitHub
38+
description: 'See https://github.com/natemcmaster/CommandLineUtils/blob/master/CHANGELOG.md for details'
39+
auth_token:
40+
secure: 7gza5cyC0Fwp5LcFPz9dGMcHXP2jxbrnu7er9R/HkdvnhzGJVADvOtfYO7+Vow5p
41+
artifact: Packages
42+
draft: false
43+
prerelease: false
44+
on:
45+
branch: master # release from master branch only
46+
appveyor_repo_tag: true # deploy on tag push only

build.ps1

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,7 @@ param(
1212
Set-StrictMode -Version 1
1313
$ErrorActionPreference = 'Stop'
1414

15-
function exec([string]$_cmd) {
16-
write-host -ForegroundColor DarkGray ">>> $_cmd $args"
17-
$ErrorActionPreference = 'Continue'
18-
& $_cmd @args
19-
$ErrorActionPreference = 'Stop'
20-
if ($LASTEXITCODE -ne 0) {
21-
write-error "Failed with exit code $LASTEXITCODE"
22-
exit 1
23-
}
24-
}
15+
Import-Module -Force -Scope Local "$PSScriptRoot/src/common.psm1"
2516

2617
#
2718
# Main

docs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Looking to read docs? Visit https://natemcmaster.github.io/CommandLineUtils/
2+
3+
Looking to help write docs? Checkout [CONTRIBUTING.md](../CONTRIBUTING.md)

docs/docfx.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
],
3838
"exclude": [
3939
"**/obj/**",
40-
"**.meta"
40+
"**.meta",
41+
"README.md"
4142
]
4243
}
4344
],

docs/generate.ps1

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ param(
66
$ErrorActionPreference = 'Stop'
77
Set-StrictMode -Version 2
88

9+
Import-Module -Force -Scope Local "$PSScriptRoot/src/common.psm1"
10+
911
Push-Location "$PSScriptRoot/../"
1012

1113
try {
@@ -15,6 +17,7 @@ try {
1517
New-Item -ItemType Directory $buildRoot -ErrorAction Ignore
1618

1719
if (-not (git worktree list --porcelain | Select-String 'gh-pages')) {
20+
& git fetch origin gh-pages
1821
& git worktree add $targetDir gh-pages
1922
}
2023

@@ -30,24 +33,24 @@ try {
3033
}
3134

3235
Push-Location $targetDir
33-
git rm --quiet --force -r .
36+
& git rm --quiet --force -r .
3437
Pop-Location
3538

3639
if (-not $NoBuild) {
37-
& dotnet build -c Release
40+
exec dotnet build -c Release
3841
}
3942

4043
$arguments = @()
4144
try {
4245
if ($Serve) {
4346
$arguments += '--serve'
4447
}
45-
& $docfx docs/docfx.json @arguments
48+
exec $docfx docs/docfx.json @arguments
4649
}
4750
finally {
4851
Push-Location $targetDir
49-
git add ./
50-
git --no-pager status -s
52+
& git add ./
53+
& git --no-pager status -s
5154
Pop-Location
5255
}
5356
}

docs/push.ps1

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#requires -version 5
2+
param(
3+
[string]$SourceCommit,
4+
[switch]$DryRun,
5+
[switch]$AppVeyor
6+
)
7+
8+
$ErrorActionPreference = 'Stop'
9+
Set-StrictMode -Version 2
10+
11+
Import-Module -Force -Scope Local "$PSScriptRoot/../src/common.psm1"
12+
13+
$workdir = "$PSScriptRoot/../.build/docs/gh-pages"
14+
Push-Location $workdir
15+
try {
16+
17+
if ($AppVeyor) {
18+
exec git config --global credential.helper store
19+
Add-Content "$HOME\.git-credentials" "https://$($env:access_token):[email protected]`n"
20+
exec git config --global user.email $env:APPVEYOR_REPO_COMMIT_AUTHOR
21+
exec git config --global user.name $env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL
22+
$SourceCommit = $env:APPVEYOR_REPO_COMMIT
23+
}
24+
25+
if (-not $SourceCommit) {
26+
Push-Location $PSScriptRoot
27+
$SourceCommit = $(git rev-parse HEAD)
28+
Pop-Location
29+
}
30+
exec git commit -m "Generate documentation from $SourceCommit"
31+
exec git push --dry-run
32+
}
33+
finally {
34+
Pop-Location
35+
}

src/common.psm1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function exec([string]$_cmd) {
2+
write-host -ForegroundColor DarkGray ">>> $_cmd $args"
3+
$ErrorActionPreference = 'Continue'
4+
& $_cmd @args
5+
$ErrorActionPreference = 'Stop'
6+
if ($LASTEXITCODE -ne 0) {
7+
write-error "Failed with exit code $LASTEXITCODE"
8+
exit 1
9+
}
10+
}

0 commit comments

Comments
 (0)