Skip to content

Commit

Permalink
feat: Set schema as latest/unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
Kieranties committed Jul 8, 2019
1 parent 63c4e4d commit 120cfb1
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions deploydocs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using namespace System.IO

param(
[String]$RootPath = $PSScriptRoot,
[String]$ArtifactsPath = (Join-Path $RootPath 'artifacts'),
[String]$DocsPath = (Join-Path $ArtifactsPath 'docs'),
[String]$DocsDeployPath = (Join-Path $ArtifactsPath 'docsdeploy')
)

# Checkout gh-pages working tree
if (-not (git worktree list | Select-String 'gh-pages')) {
git fetch --quiet -u origin gh-pages:gh-pages
git worktree add $DocsDeployPath gh-pages
}

try {
Push-Location $DocsDeployPath
# Copy new assets to the deploy path
Copy-Item $DocsPath\* $DocsDeployPath -Recurse -Force
# Update the latest/unstable paths as required
$schemaDestRoot = New-Item (Join-Path $DocsDeployPath 'schema') -ItemType Container -Force -ErrorAction ignore
$latestSchema = Get-Item ([Path]::Combine($DocsPath, 'schema', '*.json'))
$isPrerelease = $latestSchema.BaseName -like '*-*'
$versionFilter = if($isPrerelease){
{ $_.BaseName -like '*-*'}
} else {
{ $_.BaseName -notlike '*-*' }
}
$compareVersions = @(Get-ChildItem $schemaDestRoot |
Where-Object $versionFilter |
Select-Object -ExpandProperty BaseName |
Where-Object { $_ -match '\d'})
$compareVersions += $latestSchema.BaseName

$top = $compareVersions | Sort-Object -Descending | Select-Object -First 1
$destinationName = if($top -eq $latestSchema.BaseName) {
if($isPrerelease){
'unstable.json'
} else {
'stable.json'
}
}
if($destinationName) {
Write-Host "Setting [$($latestSchema.BaseName)] as the current '$destinationName'"
Copy-Item $latestSchema -Destination (Join-Path $schemaDestRoot $destinationName)-Force
}
Copy-Item $latestSchema -Destination $schemaDestRoot

# Update git
git config core.safecrlf false
git add * | Out-Null
git commit -m "Release $($latestSchema.Basename)"
} finally {
Pop-Location
}

0 comments on commit 120cfb1

Please sign in to comment.