Skip to content

Commit

Permalink
fix: add explicit go directive (#19)
Browse files Browse the repository at this point in the history
* fix: add explicit go directive

A missing go directive can lead to inconsistent
behaviour between go versions.

See https://go.dev/doc/go1.17#missing-go-directive

Add an explicit directive to target Go 1.17.

* ci: run tests on the two most recent versions of Go

* ci: replace go scripts with posix compliant scripts

* fix: resolve goimports issues

* ci: remove GO111MODULE env from ci

As of Go 1.16 module-aware mode is enabled by default so
GO111MODULE=on is no longer needed.

See https://go.dev/doc/go1.16#go-command

This should also help with forward compatibility as
GOPATH and GO111MODULE will be removed in the future,

See https://github.com/golang/go/wiki/GOPATH#deprecating-and-removing-gopath-development-mode

* ci: fix windows bat script

* test.bat: propagate the status code to the script's exit code

Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co>

* lint: set exit status if golint fails

* sh: add set -e to shell scripts

* test.bat: propagate status codes of other commands

* ci: replace golint with staticcheck

golint is deprecated and this is consistent with what
we're doing in other repositories.

* ci: move lint scripts in the main test script

Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co>
  • Loading branch information
kruskall and andrewkroh authored Jul 26, 2022
1 parent f367fbe commit 548f212
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 179 deletions.
3 changes: 1 addition & 2 deletions .ci/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pipeline {
BASE_DIR = "src/github.com/elastic/${env.REPO}"
JOB_GIT_CREDENTIALS = "f6c7695a-671e-4f4f-a331-acdce44ff9ba"
PIPELINE_LOG_LEVEL = 'INFO'
GO111MODULE = 'on'
}
options {
timeout(time: 1, unit: 'HOURS')
Expand Down Expand Up @@ -39,7 +38,7 @@ pipeline {
axes {
axis {
name 'GO_VERSION'
values '1.12'
values '1.17', '1.18'
}
axis {
name 'PLATFORM'
Expand Down
63 changes: 0 additions & 63 deletions .ci/scripts/check_format.go

This file was deleted.

87 changes: 0 additions & 87 deletions .ci/scripts/check_lint.go

This file was deleted.

26 changes: 12 additions & 14 deletions .ci/scripts/test.bat
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
set
set GO111MODULE=off
go get -u github.com/elastic/go-licenser
set GO111MODULE=on
go mod verify
go-licenser -d
go run .ci/scripts/check_format.go
go run .ci/scripts/check_lint.go

mkdir -p build
SET OUT_FILE=build\output-report.out
go test "./..." -v > %OUT_FILE% | type %OUT_FILE%
go get -v -u github.com/jstemmer/go-junit-report
go-junit-report > build\junit-%GO_VERSION%.xml < %OUT_FILE%

go mod verify || EXIT /B 1
go run github.com/elastic/go-licenser@latest -d || EXIT /B 1

go run honnef.co/go/tools/cmd/staticcheck@2022.1 ./... || EXIT /B 1

go run golang.org/x/tools/cmd/goimports@latest -l -local github.com/elastic/go-windows . || EXIT /B 1

SET OUTPUT_JSON_FILE=build\output-report.out
SET OUTPUT_JUNIT_FILE=build\junit-%GO_VERSION%.xml

go run gotest.tools/gotestsum@latest --no-color -f standard-quiet --jsonfile "$OUTPUT_JSON_FILE" --junitfile "$OUTPUT_JUNIT_FILE" ./...
27 changes: 14 additions & 13 deletions .ci/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#!/usr/bin/env bash
set -euxo pipefail
#!/bin/sh

set -e

GO111MODULE=off go get -u github.com/elastic/go-licenser
go mod verify
go-licenser -d
go run .ci/scripts/check_format.go
go run .ci/scripts/check_lint.go
go run github.com/elastic/go-licenser@latest -d
go run honnef.co/go/tools/cmd/staticcheck@2022.1 ./...
out=$(go run golang.org/x/tools/cmd/goimports@latest -l -local github.com/elastic/go-windows .)

if [ ! -z "$out" ]; then
printf "Run goimports on the code.\n"
exit 1
fi

# Run the tests
set +e
export OUT_FILE="build/test-report.out"
export OUTPUT_JSON_FILE="build/test-report.out"
export OUTPUT_JUNIT_FILE="build/junit-${GO_VERSION}.xml"
mkdir -p build
go test -v ./... | tee ${OUT_FILE}
status=$?
go get -v -u github.com/jstemmer/go-junit-report
go-junit-report > "build/junit-${GO_VERSION}.xml" < ${OUT_FILE}

exit ${status}
go run gotest.tools/gotestsum@latest --no-color -f standard-quiet --jsonfile "$OUTPUT_JSON_FILE" --junitfile "$OUTPUT_JUNIT_FILE" ./...
1 change: 1 addition & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

//go:build windows
// +build windows

package windows
Expand Down
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
module github.com/elastic/go-windows

go 1.17

require (
github.com/pkg/errors v0.8.1
github.com/stretchr/testify v1.3.0
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
)
1 change: 1 addition & 0 deletions kernel32.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

//go:build windows
// +build windows

package windows
Expand Down
1 change: 1 addition & 0 deletions kernel32_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

//go:build windows
// +build windows

package windows
Expand Down
1 change: 1 addition & 0 deletions ntdll.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

//go:build windows
// +build windows

package windows
Expand Down
1 change: 1 addition & 0 deletions psapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

//go:build windows
// +build windows

package windows
Expand Down
1 change: 1 addition & 0 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

//go:build windows
// +build windows

package windows
Expand Down
1 change: 1 addition & 0 deletions version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

//go:build windows
// +build windows

package windows
Expand Down

0 comments on commit 548f212

Please sign in to comment.