run_flake8.ps1 925 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env pwsh
  2. $ExitCode = 0
  3. $GitDiff = git diff origin/master
  4. # If there is no diff between master, then flake8 everything.
  5. if ( $GitDiff -eq $null ) {
  6. flake8 .
  7. if ($LastExitCode -ne 0) { $ExitCode = $LastExitCode }
  8. }
  9. # Else flake8 just the diff.
  10. else {
  11. Write-Output $GitDiff | flake8 --diff
  12. if ($LastExitCode -ne 0) { $ExitCode = $LastExitCode }
  13. # If the project_template changed, then flake8 the testproject too.
  14. $GitDiffTempl = Write-Output $GitDiff | Select-String -Pattern "^diff .*/project_template/.*"
  15. if ( $GitDiffTempl -ne $null ) {
  16. flake8 testproject
  17. if ($LastExitCode -ne 0) { $ExitCode = $LastExitCode }
  18. }
  19. }
  20. # Write friendly output
  21. if ($ExitCode -eq 0) {
  22. Write-Host -ForegroundColor Green "[✔] Flake8 passed with no errors"
  23. }
  24. else {
  25. Write-Host -ForegroundColor Red "[❌] Flake8 exited with errors. Please resolve issues above."
  26. }
  27. exit $ExitCode