From c4417371ef3c75bd31628a56740dbb3bde81143d Mon Sep 17 00:00:00 2001 From: lpdyck Date: Sat, 1 Sep 2018 03:59:55 -0600 Subject: [PATCH] Fix powershell scripts (#615) * add check_deps.ps1 * fix check_gofmt select-string regex pattern * capitalize JoinPath * fix typo * fail check_deps.ps1 on error --- init.ps1 | 2 +- scripts/check_deps.sh | 2 +- scripts/ps/check_deps.ps1 | 17 +++++++++++++++++ scripts/ps/check_gofmt.ps1 | 2 +- 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 scripts/ps/check_deps.ps1 diff --git a/init.ps1 b/init.ps1 index 6726277e..29a7fcb9 100644 --- a/init.ps1 +++ b/init.ps1 @@ -51,7 +51,7 @@ Param( [switch]$down ) function execScript($name) { - $scriptsDir = "$(join-path scripts ps)" + $scriptsDir = "$(Join-Path scripts ps)" & "$(Join-Path $scriptsDir $name)" } diff --git a/scripts/check_deps.sh b/scripts/check_deps.sh index e9c4156f..0d5a2d08 100755 --- a/scripts/check_deps.sh +++ b/scripts/check_deps.sh @@ -14,7 +14,7 @@ set -xeuo pipefail git remote set-branches --add origin master && git fetch ChangedFiles=`git diff --name-only origin/master` -# in the casse that ChangedFiles contains go.mod or go.sum run go mod verify +# in the case that ChangedFiles contains go.mod or go.sum run go mod verify case "$ChangedFiles" in go.mod | go.sum) go mod verify diff --git a/scripts/ps/check_deps.ps1 b/scripts/ps/check_deps.ps1 new file mode 100644 index 00000000..d718fee1 --- /dev/null +++ b/scripts/ps/check_deps.ps1 @@ -0,0 +1,17 @@ +# check_deps.ps1 +# this script checks for changes to the files go.mod and go.sum +# +# this is intended to be used in your CI tests +# +# on encountering any changes for these files the script runs go mod verify +# to check for any conflicts in versions or digests +# which on any exit code > 0 would suggest that action should be taken +# before a pull request can be merged. +git remote set-branches --add origin master ; git fetch +$ChangedFiles=$(git diff --name-only origin/master) + +# in the case that ChangedFiles contains go.mod or go.sum run go mod verify +$contains= $ChangedFiles | Select-String -Pattern "go.mod|go.sum" +if ($contains.length -gt 0) { + Write-Error $(go mod verify) +} \ No newline at end of file diff --git a/scripts/ps/check_gofmt.ps1 b/scripts/ps/check_gofmt.ps1 index 909a1374..972fd4d3 100755 --- a/scripts/ps/check_gofmt.ps1 +++ b/scripts/ps/check_gofmt.ps1 @@ -1,6 +1,6 @@ # 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 +$GO_FILES = Get-ChildItem -Recurse -Filter *.go -Name | Select-String -Pattern $(Join-Path "vendor" -ChildPath ".*") -NotMatch $out = & gofmt -s -l $GO_FILES if ($out.length -gt 0) { Write-Error $out