CodeCheck.ps1 2.3 KB

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