|
1 | | -echo "--- Fixing CRLF in git checkout" |
| 1 | +$ErrorActionPreference = "Stop" # set -e |
| 2 | + |
2 | 3 | # Forcing to checkout again all the files with a correct autocrlf. |
3 | 4 | # Doing this here because we cannot set git clone options before. |
4 | | -git config core.autocrlf input |
5 | | -git rm --quiet --cached -r . |
6 | | -git reset --quiet --hard |
| 5 | +function fixCRLF { |
| 6 | + Write-Host "-- Fixing CRLF in git checkout --" |
| 7 | + git config core.autocrlf input |
| 8 | + git rm --quiet --cached -r . |
| 9 | + git reset --quiet --hard |
| 10 | +} |
| 11 | + |
| 12 | +function withGolang($version) { |
| 13 | + Write-Host "-- Install golang $version --" |
| 14 | + choco install -y golang --version $version |
| 15 | + $env:ChocolateyInstall = Convert-Path "$((Get-Command choco).Path)\..\.." |
| 16 | + Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" |
| 17 | + refreshenv |
| 18 | + go version |
| 19 | + go env |
| 20 | +} |
7 | 21 |
|
8 | | -echo "--- Installing golang" |
9 | | -choco install -y golang --version 1.20.3 |
| 22 | +function installGoDependencies { |
| 23 | + $installPackages = @( |
| 24 | + "github.com/elastic/go-licenser" |
| 25 | + "golang.org/x/tools/cmd/goimports" |
| 26 | + "github.com/jstemmer/go-junit-report/v2" |
| 27 | + "gotest.tools/gotestsum" |
| 28 | + ) |
| 29 | + foreach ($pkg in $installPackages) { |
| 30 | + go install "$pkg@latest" |
| 31 | + } |
| 32 | +} |
10 | 33 |
|
11 | | -echo "--- Updating session environment" |
12 | | -# refreshenv requires to have chocolatey profile installed |
13 | | -$env:ChocolateyInstall = Convert-Path "$((Get-Command choco).Path)\..\.." |
14 | | -Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1" |
| 34 | +fixCRLF |
| 35 | +withGolang $env:GO_VERSION |
15 | 36 |
|
16 | | -refreshenv |
17 | 37 |
|
18 | 38 | echo "--- Downloading Go modules" |
19 | 39 | go version |
20 | 40 | go mod download -x |
21 | 41 |
|
22 | 42 | echo "--- Running unit tests" |
23 | 43 | go version |
24 | | -go test ./... |
| 44 | +$ErrorActionPreference = "Continue" # set +e |
| 45 | +go run gotest.tools/gotestsum --junitfile "$(PWD)/TEST-unit.xml" -- -count=1 ./... |
| 46 | +$EXITCODE=$LASTEXITCODE |
| 47 | +$ErrorActionPreference = "Stop" |
| 48 | + |
| 49 | +Exit $EXITCODE |
0 commit comments