Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

90 lignes
3.5KB

  1. <#
  2. Builds a deployable release folder for the Purple Envelope Orders Site.
  3. "Build" for this Classic ASP app just means: assemble the exact file set that should ship
  4. to production, with the production web.config swapped in. There's no compile step.
  5. - Archives the given git ref via `git archive`, which respects .gitattributes
  6. export-ignore rules (drops docs/, tests/, .claude/, dev-only config, etc. - see
  7. .gitattributes for the full list).
  8. - Enforces $KeepTopLevel below as the authoritative allow-list: anything extracted from
  9. the archive that isn't on this list gets deleted. This is the real safety net - a file
  10. added to the repo root later and never added to .gitattributes would otherwise ship to
  11. production by default. Here, it has to be explicitly added to $KeepTopLevel to ship.
  12. - Overwrites public/web.config in the archive with public/web.config.production.template.
  13. - Leaves the assembled tree in -OutDir, ready to zip and ship.
  14. Usage:
  15. powershell -File scripts\build-release.ps1
  16. powershell -File scripts\build-release.ps1 -Ref master -OutDir dist\release
  17. #>
  18. param(
  19. [string]$Ref = 'HEAD',
  20. [string]$OutDir = ''
  21. )
  22. $ErrorActionPreference = 'Stop'
  23. # Everything the live site needs to run: app code, framework internals, the IIS root, and
  24. # the migration runner (+ its generator siblings, harmless to ship alongside it). Only
  25. # db\migrations is kept under db - never db\webdata.accdb, even if something ever put a
  26. # stray copy there.
  27. $KeepTopLevel = @('app', 'core', 'public', 'scripts')
  28. $KeepUnderDb = @('migrations')
  29. $repoRoot = Split-Path $PSScriptRoot -Parent
  30. Push-Location $repoRoot
  31. try {
  32. if([string]::IsNullOrWhiteSpace($OutDir)){
  33. $OutDir = Join-Path $repoRoot ('dist\release_' + (Get-Date -Format 'yyyyMMdd_HHmmss'))
  34. }
  35. if(Test-Path $OutDir){
  36. Remove-Item -Recurse -Force $OutDir
  37. }
  38. New-Item -ItemType Directory -Force -Path $OutDir | Out-Null
  39. $templatePath = Join-Path $repoRoot 'public\web.config.production.template'
  40. if(!(Test-Path $templatePath)){
  41. throw "public\web.config.production.template not found - can't build a production release without it."
  42. }
  43. Write-Host "Archiving $Ref (honoring .gitattributes export-ignore rules)..."
  44. $archivePath = Join-Path $OutDir '_archive.zip'
  45. git archive --format=zip --output $archivePath $Ref
  46. if($LASTEXITCODE -ne 0){ throw 'git archive failed' }
  47. Expand-Archive -Path $archivePath -DestinationPath $OutDir -Force
  48. Remove-Item $archivePath
  49. Write-Host "Pruning to the allow-list: $($KeepTopLevel -join ', '), db\$($KeepUnderDb -join ', db\')"
  50. Get-ChildItem -Path $OutDir -Force | ForEach-Object {
  51. if($_.Name -notin $KeepTopLevel){
  52. Write-Host " removing (not on allow-list): $($_.Name)"
  53. Remove-Item -Recurse -Force $_.FullName
  54. }
  55. }
  56. $dbDir = Join-Path $OutDir 'db'
  57. if(Test-Path $dbDir){
  58. Get-ChildItem -Path $dbDir -Force | ForEach-Object {
  59. if($_.Name -notin $KeepUnderDb){
  60. Write-Host " removing (not on allow-list): db\$($_.Name)"
  61. Remove-Item -Recurse -Force $_.FullName
  62. }
  63. }
  64. }
  65. if(!(Test-Path (Join-Path $OutDir 'public'))){
  66. throw "Release has no public\ folder after pruning - check `$KeepTopLevel in this script"
  67. }
  68. $liveConfig = Join-Path $OutDir 'public\web.config'
  69. Copy-Item $templatePath $liveConfig -Force
  70. Remove-Item (Join-Path $OutDir 'public\web.config.production.template') -ErrorAction SilentlyContinue
  71. Write-Host "Release built at $OutDir"
  72. Write-Host " public\web.config swapped in from web.config.production.template"
  73. } finally {
  74. Pop-Location
  75. }

Powered by TurnKey Linux.