mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-11-25 23:16:15 +01:00
refactor: move development scripts from Scripts to Tools directory (#881)
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Builds versioned runtime release assets.
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[ValidatePattern('^\d{4}\.\d{2}\.\d{2}(?:-r[1-9]\d*)?$')]
|
||||
[string]$Version,
|
||||
[Parameter(Mandatory)]
|
||||
[string]$OutputDirectory,
|
||||
[string]$SourcePath = (Split-Path -Parent $PSScriptRoot)
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$null = [datetime]::ParseExact($Version.Substring(0, 10), 'yyyy.MM.dd', [cultureinfo]::InvariantCulture)
|
||||
$outputPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($OutputDirectory)
|
||||
New-Item -ItemType Directory -Path $outputPath -Force | Out-Null
|
||||
foreach ($name in 'Win11Debloat.zip', 'SHA256SUMS', 'Get.ps1') {
|
||||
if (Test-Path -LiteralPath (Join-Path $outputPath $name)) {
|
||||
throw "Output already exists: $name. Use a fresh output directory."
|
||||
}
|
||||
}
|
||||
|
||||
$workPath = Join-Path $outputPath ('staging-' + [guid]::NewGuid().ToString('N'))
|
||||
$packageName = "Win11Debloat-$Version"
|
||||
$packagePath = Join-Path $workPath $packageName
|
||||
$archivePath = Join-Path $outputPath 'Win11Debloat.zip'
|
||||
$excludedPaths = @(
|
||||
'.git', '.github', '.gitignore', 'Tests', 'Logs', 'Backups',
|
||||
'Scripts/Build-Release.ps1', 'Scripts/Run-Tests.ps1',
|
||||
'LastUsedSettings.json', 'Config/LastUsedSettings.json'
|
||||
)
|
||||
|
||||
# Prune excluded directories before descending, including output staged inside the source tree.
|
||||
function Copy-ReleaseDirectory([string]$Path, [string]$RelativePath = '') {
|
||||
foreach ($item in Get-ChildItem -LiteralPath $Path -Force) {
|
||||
$relativeItemPath = ($RelativePath + '/' + $item.Name).TrimStart('/')
|
||||
if ($relativeItemPath -in $excludedPaths -or $item.FullName -in @($outputPath, $workPath)) { continue }
|
||||
$destination = Join-Path $packagePath $relativeItemPath
|
||||
if ($item.PSIsContainer) {
|
||||
New-Item -ItemType Directory -Path $destination -Force | Out-Null
|
||||
Copy-ReleaseDirectory $item.FullName $relativeItemPath
|
||||
}
|
||||
else {
|
||||
Copy-Item -LiteralPath $item.FullName -Destination $destination
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
New-Item -ItemType Directory -Path $packagePath -Force | Out-Null
|
||||
Copy-ReleaseDirectory $SourcePath
|
||||
$scriptPath = Join-Path $packagePath 'Win11Debloat.ps1'
|
||||
$text = [IO.File]::ReadAllText($scriptPath)
|
||||
$versionPattern = '(?m)^\$script:Version = "[^"\r\n]+"\r?$'
|
||||
if ([regex]::Matches($text, $versionPattern).Count -ne 1) {
|
||||
throw 'Expected exactly one script version assignment.'
|
||||
}
|
||||
$text = [regex]::Replace($text, $versionPattern, ('$script:Version = "' + $Version + '"'))
|
||||
[IO.File]::WriteAllText($scriptPath, $text, [Text.UTF8Encoding]::new($true))
|
||||
|
||||
Compress-Archive -LiteralPath $packagePath -DestinationPath $archivePath
|
||||
$hash = (Get-FileHash -LiteralPath $archivePath -Algorithm SHA256).Hash.ToLowerInvariant()
|
||||
[IO.File]::WriteAllText((Join-Path $outputPath 'SHA256SUMS'), "$hash Win11Debloat.zip`n", [Text.UTF8Encoding]::new($false))
|
||||
Copy-Item -LiteralPath (Join-Path $packagePath 'Scripts/Get.ps1') -Destination (Join-Path $outputPath 'Get.ps1')
|
||||
}
|
||||
finally {
|
||||
# Only remove this invocation's generated staging directory inside the output directory.
|
||||
$resolvedWorkPath = [IO.Path]::GetFullPath($workPath)
|
||||
if ($resolvedWorkPath.StartsWith($outputPath.TrimEnd('\') + '\', [StringComparison]::OrdinalIgnoreCase) -and (Test-Path -LiteralPath $resolvedWorkPath)) {
|
||||
Remove-Item -LiteralPath $resolvedWorkPath -Recurse -Force
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Runs the Win11Debloat Pester test suite locally.
|
||||
|
||||
.PARAMETER Bootstrap
|
||||
Installs a compatible Pester 5 release for the current user when Pester is
|
||||
not already available.
|
||||
#>
|
||||
[CmdletBinding()]
|
||||
param(
|
||||
[switch]$Bootstrap
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repositoryRoot = Split-Path -Parent $PSScriptRoot
|
||||
$testPath = Join-Path $repositoryRoot 'Tests'
|
||||
|
||||
if (-not (Get-Module -ListAvailable -Name Pester | Where-Object { $_.Version.Major -eq 5 })) {
|
||||
if (-not $Bootstrap) {
|
||||
Write-Error 'Pester 5 is required. Install it with: .\Scripts\Run-Tests.ps1 -Bootstrap'
|
||||
exit 1
|
||||
}
|
||||
|
||||
try {
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
|
||||
|
||||
if (-not (Get-PackageProvider -Name NuGet -ListAvailable -ErrorAction SilentlyContinue)) {
|
||||
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Scope CurrentUser -Force -Confirm:$false | Out-Null
|
||||
}
|
||||
|
||||
Install-Module -Name Pester -RequiredVersion 5.9.0 -Scope CurrentUser -Force -AllowClobber -Confirm:$false
|
||||
}
|
||||
catch {
|
||||
Write-Error "Unable to install Pester 5: $($_.Exception.Message)"
|
||||
exit 1
|
||||
}
|
||||
|
||||
if (-not (Get-Module -ListAvailable -Name Pester | Where-Object { $_.Version.Major -eq 5 })) {
|
||||
Write-Error 'Pester 5 was not installed. Update PowerShellGet or install Pester 5 manually, then run the tests again.'
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
Import-Module Pester -MinimumVersion 5.0.0 -MaximumVersion 5.999.999 -Force
|
||||
$result = Invoke-Pester -Path $testPath -Output Detailed -PassThru
|
||||
|
||||
if ($result.Result -ne 'Passed' -or $result.FailedContainersCount -gt 0 -or $result.TotalCount -eq 0) {
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user