CodeCheck.ps1 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. try {
  15. #
  16. # Solutions
  17. #
  18. Write-Host "Checking that solutions are up to date"
  19. Get-ChildItem "$repoRoot/*.sln" -Recurse | % {
  20. Write-Host " Checking $(Split-Path -Leaf $_)"
  21. $slnDir = Split-Path -Parent $_
  22. $sln = $_
  23. & dotnet sln $_ list `
  24. | ? { $_ -ne 'Project(s)' -and $_ -ne '----------' } `
  25. | % {
  26. $proj = Join-Path $slnDir $_
  27. if (-not (Test-Path $proj)) {
  28. $errors += "Missing project. Solution references a project which does not exist: $proj. [$sln] "
  29. }
  30. }
  31. }
  32. #
  33. # Generated code check
  34. #
  35. Write-Host "Re-running code generation"
  36. Invoke-Block {
  37. [string[]] $generateArgs = @()
  38. if ($ci) {
  39. $generateArgs += '-ci'
  40. }
  41. & $repoRoot/build.cmd /t:GenerateProjectList @generateArgs
  42. }
  43. Write-Host "git diff"
  44. & git diff --ignore-space-at-eol --exit-code
  45. if ($LastExitCode -ne 0) {
  46. $status = git status -s | Out-String
  47. $status = $status -replace "`n","`n "
  48. $errors += "Generated code is not up to date."
  49. }
  50. }
  51. finally {
  52. foreach ($err in $errors) {
  53. Write-Host -f Red "error : $err"
  54. }
  55. if ($errors) {
  56. exit 1
  57. }
  58. }