Powershell scripts (#525)

* port scripts to ps

* remove ps core features

* init script

* make it work on ps 5.0

* sync with make file

* cleanup

* cleanup

* review feedback

* newline
This commit is contained in:
marpio
2018-08-24 19:44:36 +02:00
committed by Michal Pristas
parent 7c137a736b
commit fa16c6950b
7 changed files with 273 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
$benchFiles = Get-ChildItem -Recurse -Filter "*storage*test.go" | Resolve-Path -Relative | Select-String -Pattern $(Join-Path "vendor" "") -NotMatch
& go test -v $benchFiles -bench=. -run=^$
+7
View File
@@ -0,0 +1,7 @@
# check_gofmt.ps1
# Fail if a .go file hasn't been formatted with gofmt
$GO_FILES = Get-ChildItem -Recurse -Filter *.go -Name | Select-String -Pattern $(Join-Path "vendor" | Join-Path -ChildPath "") -NotMatch
$out = & gofmt -s -l $GO_FILES
if ($out.length -gt 0) {
Write-Error $out
}
+7
View File
@@ -0,0 +1,7 @@
# check_golint.ps1
# Run the linter on everything
$out = & golint -set_exit_status $(& go list ./...)
if ($LastExitCode -ne 0) {
Write-Error $out
}
+6
View File
@@ -0,0 +1,6 @@
# install_dev_deps.ps1
# Ensure that the tools needed to build locally are present
& go get github.com/golang/lint/golint
& go get github.com/golang/dep/cmd/dep
& go get github.com/gobuffalo/buffalo/buffalo
+78
View File
@@ -0,0 +1,78 @@
# Execute end-to-end (e2e) tests to verify that everything is working right
# from the end user perpsective
Get-Process -Name *buffalo*
$repoDir = Join-Path $PSScriptRoot ".." | Join-Path -ChildPath ".."
if (-not (Test-Path env:GO_BINARY_PATH)) { $env:GO_BINARY_PATH = "go" }
$globalTmpDir = [System.IO.Path]::GetTempPath()
$tmpDirName = [GUID]::NewGuid()
$testGoPath = Join-Path $globalTmpDir $tmpDirName
$origGOPATH = $env:GOPATH
$origGOPROXY = $env:GOPROXY
New-Item $testGoPath -ItemType Directory | Out-Null
$goModCache = Join-Path $testGoPath "pkg" | Join-Path -ChildPath "mod"
$env:Path += ";" + "${$(Join-Path $repoDir "bin")}"
function clearGoModCache () {
Get-ChildItem -Path $goModCache -Recurse | Remove-Item -Recurse -Force -Confirm:$false
}
function stopProcesses () {
Get-Process -Name buffalo* -ErrorAction SilentlyContinue | Stop-Process -Force
Get-Process -Name athens-build* -ErrorAction SilentlyContinue | Stop-Process -Force
}
function teardown () {
# Cleanup after our tests
$env:GOPATH = $origGOPATH
$env:GOPROXY = $origGOPROXY
stopProcesses
# clean test gopath
Get-ChildItem -Path $testGoPath -Recurse | Remove-Item -Recurse -Force -Confirm:$false
Pop-Location
Pop-Location
}
try {
## Start the proxy in the background and wait for it to be ready
Push-Location $(Join-Path $repoDir cmd | Join-Path -ChildPath proxy)
## just in case something is still running
stopProcesses
Start-Process -NoNewWindow buffalo dev
$proxyUp = $false
do {
try {
$proxyUp = (Invoke-WebRequest -Method GET -Uri http://localhost:3000/healthz).StatusCode -eq "200"
}
catch {
Start-Sleep -Seconds 5
}
} while(-not $proxyUp)
## Clone our test repo
$testSource = Join-Path $testGoPath "happy-path"
git clone https://github.com/athens-artifacts/happy-path.git ${testSource}
Push-Location ${testSource}
## set modules on after running buffalo dev, not sure why
## issue https://github.com/gomods/athens/issues/412
$env:GO111MODULE = "on"
$env:GOPATH = $testGoPath
## Make sure that our test repo works without the GOPROXY first
if (Test-Path env:GOPROXY) { Remove-Item env:GOPROXY }
& $env:GO_BINARY_PATH run .
clearGoModCache
## Verify that the test works against the proxy
$env:GOPROXY = "http://localhost:3000"
& $env:GO_BINARY_PATH run .
}
finally {
teardown
}
+15
View File
@@ -0,0 +1,15 @@
# Run the unit tests with the race detector and code coverage enabled
$envPath = Join-Path "cmd" "proxy" | Join-Path -ChildPath ".env"
Get-Content $envPath | ForEach-Object {
$line = $_.ToString().Split("=")
if ($line.Length -ne 2) {
return
}
$name = $line[0]
$val = $line[1]
[System.Environment]::SetEnvironmentVariable($name, $val)
}
& go test -race -coverprofile cover.out -covermode atomic ./...