You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2022/01/08 12:25:25 UTC
[lucenenet] 10/15: .build/runbuild.ps1: Track added files so they can be reverted if the build is cancelled
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
commit c47dd666db093621ac14280879da022bf24b295f
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Sat Jan 8 14:25:07 2022 +0700
.build/runbuild.ps1: Track added files so they can be reverted if the build is cancelled
---
.build/runbuild.ps1 | 41 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 36 insertions(+), 5 deletions(-)
diff --git a/.build/runbuild.ps1 b/.build/runbuild.ps1
index a62d460..f0c9f61 100644
--- a/.build/runbuild.ps1
+++ b/.build/runbuild.ps1
@@ -55,6 +55,7 @@ properties {
}
$backedUpFiles = New-Object System.Collections.ArrayList
+$addedFiles = New-Object System.Collections.ArrayList
task default -depends Pack
@@ -143,6 +144,7 @@ task Compile -depends Clean, Init, Restore -description "This task compiles the
$success = $true
} finally {
if ($success -ne $true) {
+ Delete-Added-Files $addedFiles
Restore-Files $backedUpFiles
}
}
@@ -168,11 +170,8 @@ task Pack -depends Compile -description "This task creates the NuGet packages" {
$success = $true
} finally {
#if ($success -ne $true) {
+ Delete-Added-Files $addedFiles
Restore-Files $backedUpFiles
- #Remove Version.props, as we don't want it to be committed to the repository
- if ($backupFiles -eq $true -and (Test-Path -Path "$versionPropsFile") -eq $true) {
- Remove-Item -Path "$versionPropsFile" -Force
- }
#}
}
}
@@ -246,6 +245,7 @@ task Publish -depends Compile -description "This task uses dotnet publish to pac
$success = $true
} finally {
#if ($success -ne $true) {
+ Delete-Added-Files $addedFiles
Restore-Files $backedUpFiles
#}
}
@@ -503,6 +503,7 @@ $fileText = "{
Ensure-Directory-Exists $dir
Write-Host "Generating global.json file: $(Normalize-FileSystemSlashes "$file")"
+ Track-Added-File $file
Out-File -filePath $file -encoding UTF8 -inputObject $fileText
}
@@ -543,6 +544,7 @@ $fileText = "<!--
Ensure-Directory-Exists $dir
Write-Host "Generating version.props file: $(Normalize-FileSystemSlashes "$file")"
+ Track-Added-File $file
Out-File -filePath $file -encoding UTF8 -inputObject $fileText
}
@@ -675,7 +677,7 @@ function Backup-File([string]$path) {
Copy-Item $path "$path.bak" -Force
$backedUpFiles.Insert(0, $path)
} else {
- Write-Host "Ignoring backup of file $path" -ForegroundColor DarkRed
+ Write-Host "Ignoring backup of file $(Normalize-FileSystemSlashes "$path")" -ForegroundColor DarkRed
}
}
@@ -694,6 +696,35 @@ function Restore-File([string]$path) {
}
}
+function Track-Added-Files([string[]]$paths) {
+ foreach ($path in $paths) {
+ Track-Added-File $path
+ }
+}
+
+function Track-Added-File([string]$path) {
+ if ($backupFiles -eq $true) {
+ $addedFiles.Insert(0, $path)
+ } else {
+ Write-Host "Ignoring tracking of file $(Normalize-FileSystemSlashes "$path")" -ForegroundColor DarkRed
+ }
+}
+
+function Delete-Added-Files([string[]]$paths) {
+ foreach ($path in $paths) {
+ Delete-Added-File $path
+ }
+}
+
+function Delete-Added-File([string]$path) {
+ if ($backupFiles -eq $true) {
+ if (Test-Path "$path") {
+ Remove-Item "$path" -Force
+ }
+ $addedFiles.Remove($path)
+ }
+}
+
function Ensure-Directory-Exists([string] $path) {
if (!(Test-Path $path)) {
New-Item $path -ItemType Directory