1212# The commit the fake "git rev-parse" reports, so a test can assert what was archived and recorded.
1313$script :FakeCommitHash = ' a1b2c3d4e5f6071829a3b4c5d6e7f80912345678'
1414
15- # Logs its call, fails when named in FAKE_FAIL, and otherwise writes the files the real command
16- # would, where it is told to, so a wrong output path fails as it would for real. "git status" and
17- # "git rev-parse" answer on stdout instead, FAKE_DIRTY faking an unclean tree.
15+ # Logs its call, fails when named in FAKE_FAIL (by command, or by command and first argument, as
16+ # in "dotnet docfx"), and otherwise writes the files the real command would, where it is told to,
17+ # so a wrong output path fails as it would for real. "git status" and "git rev-parse" answer on
18+ # stdout instead, FAKE_DIRTY faking an unclean tree and FAKE_NO_OUTPUT a docfx that wrote nothing.
19+ # "curl -o" writes a package with an assembly and its xml for every framework a script may look
20+ # for, and "dotnet docfx" its index.html at the -o base, or at target/site/api without one.
1821$script :FakeCommand = @'
1922param([string]$Name)
2023Add-Content -Path $env:FAKE_LOG -Value "$Name $($args -join ' ')"
21- if ($env:FAKE_FAIL -eq $Name) { exit 1 }
24+ if ($env:FAKE_FAIL -in $Name, "$Name $($args[0])" ) { exit 1 }
2225if ($Name -eq 'git')
2326{
2427 switch ($args[0])
@@ -31,29 +34,65 @@ $outputs = switch ($Name)
3134{
3235 'dotnet'
3336 {
34- $version = ($args -join ' ') -replace '.*PackageVersion=(\S+).*', '$1'
35- $build = "$(Split-Path $PSScriptRoot)/build"
36- "$build/artifacts/log4net.$version.nupkg", "$build/artifacts/log4net.Ext.Mail.$version.nupkg", "$build/Release/net462/log4net.dll"
37+ $root = Split-Path $PSScriptRoot
38+ switch ($args[0])
39+ {
40+ 'tool' { }
41+ 'docfx'
42+ {
43+ $base = $args.IndexOf('-o') -ge 0 ? $args[$args.IndexOf('-o') + 1] : "$root/target/site/api"
44+ if (!$env:FAKE_NO_OUTPUT) { "$base/index.html" }
45+ }
46+ default
47+ {
48+ $version = ($args -join ' ') -replace '.*PackageVersion=(\S+).*', '$1'
49+ "$root/build/artifacts/log4net.$version.nupkg", "$root/build/artifacts/log4net.Ext.Mail.$version.nupkg", "$root/build/Release/net462/log4net.dll"
50+ }
51+ }
3752 }
3853 'git' { if ($args[0] -eq 'archive') { $args[$args.IndexOf('--output') + 1] } }
3954 'zip' { $args[1] }
55+ 'curl'
56+ {
57+ $package = New-Item -ItemType Directory -Path (Join-Path ([IO.Path]::GetTempPath()) ([guid]::NewGuid()))
58+ foreach ($lib in 'net462', 'netstandard2.0')
59+ {
60+ foreach ($file in 'log4net.dll', 'log4net.xml', 'log4net.Ext.Mail.dll', 'log4net.Ext.Mail.xml')
61+ {
62+ New-Item -ItemType File -Force -Path (Join-Path $package 'lib' $lib $file) | Out-Null
63+ }
64+ }
65+ Compress-Archive -Path (Join-Path $package 'lib') -DestinationPath $args[$args.IndexOf('-o') + 1] -Force
66+ Remove-Item $package -Recurse -Force
67+ }
4068}
4169$outputs | ForEach-Object { New-Item -ItemType File -Force -Path $_ | Out-Null }
4270'@
4371
4472function New-ScratchTree
4573{
46- param ([Parameter (Mandatory )][string ]$Script )
74+ param ([Parameter (Mandatory , HelpMessage = ' The script under test, relative to scripts/. ' )][string ]$Script )
4775
4876 $root = New-Item - ItemType Directory - Path (Join-Path ([System.IO.Path ]::GetTempPath()) ([guid ]::NewGuid()))
4977 $scripts = New-Item - ItemType Directory - Path (Join-Path $root ' scripts' )
5078 $bin = New-Item - ItemType Directory - Path (Join-Path $root ' fakebin' )
51- Copy-Item (Join-Path $PSScriptRoot $Script ) $scripts
79+ # The script keeps its place under scripts/, as the paths it derives from its own depend on it.
80+ $target = Join-Path $scripts $Script
81+ New-Item - ItemType Directory - Path (Split-Path $target ) - Force | Out-Null
82+ Copy-Item (Join-Path $PSScriptRoot $Script ) $target
5283 Copy-Item (Join-Path $PSScriptRoot ' verify-release.*' ) $scripts
84+ # build-release.ps1 calls it by path, and the build scripts import Common.psm1.
85+ Copy-Item (Join-Path $PSScriptRoot ' build-api-docs.ps1' ) $scripts
86+ Copy-Item (Join-Path $PSScriptRoot ' Common.psm1' ) $scripts
87+ # The version build-api-docs.ps1 names in its titles.
88+ Set-Content - Path (New-Item - ItemType File - Force - Path (Join-Path $root ' src' ' Directory.Build.props' )) - Value ' <Project><PropertyGroup><VersionPrefix>9.9.9</VersionPrefix></PropertyGroup></Project>'
89+ # The shared docfx sources the old-version script copies.
90+ Copy-Item (Join-Path $PSScriptRoot ' ..' ' src' ' site' ' docfx' ' logo.svg' ) (New-Item - ItemType Directory - Path (Join-Path $root ' src' ' site' ' docfx' ))
91+ New-Item - ItemType Directory - Path (Join-Path $root ' src' ' site' ' docfx' ' template' ) | Out-Null
5392 ' license' | Set-Content (Join-Path $root ' LICENSE' )
5493 ' notice' | Set-Content (Join-Path $root ' NOTICE' )
5594 Set-Content - Path (Join-Path $bin ' fake.ps1' ) - Value $script :FakeCommand
56- foreach ($name in ' dotnet' , ' git' , ' gpg' , ' zip' , ' mvnw' )
95+ foreach ($name in ' dotnet' , ' git' , ' gpg' , ' zip' , ' mvnw' , ' curl ' )
5796 {
5897 # mvnw is called by path from the root, the others through PATH.
5998 $directory = $name -eq ' mvnw' ? $root : $bin
@@ -74,7 +113,7 @@ function New-ScratchTree
74113function Invoke-InScratchTree
75114{
76115 param ([Parameter (Mandatory )][string ]$Root , [Parameter (Mandatory )][string ]$Script , [string ]$Fail ,
77- [switch ]$Dirty )
116+ [switch ]$Dirty , [ switch ] $NoOutput , [ string []] $Arguments = @ () )
78117
79118 $log = Join-Path $Root ' calls.log'
80119 New-Item - ItemType File - Path $log - Force | Out-Null
@@ -86,14 +125,15 @@ function Invoke-InScratchTree
86125 $env: FAKE_FAIL = $Fail
87126 $env: FAKE_SHA = $script :FakeCommitHash
88127 $env: FAKE_DIRTY = $Dirty ? ' 1' : ' '
128+ $env: FAKE_NO_OUTPUT = $NoOutput ? ' 1' : ' '
89129 # NonInteractive makes the confirmation pause throw, standing in for a release manager who says no.
90- $output = pwsh - NoProfile - NonInteractive - File (Join-Path $Root ' scripts' $Script ) 2>&1
130+ $output = pwsh - NoProfile - NonInteractive - File (Join-Path $Root ' scripts' $Script ) @Arguments 2>&1
91131 $exitCode = $LASTEXITCODE
92132 }
93133 finally
94134 {
95135 $env: PATH = $path
96- Remove-Item Env:FAKE_LOG, Env:FAKE_FAIL, Env:FAKE_SHA, Env:FAKE_DIRTY - ErrorAction SilentlyContinue
136+ Remove-Item Env:FAKE_LOG, Env:FAKE_FAIL, Env:FAKE_SHA, Env:FAKE_DIRTY, Env:FAKE_NO_OUTPUT - ErrorAction SilentlyContinue
97137 }
98138 return [pscustomobject ]@ {
99139 ExitCode = $exitCode
0 commit comments