CodeCheck.ps1 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #requires -version 5
  2. <#
  3. .SYNOPSIS
  4. This script runs a quick check for common errors, such as checking that Visual Studio solutions are up to date or that generated code has been committed to source.
  5. #>
  6. param(
  7. [switch]$ci
  8. )
  9. $ErrorActionPreference = 'Stop'
  10. Set-StrictMode -Version 1
  11. Import-Module -Scope Local -Force "$PSScriptRoot/common.psm1"
  12. $repoRoot = Resolve-Path "$PSScriptRoot/../../"
  13. [string[]] $errors = @()
  14. function LogError([string]$message) {
  15. Write-Host -f Red "error: $message"
  16. $script:errors += $message
  17. }
  18. try {
  19. #
  20. # Solutions
  21. #
  22. if ($ci) {
  23. & $repoRoot/build.cmd /t:InstallDotNet
  24. }
  25. Write-Host "Checking that solutions are up to date"
  26. Get-ChildItem "$repoRoot/*.sln" -Recurse `
  27. | ? {
  28. # This .sln file is used by the templating engine.
  29. $_.Name -ne "RazorComponentsWeb-CSharp.sln"
  30. } `
  31. | % {
  32. Write-Host " Checking $(Split-Path -Leaf $_)"
  33. $slnDir = Split-Path -Parent $_
  34. $sln = $_
  35. & dotnet sln $_ list `
  36. | ? { $_ -ne 'Project(s)' -and $_ -ne '----------' } `
  37. | % {
  38. $proj = Join-Path $slnDir $_
  39. if (-not (Test-Path $proj)) {
  40. LogError "Missing project. Solution references a project which does not exist: $proj. [$sln] "
  41. }
  42. }
  43. }
  44. #
  45. # Generated code check
  46. #
  47. Write-Host "Re-running code generation"
  48. Write-Host "Re-generating ProjectReference.props"
  49. Invoke-Block {
  50. [string[]] $generateArgs = @()
  51. if ($ci) {
  52. $generateArgs += '-ci'
  53. }
  54. & $repoRoot/build.cmd /t:GenerateProjectList @generateArgs
  55. }
  56. Write-Host "Re-generating package baselines"
  57. $dotnet = 'dotnet'
  58. if ($ci) {
  59. $dotnet = "$repoRoot/.dotnet/x64/dotnet.exe"
  60. }
  61. Invoke-Block {
  62. & $dotnet run -p "$repoRoot/eng/tools/BaselineGenerator/"
  63. }
  64. Write-Host "git diff"
  65. & git diff --ignore-space-at-eol --exit-code
  66. if ($LastExitCode -ne 0) {
  67. $status = git status -s | Out-String
  68. $status = $status -replace "`n","`n "
  69. LogError "Generated code is not up to date."
  70. }
  71. }
  72. finally {
  73. Write-Host ""
  74. Write-Host "Summary:"
  75. Write-Host ""
  76. Write-Host " $($errors.Length) error(s)"
  77. Write-Host ""
  78. foreach ($err in $errors) {
  79. Write-Host -f Red "error : $err"
  80. }
  81. if ($errors) {
  82. exit 1
  83. }
  84. }