Skip to content

Commit 11d27bd

Browse files
committed
Improve tools/ci/build-docs.ps1 [skip ci]
1 parent cb33556 commit 11d27bd

File tree

3 files changed

+82
-49
lines changed

3 files changed

+82
-49
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ temp/
202202
**/SharedLoader.java
203203

204204
# ignore downloaded tools
205-
tools/external/
205+
tools/external
206206

207207
# ignore lua-tests res folder which is copy from cpp-tests
208208
tests/lua-tests/res/

docs/menu_version.js.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'use strict';
33

44
var url_re = /(axmol\.dev\/manual\/)(latest|(\d\.\d+|\d\.\d+\.\d+)(-beta\d)?)\//;
5-
var url_local = /dist\/site1\/manual\/(latest|(\d\.\d+|\d\.\d+\.\d+)(-beta\d)?)\//;
5+
var url_local = /dist\/manual\/(latest|(\d\.\d+|\d\.\d+\.\d+)(-beta\d)?)\//;
66
var current_version_local = '@VERSION@'
77
var all_versions = [
88
@VERLIST@
@@ -43,7 +43,7 @@
4343
return url.replace(url_re, 'axmol.dev/manual/' + new_version + '/');
4444
}
4545
else {
46-
return url.replace(url_local, 'dist/site1/manual/' + new_version + '/');
46+
return url.replace(url_local, 'dist/manual/' + new_version + '/');
4747
}
4848
}
4949

tools/ci/build-docs.ps1

Lines changed: 79 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ param(
77

88
$myRoot = $PSScriptRoot
99

10+
$ErrorActionPreference = 'Stop'
11+
1012
$isWin = $IsWindows -or ("$env:OS" -eq 'Windows_NT')
1113

1214
$pwsh_ver = $PSVersionTable.PSVersion.ToString()
@@ -18,8 +20,6 @@ if (!$git_prog) {
1820
throw 'build-docs: requires git installed'
1921
}
2022

21-
$stored_branch = $(git -C $AX_ROOT branch --show-current)
22-
2323
function mkdirs([string]$path) {
2424
if (!(Test-Path $path)) {
2525
New-Item $path -ItemType Directory 1>$null
@@ -88,25 +88,35 @@ setup_doxygen
8888

8989
Write-Host "Using doxygen $(doxygen --version)"
9090

91-
$remote_default_branch = (git symbolic-ref refs/remotes/origin/HEAD) -replace '^refs/remotes/origin/', ''
92-
$latest_branch = $remote_default_branch
91+
# begin generate docs
9392

94-
Write-Host "remote_default_branch=$remote_default_branch"
93+
$latest_branch = $(git -C $AX_ROOT branch --show-current)
94+
if (!$latest_branch) {
95+
throw "please checkout a branch as latest doc version"
96+
}
97+
98+
$remote_default_branch = (git symbolic-ref refs/remotes/origin/HEAD) -replace '^refs/remotes/origin/', ''
99+
Write-Host "latest_branch=$latest_branch, remote_default_branch=$remote_default_branch"
95100

96-
function parse_latest_rev() {
97-
git checkout $latest_branch | Out-Host
98-
$axver_file = (Resolve-Path $AX_ROOT/axmol/axmolver.h.in).Path
101+
# parse revision of current head ref to x.y.z-beef123
102+
function parse_current_rev() {
103+
$axver_file = Join-Path $AX_ROOT 'axmol/axmolver.h.in'
104+
if (!(Test-Path $axver_file -PathType Leaf)) {
105+
$axver_file = (Resolve-Path $AX_ROOT/core/axmolver.h.in).Path
106+
}
99107
$axver_content = $(Get-Content -Path $axver_file)
100-
function parse_axver($part) {
108+
109+
$parse_axver = {
110+
param($part)
101111
return ($axver_content | Select-String "#define AX_VERSION_$part").Line.Split(' ')[2]
102112
}
103113

104-
$axver = "$(parse_axver 'MAJOR').$(parse_axver 'MINOR').$(parse_axver 'PATCH')"
114+
$axver = "$(&$parse_axver 'MAJOR').$(&$parse_axver 'MINOR').$(&$parse_axver 'PATCH')"
105115

106-
$branchName = $(git -C $AX_ROOT branch --show-current)
107-
if ($branchName.StartsWith('dev/')) {
108-
$commitHash = $(git -C $AX_ROOT rev-parse --short=7 HEAD)
109-
$axver += "-$commitHash"
116+
$branch_name = $(git -C $AX_ROOT branch --show-current)
117+
if ($branch_name.StartsWith('dev/') -or $branch_name.StartsWith('release/')) {
118+
$short_sha = $(git -C $AX_ROOT rev-parse --short=7 HEAD)
119+
$axver += "-$short_sha"
110120
}
111121
return $axver
112122
}
@@ -130,63 +140,86 @@ function configure_file($infile, $outfile, $vars) {
130140

131141
# build manuals
132142

133-
# query version map to build docs
143+
# collection ver_list
144+
# doc_ver 2.4 latest
145+
# ref v2.4.1 dev/v3
146+
#
134147
$release_tags = $(git tag)
135-
$verMap = @{}
148+
$ver_list = [System.Collections.ArrayList]::new()
149+
150+
$ver_list.Add([PSCustomObject]@{
151+
doc_ver = 'latest'
152+
head_ref = $latest_branch
153+
}) | Out-Null
154+
136155
foreach ($item in $release_tags) {
137156
if ([Regex]::Match($item, '^v[0-9]+\.[0-9]+\.[0-9]+$').Success) {
138-
$docVer = $($item.Split('.')[0..1] -join '.').TrimStart('v')
139-
if ($docVer -lt $min_ver) {
157+
$doc_ver = $($item.Split('.')[0..1] -join '.').TrimStart('v')
158+
if ($doc_ver -lt $min_ver) {
140159
continue
141160
}
142-
$verMap[$docVer] = $item
161+
$ver_list.Add([PSCustomObject]@{
162+
doc_ver = $doc_ver
163+
head_ref = $item
164+
}) | Out-Null
143165
}
144166
}
145167

146-
$verList = $verMap.GetEnumerator() | Sort-Object Value -Descending | ForEach-Object { $_.Key }
147-
148-
$verMap['latest'] = parse_latest_rev
168+
$ver_list.Sort([System.Collections.Generic.Comparer[object]]::Create({
169+
param($x, $y)
170+
return [System.Collections.Comparer]::Default.Compare($y.doc_ver, $x.doc_ver)
171+
}))
172+
$ver_list | Format-Table doc_ver, head_ref -AutoSize
149173

150-
$strVerList = "'latest','$($verList -join "','")'"
151-
Write-Host "$(Out-String -InputObject $verMap)"
174+
$menu_ver_list = ($ver_list | ForEach-Object { "'$($_.doc_ver)'" }) -join ','
152175

153176
# set default doc ver to 'latest'
154177
mkdirs "$site_dist/manual"
155178
configure_file './doc_index.html.in' "$site_dist/manual/index.html" @{'@VERSION@' = 'latest' }
156179

157-
$branches = $(git branch -a)
158-
$canon_branches = @{}
159-
foreach ($branch in $branches) {
160-
$canon_branches[$branch.Trim()] = $true
161-
}
180+
function generate_docs($ver_info) {
181+
$doc_ver = $ver_info.doc_ver
182+
$head_ref = $ver_info.head_ref
162183

163-
# build manuals
164-
foreach ($item in $verMap.GetEnumerator()) {
165-
$ver = $item.Key
166-
$release_tag = $item.Value
167-
Write-Host "Generating docs for ${ver}:${release_tag} ..."
184+
# checkout
185+
Write-Host "Checking out to ${doc_ver}:${head_ref} ..."
186+
git checkout "$head_ref" --force | Out-Host
187+
$current_ref = git symbolic-ref --short HEAD 2>/dev/null || git describe --tags --exact-match 2>/dev/null
188+
if ($current_ref -ne $head_ref -and $LASTEXITCODE -ne 0) {
189+
throw "git checkout `"$head_ref`" failed or did not switch HEAD"
190+
}
191+
if ($doc_ver -eq 'latest') {
192+
$real_ver = parse_current_rev
193+
}
194+
else {
195+
$real_ver = $head_ref
196+
}
168197

169-
$html_out = Join-Path $site_dist "manual/$ver"
170-
mkdirs $html_out
198+
Write-Host "Generating docs for ${doc_ver}:${head_ref} ..."
171199

172-
if($ver -ne 'latest') {
173-
git checkout $release_tag | Out-Host
174-
} else {
175-
git checkout $latest_branch | Out-Host
176-
}
200+
# prepare html_out
201+
$html_out = Join-Path $site_dist "manual/$doc_ver"
202+
mkdirs $html_out
177203

178-
configure_file './Doxyfile.in' './Doxyfile' @{'@VERSION@' = $release_tag; '@OUTPUT_DIR@' = $site_dist; './dist' = $site_dist; '@HTML_OUTPUT@' = "manual/$ver" }
204+
# configure file
205+
configure_file './Doxyfile.in' './Doxyfile' @{'@VERSION@' = $real_ver; '@OUTPUT_DIR@' = $site_dist; './dist' = $site_dist; '@HTML_OUTPUT@' = "manual/$doc_ver" }
179206

207+
# generate docs
180208
doxygen "./Doxyfile" # 1>$null 2>$null
181209

182210
Copy-Item './hacks.js' $html_out
183211
Copy-Item './doc_style.css' "$html_out/stylesheet.css"
184-
configure_file './menu_version.js.in' "$html_out/menu_version.js" @{'@VERLIST@' = $strVerList; '@VERSION@' = $ver }
212+
configure_file './menu_version.js.in' "$html_out/menu_version.js" @{'@VERLIST@' = $menu_ver_list; '@VERSION@' = $doc_ver }
185213

186-
Write-Host "Generating docs for ${ver}:${release_tag} done"
214+
Write-Host "Generating docs for ${doc_ver}:${real_ver} done"
215+
}
216+
217+
# build manuals
218+
foreach ($ver in $ver_list) {
219+
generate_docs $ver
187220
}
188221

189-
# checkout back to stored branch
190-
git checkout $stored_branch
222+
# checkout back to latest branch
223+
git checkout $latest_branch
191224

192225
Set-Location $store_cwd

0 commit comments

Comments
 (0)