Skip to content

Commit

Permalink
Deploy with ps1 (#7678)
Browse files Browse the repository at this point in the history
* deploy with powershell
  • Loading branch information
v-pegao authored Oct 28, 2021
1 parent 671ac93 commit 3b1cfd6
Show file tree
Hide file tree
Showing 29 changed files with 520 additions and 1,286 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,8 @@ jobs:
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql-config.yml

- run: npm install
working-directory: tools/Deployment

- run: node .\node_modules\typescript\bin\tsc
working-directory: tools/Deployment

- run: node .\node_modules\gulp\bin\gulp.js dev
working-directory: tools/Deployment
- run: pwsh .\tools\Deployment\deploy.ps1

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
2 changes: 1 addition & 1 deletion UpdateTemplate.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@ECHO OFF
PUSHD %~dp0
PowerShell -NoProfile -ExecutionPolicy Bypass -Command ".\UpdateTemplate.ps1 %*; exit $LastExitCode;"
pwsh -NoProfile -ExecutionPolicy Bypass -Command ".\UpdateTemplate.ps1 %*; exit $LastExitCode;"
POPD
83 changes: 74 additions & 9 deletions UpdateTemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,81 @@ $logLevelParam = if ($env:TF_BUILD -eq "True") { "--loglevel=error" } else { ""

Push-Location $PSScriptRoot

$TemplateHome="$PSScriptRoot/src/docfx.website.themes/"
$DefaultTemplate="${TemplateHome}default/"
$GulpCommand="${DefaultTemplate}node_modules/gulp/bin/gulp"
$templateHome ="$PSScriptRoot\src\docfx.website.themes"
$defaultTemplate ="$templateHome\default"

Set-Location "$DefaultTemplate"
# Prepare default templates
Set-Location $defaultTemplate
npm install $logLevelParam
node "$GulpCommand"
$cleanCssCommand="$defaultTemplate\node_modules\clean-css-cli\bin\cleancss"
$terserCommand="$defaultTemplate\node_modules\terser\bin\terser"
$vendor = @{
css = @(
'node_modules\bootstrap\dist\css\bootstrap.css',
'node_modules\highlightjs\styles\github-gist.css'
);
js = @(
'node_modules\jquery\dist\jquery.min.js',
'node_modules\bootstrap\dist\js\bootstrap.min.js',
'node_modules\highlightjs\highlight.pack.min.js',
'node_modules\@websanova\url\dist\url.min.js',
'node_modules\twbs-pagination\jquery.twbsPagination.min.js',
'node_modules\mark.js\dist\jquery.mark.min.js',
'node_modules\anchor-js\anchor.min.js'
);
font = 'node_modules\bootstrap\dist\fonts\*';
lunr = 'node_modules\lunr\lunr.js'
}
node $cleanCssCommand $Vendor.css -o ".\styles\docfx.vendor.css" --format "keep-breaks" -O2
node $terserCommand $Vendor.js -o ".\styles\docfx.vendor.js" --comments "false"
node $terserCommand $Vendor.lunr -o ".\styles\lunr.min.js" --comments "false"
Copy-Item -Path $vendor.font -Destination (New-Item ".\fonts" -Type Container -Force) -Force -Recurse
Copy-Item -Path $vendor.lunr -Destination (New-Item ".\styles" -Type Container -Force) -Force -Recurse

Set-Location "$TemplateHome"
npm install $logLevelParam
node "$GulpCommand"
# Pack templates
$templateFiles = @('layout\', 'partials\', '*.js', '*.tmpl', '*.liquid', 'token.json')
$webpageFiles = @('fonts\', 'styles\', 'favicon.ico', 'logo.svg', 'search-stopwords.json')
$files = $TemplateFiles + $WebpageFiles
$packs = @{
common = @(
@{ files = $files; }
);
default = @(
@{ files = $files; cwd = 'common'; },
@{ files = $files; }
);
'default(zh-cn)' = @(
@{ files = $files; }
);
statictoc = @(
@{ files = $files; cwd = 'common'; },
@{ files = $files; cwd = 'default'; excluder = @('toc.html.*') },
@{ files = $files }
);
'pdf.default' = @(
@{ files = $files; cwd = 'common'; },
@{ files = $templateFiles + 'fonts\'; cwd = 'default';},
@{ files = $files } # Overrides the former one if file name is the same
);
};
$packs.Keys | Foreach-Object -Parallel {
$tempFolder = "$using:PSScriptRoot\src\docfx\Template\$_"
$destPath = "$using:PSScriptRoot\src\docfx\Template\$_.zip"
$packs = $using:packs
foreach ($fileGroup in $packs[$_]) {
$baseDir = "$using:templateHome\$($fileGroup.cwd ?? $_)"
Set-Location $baseDir
$fileGroup.files | % {
if (Test-Path($_)) {
Copy-Item -Path $_ -Destination (New-Item $tempFolder -Type Container -Force) -Exclude $fileGroup.excluder -Recurse -Force
}
}
}
Add-Type -AssemblyName System.IO.Compression
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.AppContext]::SetSwitch('Switch.System.IO.Compression.ZipFile.UseBackslash', $false)
[System.IO.Compression.ZipFile]::CreateFromDirectory($tempFolder, $destPath)
Remove-Item -Path $tempFolder -Recurse -Force
}

Pop-Location
Pop-Location
52 changes: 18 additions & 34 deletions azure-pipelines-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,18 @@ steps:
packageType: sdk
version: '5.0.100'

- task: NodeTool@0
displayName: 'Use Node 8.x'
inputs:
versionSpec: 8.x

- task: NuGetToolInstaller@1
displayName: 'Use NuGet'
inputs:
versionSpec: 5.9.1

- task: CmdLine@1
displayName: 'npm install'
inputs:
filename: npm
arguments: install
workingFolder: tools/Deployment

- task: CmdLine@1
displayName: 'tsc compile'
inputs:
filename: node
arguments: '.\node_modules\typescript\bin\tsc'
workingFolder: tools/Deployment

- task: CmdLine@1
displayName: 'gulp build'
- task: PowerShell@2
displayName: 'main build'
inputs:
filename: node
arguments: '.\node_modules\gulp\bin\gulp.js main:build'
workingFolder: tools/Deployment
pwsh: true
failOnStderr: true
filePath: 'tools\Deployment\deploy.ps1'
arguments: '-main'
env:
TOKEN: $(ServiceAccountGithubToken)

Expand Down Expand Up @@ -183,12 +165,13 @@ steps:
MaxConcurrency: '50'
MaxRetryAttempts: '5'

- task: CmdLine@1
displayName: 'gulp pack'
- task: PowerShell@2
displayName: 'main pack'
inputs:
filename: node
arguments: '.\node_modules\gulp\bin\gulp.js main:pack'
workingFolder: tools/Deployment
pwsh: true
failOnStderr: true
filePath: 'tools\Deployment\deploy.ps1'
arguments: '-main -targets pack'

- task: EsrpCodeSigning@1
displayName: 'Sign NuGet packages'
Expand Down Expand Up @@ -226,12 +209,13 @@ steps:
SessionTimeout: 20

- task: CmdLine@1
displayName: 'gulp release'
- task: PowerShell@2
displayName: 'main release'
inputs:
filename: node
arguments: '.\node_modules\gulp\bin\gulp.js main:release'
workingFolder: tools/Deployment
pwsh: true
failOnStderr: true
filePath: 'tools\Deployment\deploy.ps1'
arguments: '-main -targets release'
env:
NUGETAPIKEY: $(NugetAPIKey)
CHOCO_TOKEN: $(ChocoleteyPublishToken)
Expand Down
40 changes: 11 additions & 29 deletions azure-pipelines-stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,17 @@ steps:
packageType: sdk
version: '5.0.100'

- task: NodeTool@0
displayName: 'Use Node 8.x'
inputs:
versionSpec: 8.x

- task: NuGetToolInstaller@1
displayName: 'Use NuGet'
inputs:
versionSpec: 5.9.1

- task: CmdLine@1
displayName: 'npm install'
inputs:
filename: npm
arguments: install
workingFolder: tools/Deployment

- task: CmdLine@1
displayName: 'tsc compile'
inputs:
filename: node
arguments: '.\node_modules\typescript\bin\tsc'
workingFolder: tools/Deployment

- task: CmdLine@1
displayName: 'gulp build'
- task: PowerShell@2
displayName: 'dev build'
inputs:
filename: node
arguments: '.\node_modules\gulp\bin\gulp.js dev:build'
workingFolder: tools/Deployment
pwsh: true
failOnStderr: true
filePath: 'tools\Deployment\deploy.ps1'

- task: UseDotNet@2
displayName: 'Install .NET Core sdk required for ESRPCodeSigning'
Expand Down Expand Up @@ -181,12 +162,13 @@ steps:
MaxConcurrency: '50'
MaxRetryAttempts: '5'

- task: CmdLine@1
displayName: 'gulp pack'
- task: PowerShell@2
displayName: 'dev release'
inputs:
filename: node
arguments: '.\node_modules\gulp\bin\gulp.js dev:release'
workingFolder: tools/Deployment
pwsh: true
failOnStderr: true
filePath: 'tools\Deployment\deploy.ps1'
arguments: '-targets pack,release'
env:
AZDEVOPSPAT: $(AzureDevOpsFeedPAT)

Expand Down
31 changes: 6 additions & 25 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,17 @@ pool:
name: Hosted Windows 2019 with VS2019
vmImage: 'windows-2019'
steps:
- task: NodeTool@0
displayName: 'Use Node 8.x'
inputs:
versionSpec: 8.x

- task: NuGetToolInstaller@1
displayName: 'Use NuGet'
inputs:
versionSpec: 5.9.1

- task: CmdLine@1
displayName: 'npm install'
inputs:
filename: npm
arguments: install
workingFolder: tools/Deployment

- task: CmdLine@1
displayName: 'tsc compile'
inputs:
filename: node
arguments: '.\node_modules\typescript\bin\tsc'
workingFolder: tools/Deployment

- task: CmdLine@1
displayName: 'gulp build'
- task: PowerShell@2
displayName: 'dev build'
inputs:
filename: node
arguments: '.\node_modules\gulp\bin\gulp.js dev'
workingFolder: tools/Deployment
pwsh: true
failOnStderr: true
filePath: 'tools\Deployment\deploy.ps1'

- task: PublishBuildArtifacts@1
condition: always()
Expand All @@ -55,4 +36,4 @@ steps:
condition: always()
inputs:
pathtoPublish: 'test\docfx-seed\_site'
artifactName: docfx-seed-site
artifactName: docfx-seed-site
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $assemblyVersion = "1.0.0.0"

$os = GetOperatingSystemName
Write-Host "Running on OS $os"
$nugetCommand = GetNuGetCommand ($os)
$nugetCommand = GetNuGetCommandWithValidation ($os)
$scriptPath = $MyInvocation.MyCommand.Path
$scriptHome = Split-Path $scriptPath
$versionCsFolderPath = $scriptHome + "/TEMP/"
Expand Down
38 changes: 28 additions & 10 deletions common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ function GetOperatingSystemName()
}
}

function GetNuGetCommand([string]$os)
{
if ($os -eq "Windows") {
return "$env:LOCALAPPDATA/Nuget/Nuget.exe"
}
else {
return "nuget"
}
}

function ProcessLastExitCode {
param($exitCode, $msg)
if ($exitCode -eq 0) {
Expand All @@ -35,4 +25,32 @@ function ProcessLastExitCode {
function ValidateCommand {
param($command)
return (Get-Command $command -ErrorAction SilentlyContinue) -ne $null
}

function GetNuGetCommandWithValidation([string]$os, [bool]$downloadIfNotExist = $false)
{
$nugetCommand = $null
if (ValidateCommand("nuget")) {
$nugetCommand = "nuget"
} elseIf ($os -eq "Windows") {
$localNugetExe = "$env:LOCALAPPDATA\Nuget\nuget.exe"
if (ValidateCommand($localNugetExe)) {
$nugetCommand = $localNugetExe
} elseIf ($downloadIfNotExist) {
Write-Host "Downloading NuGet.exe..."
mkdir -Path $(Split-Path $localNugetExe) -Force
$ProgressPreference = 'SilentlyContinue'
[Net.WebRequest]::DefaultWebProxy.Credentials = [Net.CredentialCache]::DefaultCredentials

# Pin Nuget version to v5.9.1 to workaround for Nuget issue: https://github.com/NuGet/Home/issues/11125
# Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -OutFile $nugetCommand
Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/v5.9.1/nuget.exe' -OutFile $localNugetExe
$nugetCommand = $localNugetExe
}
}
if ($nugetCommand) {
Write-Host "Using Nuget Command: $nugetCommand, $(& $nugetCommand help | Select -First 1)"
return $nugetCommand
}
ProcessLastExitCode 1 "Nuget is required however it is not installed."
}
18 changes: 1 addition & 17 deletions pack.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ else{

$os = GetOperatingSystemName
Write-Host "Running on OS $os"
$globalNugetCommand = 'nuget'
$nugetCommand = GetNuGetCommand ($os)
$nugetCommand = GetNuGetCommandWithValidation ($os) ($true)
$scriptPath = $MyInvocation.MyCommand.Path
$scriptHome = Split-Path $scriptPath

Expand All @@ -39,21 +38,6 @@ if (-not(ValidateCommand("dotnet"))) {
ProcessLastExitCode 1 "Dotnet CLI is not successfully configured. Please follow https://www.microsoft.com/net/core to install .NET Core."
}

# Check if nuget.exe exists
if (ValidateCommand($globalNugetCommand)) {
$nugetCommand = $globalNugetCommand
} elseIf (-not(ValidateCommand($nugetCommand))) {
Write-Host "Downloading NuGet.exe..."
mkdir -Path "$env:LOCALAPPDATA/Nuget" -Force
$ProgressPreference = 'SilentlyContinue'
[Net.WebRequest]::DefaultWebProxy.Credentials = [Net.CredentialCache]::DefaultCredentials

# Pin Nuget version to v5.9.1 to workaround for Nuget issue: https://github.com/NuGet/Home/issues/11125
# Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -OutFile $nugetCommand
Invoke-WebRequest 'https://dist.nuget.org/win-x86-commandline/v5.9.1/nuget.exe' -OutFile $nugetCommand
}
Write-Host "Using Nuget Command: $nugetCommand, $(& $nugetCommand help | Select -First 1)"

# dotnet pack first
foreach ($proj in (Get-ChildItem -Path ("src", "plugins") -Include *.[cf]sproj -Exclude 'docfx.msbuild.csproj' -Recurse)) {
if ($os -eq "Windows") {
Expand Down
Loading

0 comments on commit 3b1cfd6

Please sign in to comment.