mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Adds precommit for windows + documentation
This commit is contained in:
90
bin/Invoke-PreCommit.ps1
Normal file
90
bin/Invoke-PreCommit.ps1
Normal file
@@ -0,0 +1,90 @@
|
||||
<#
|
||||
|
||||
Please reference this document:
|
||||
/docs/howtowindows.md
|
||||
|
||||
#>
|
||||
|
||||
#####################################################################################
|
||||
# Start of process
|
||||
#####################################################################################
|
||||
# stop on any error
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
|
||||
Push-Location
|
||||
|
||||
try{
|
||||
$scriptPath = $MyInvocation.MyCommand.Path
|
||||
Write-Host "Script Root: $scriptPath"
|
||||
$baseDir = Split-Path (Split-Path $scriptPath -Parent) -Parent
|
||||
Write-Host "Changing Directory: $baseDir"
|
||||
|
||||
Set-Location $baseDir
|
||||
|
||||
$rc = $false
|
||||
|
||||
function Test-GoLangCILint {
|
||||
golangci-lint -v run ./...
|
||||
}
|
||||
|
||||
function Test-GoTest {
|
||||
go test -v ./...
|
||||
}
|
||||
|
||||
function Test-Examples {
|
||||
mdrip --mode test --label test README.md ./examples
|
||||
}
|
||||
|
||||
# unfortunately because go test hides output in windows if we try to call it
|
||||
# using Invoke-Express ( calling the function dynamically )
|
||||
# we have to call them in-line here instead of using a function
|
||||
|
||||
Write-Host "============== begin Test-GoLangCILint"
|
||||
Test-GoLangCILint
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
$lint = 0
|
||||
$result = "SUCCESS"
|
||||
} else {
|
||||
$lint = 1
|
||||
$result = "FAILURE"
|
||||
}
|
||||
Write-Host ("============== end Test-GoLangCILint : {0} code={1}`n`n`n" -f $result, $lint)
|
||||
|
||||
|
||||
Write-Host "============== begin Test-GoTest"
|
||||
Test-GoTest
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
$tests = 0
|
||||
$result = "SUCCESS"
|
||||
} else {
|
||||
$tests = 1
|
||||
$result = "FAILURE"
|
||||
}
|
||||
Write-Host ("============== end Test-GoTest : {0} code={1}`n`n`n" -f $result, $tests)
|
||||
|
||||
|
||||
Write-Host "============== begin Test-Examples"
|
||||
Test-Examples
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
$examples = 0
|
||||
$result = "SUCCESS"
|
||||
} else {
|
||||
$examples = 1
|
||||
$result = "FAILURE"
|
||||
}
|
||||
Write-Host ("============== end Test-Examples : {0} code={1}`n`n`n" -f $result, $examples)
|
||||
|
||||
#calc final return code
|
||||
$rc = $lint -AND $tests -AND $examples
|
||||
|
||||
Pop-Location
|
||||
|
||||
Exit $rc
|
||||
|
||||
} catch {
|
||||
Write-Host "Error: $_"
|
||||
exit 1
|
||||
}
|
||||
|
||||
Pop-Location
|
||||
54
docs/howtowindows.md
Normal file
54
docs/howtowindows.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# How To Windows
|
||||
|
||||
This is the PowerShell script to run all go tests for Kustomize on a windows based platform which mimics /build/pre-commit.sh
|
||||
|
||||
## Pre-Reqs:
|
||||
- (obviously) PowerShell installed
|
||||
- PowerShell Core is supported
|
||||
- go installed
|
||||
- golangci-lint installed
|
||||
- mdrip installed
|
||||
|
||||
This script should output to the current console and return an exit code if all tests are successful(0) or any failed(1).
|
||||
|
||||
### If you are tryin to run these tests locally you can follow these instructions.
|
||||
|
||||
Assume:
|
||||
- Running a stock Windows 10 system
|
||||
- Local Admin rights.
|
||||
- You can open [PowerShell as administrator](http://lmgtfy.com/?iie=1&q=How+to+open+powershell+as+administrator)
|
||||
- You should be knowledgeable enough to pull source for packages into your GO ```src``` directory
|
||||
- Yes, this means you also need to know a bit about **git** usually
|
||||
|
||||
|
||||
#### Step 1 - Install Go
|
||||
- [Install Go](https://golang.org/dl/) - please use the msi
|
||||
- If you use chocolatey - it's using the zip not msi and assumptions on where go is located are made for you.
|
||||
#### Step 2 - Install Go Packages
|
||||
- Open new PowerShell Administrative window
|
||||
- Install golangci-lint
|
||||
- ```go get -u github.com/golangci/golangci-lint/cmd/golangci-lint```
|
||||
- Install mdrip
|
||||
- ```go get github.com/monopole/mdrip```
|
||||
|
||||
You should now be able to issue these commands and see comparable responses
|
||||
|
||||
```
|
||||
C:\...> golangci-lint --help
|
||||
Smart, fast linters runner. Run it in cloud for every GitHub pull request on https://golangci.com
|
||||
...
|
||||
|
||||
C:\...> mdrip --help
|
||||
Usage: C:\_go\bin\mdrip.exe {fileName}...
|
||||
...
|
||||
```
|
||||
|
||||
#### Step 3 - Get Source and Test
|
||||
- In your GoRoot src
|
||||
- ```Example: C:\_go\src```
|
||||
- Navigate to the Kustomize bin directory
|
||||
- ```Example: C:\_go\src\sigs.k8s.io\kustomize\bin```
|
||||
- Now Execute:
|
||||
- ```.\Invoke-PreCommit.ps1```
|
||||
|
||||
This should run all pre-commit tests thus defined in the script.
|
||||
Reference in New Issue
Block a user