CodeCheck.ps1 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.ps1 -ci /t:InstallDotNet
  24. }
  25. Write-Host "Checking that Versions.props and Version.Details.xml match"
  26. [xml] $versionProps = Get-Content "$repoRoot/eng/Versions.props"
  27. [xml] $versionDetails = Get-Content "$repoRoot/eng/Version.Details.xml"
  28. foreach ($dep in $versionDetails.SelectNodes('//ProductDependencies/Dependency')) {
  29. Write-Verbose "Found $dep"
  30. $varName = $dep.Name -replace '\.',''
  31. $varName = $varName -replace '\-',''
  32. $varName = "${varName}PackageVersion"
  33. $versionVar = $versionProps.SelectSingleNode("//PropertyGroup[`@Label=`"Automated`"]/$varName")
  34. if (-not $versionVar) {
  35. LogError "Missing version variable '$varName' in the 'Automated' property group in $repoRoot/eng/Versions.props"
  36. continue
  37. }
  38. $expectedVersion = $dep.Version
  39. $actualVersion = $versionVar.InnerText
  40. if ($expectedVersion -ne $actualVersion) {
  41. LogError "Version variable '$varName' does not match the value in Version.Details.xml. Expected '$expectedVersion', actual '$actualVersion'"
  42. }
  43. }
  44. Write-Host "Checking that solutions are up to date"
  45. Get-ChildItem "$repoRoot/*.sln" -Recurse `
  46. | ? {
  47. # This .sln file is used by the templating engine.
  48. $_.Name -ne "RazorComponentsWeb-CSharp.sln"
  49. } `
  50. | % {
  51. Write-Host " Checking $(Split-Path -Leaf $_)"
  52. $slnDir = Split-Path -Parent $_
  53. $sln = $_
  54. & dotnet sln $_ list `
  55. | ? { $_ -ne 'Project(s)' -and $_ -ne '----------' } `
  56. | % {
  57. $proj = Join-Path $slnDir $_
  58. if (-not (Test-Path $proj)) {
  59. LogError "Missing project. Solution references a project which does not exist: $proj. [$sln] "
  60. }
  61. }
  62. }
  63. #
  64. # Generated code check
  65. #
  66. Write-Host "Re-running code generation"
  67. Write-Host "Re-generating project lists"
  68. Invoke-Block {
  69. & $PSScriptRoot\GenerateProjectList.ps1 -ci:$ci
  70. }
  71. Write-Host "Re-generating package baselines"
  72. $dotnet = 'dotnet'
  73. if ($ci) {
  74. $dotnet = "$repoRoot/.dotnet/x64/dotnet.exe"
  75. }
  76. Invoke-Block {
  77. & $dotnet run -p "$repoRoot/eng/tools/BaselineGenerator/"
  78. }
  79. Write-Host "git diff"
  80. & git diff --ignore-space-at-eol --exit-code
  81. if ($LastExitCode -ne 0) {
  82. $status = git status -s | Out-String
  83. $status = $status -replace "`n","`n "
  84. LogError "Generated code is not up to date."
  85. }
  86. }
  87. finally {
  88. Write-Host ""
  89. Write-Host "Summary:"
  90. Write-Host ""
  91. Write-Host " $($errors.Length) error(s)"
  92. Write-Host ""
  93. foreach ($err in $errors) {
  94. Write-Host -f Red "error : $err"
  95. }
  96. if ($errors) {
  97. exit 1
  98. }
  99. }