CodeCheck.ps1 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. Write-Host "Checking that solutions are up to date"
  23. Get-ChildItem "$repoRoot/*.sln" -Recurse | % {
  24. Write-Host " Checking $(Split-Path -Leaf $_)"
  25. $slnDir = Split-Path -Parent $_
  26. $sln = $_
  27. & dotnet sln $_ list `
  28. | ? { $_ -ne 'Project(s)' -and $_ -ne '----------' } `
  29. | % {
  30. $proj = Join-Path $slnDir $_
  31. if (-not (Test-Path $proj)) {
  32. LogError "Missing project. Solution references a project which does not exist: $proj. [$sln] "
  33. }
  34. }
  35. }
  36. #
  37. # Generated code check
  38. #
  39. Write-Host "Re-running code generation"
  40. Write-Host "Re-generating ProjectReference.props"
  41. Invoke-Block {
  42. [string[]] $generateArgs = @()
  43. if ($ci) {
  44. $generateArgs += '-ci'
  45. }
  46. & $repoRoot/build.cmd /t:GenerateProjectList @generateArgs
  47. }
  48. Write-Host "Re-generating package baselines"
  49. $dotnet = 'dotnet'
  50. if ($ci) {
  51. $dotnet = "$repoRoot/.dotnet/x64/dotnet.exe"
  52. }
  53. Invoke-Block {
  54. & $dotnet run -p "$repoRoot/eng/tools/BaselineGenerator/"
  55. }
  56. Write-Host "git diff"
  57. & git diff --ignore-space-at-eol --exit-code
  58. if ($LastExitCode -ne 0) {
  59. $status = git status -s | Out-String
  60. $status = $status -replace "`n","`n "
  61. LogError "Generated code is not up to date."
  62. }
  63. }
  64. finally {
  65. Write-Host ""
  66. Write-Host "Summary:"
  67. Write-Host ""
  68. Write-Host " $($errors.Length) error(s)"
  69. Write-Host ""
  70. foreach ($err in $errors) {
  71. Write-Host -f Red "error : $err"
  72. }
  73. if ($errors) {
  74. exit 1
  75. }
  76. }