diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile index c424bc5..7c3742c 100644 --- a/.ci/Jenkinsfile +++ b/.ci/Jenkinsfile @@ -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') @@ -39,7 +38,7 @@ pipeline { axes { axis { name 'GO_VERSION' - values '1.12' + values '1.17', '1.18' } axis { name 'PLATFORM' diff --git a/.ci/scripts/check_format.go b/.ci/scripts/check_format.go deleted file mode 100644 index 9b032e1..0000000 --- a/.ci/scripts/check_format.go +++ /dev/null @@ -1,63 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package main - -import ( - "flag" - "fmt" - "go/build" - "log" - "os" - "os/exec" - "path/filepath" - "strings" -) - -const localPkgs = "github.com/elastic/go-windows" - -var defaultPaths = []string{"."} - -func main() { - log.SetFlags(0) - flag.Parse() - - paths := defaultPaths - if len(flag.Args()) > 0 { - paths = flag.Args() - } - - goGet := exec.Command("go", "get", "-u", "golang.org/x/tools/cmd/goimports") - goGet.Env = os.Environ() - goGet.Env = append(goGet.Env, "GO111MODULE=off") - out, err := goGet.Output() - if err != nil { - log.Fatalf("failed to %v: %v", strings.Join(goGet.Args, " "), err) - } - - goimports := exec.Command(filepath.Join(build.Default.GOPATH, "bin", "goimports"), - append([]string{"-l", "-local", localPkgs}, paths...)...) - out, err = goimports.Output() - if err != nil { - log.Fatalf("failed to %v: %v", strings.Join(goimports.Args, " "), err) - } - if len(out) > 0 { - fmt.Fprintln(os.Stderr, "Run goimports on the code.") - fmt.Printf(string(out)) - os.Exit(1) - } -} diff --git a/.ci/scripts/check_lint.go b/.ci/scripts/check_lint.go deleted file mode 100644 index 43b508a..0000000 --- a/.ci/scripts/check_lint.go +++ /dev/null @@ -1,87 +0,0 @@ -// Licensed to Elasticsearch B.V. under one or more contributor -// license agreements. See the NOTICE file distributed with -// this work for additional information regarding copyright -// ownership. Elasticsearch B.V. licenses this file to you under -// the Apache License, Version 2.0 (the "License"); you may -// not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package main - -import ( - "bufio" - "bytes" - "flag" - "fmt" - "go/build" - "log" - "os" - "os/exec" - "path/filepath" - "regexp" - "strings" -) - -var ignoreWarnings = []string{ - `don't use underscores in Go names`, - `don't use ALL_CAPS in Go names`, -} - -var ignoreWarningsRe = regexp.MustCompile(strings.Join(ignoreWarnings, "|")) - -func main() { - log.SetFlags(0) - flag.Parse() - - goGet := exec.Command("go", "get", "-u", "golang.org/x/lint/golint") - goGet.Env = os.Environ() - goGet.Env = append(goGet.Env, "GO111MODULE=off") - out, err := goGet.Output() - if err != nil { - log.Fatalf("failed to %v: %v", strings.Join(goGet.Args, " "), err) - } - - golint := exec.Command(filepath.Join(build.Default.GOPATH, "bin", "golint"), - flag.Args()...) - golint.Env = os.Environ() - golint.Env = append(golint.Env, "GOOS=windows") - out, err = golint.Output() - if err != nil { - log.Fatalf("failed to %v: %v", strings.Join(golint.Args, " "), err) - } - - out, err = filterIgnores(out) - if err != nil { - log.Fatal(err) - } - - if len(out) > 0 { - log.Println("There are golint warnings.") - fmt.Printf(string(out)) - os.Exit(1) - } -} - -func filterIgnores(out []byte) ([]byte, error) { - var lines [][]byte - s := bufio.NewScanner(bytes.NewReader(out)) - for s.Scan() { - if !ignoreWarningsRe.Match(s.Bytes()) { - lines = append(lines, s.Bytes()) - } - } - var filtered []byte - if len(lines) > 0 { - filtered = append(bytes.Join(lines, []byte("\n")), []byte("\n")...) - } - return filtered, s.Err() -} diff --git a/.ci/scripts/test.bat b/.ci/scripts/test.bat index 20db434..5e4498c 100755 --- a/.ci/scripts/test.bat +++ b/.ci/scripts/test.bat @@ -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" ./... diff --git a/.ci/scripts/test.sh b/.ci/scripts/test.sh index 4399fc2..04e23d4 100755 --- a/.ci/scripts/test.sh +++ b/.ci/scripts/test.sh @@ -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} \ No newline at end of file +go run gotest.tools/gotestsum@latest --no-color -f standard-quiet --jsonfile "$OUTPUT_JSON_FILE" --junitfile "$OUTPUT_JUNIT_FILE" ./... diff --git a/constants.go b/constants.go index 5459d0e..4dfc905 100644 --- a/constants.go +++ b/constants.go @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. +//go:build windows // +build windows package windows diff --git a/go.mod b/go.mod index 1f89547..9f89449 100644 --- a/go.mod +++ b/go.mod @@ -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 +) diff --git a/kernel32.go b/kernel32.go index d618a96..8fc6a8a 100644 --- a/kernel32.go +++ b/kernel32.go @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. +//go:build windows // +build windows package windows diff --git a/kernel32_test.go b/kernel32_test.go index 13929f2..59846a6 100644 --- a/kernel32_test.go +++ b/kernel32_test.go @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. +//go:build windows // +build windows package windows diff --git a/ntdll.go b/ntdll.go index b0b1669..7982fd4 100644 --- a/ntdll.go +++ b/ntdll.go @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. +//go:build windows // +build windows package windows diff --git a/psapi.go b/psapi.go index 7832cdf..7c93926 100644 --- a/psapi.go +++ b/psapi.go @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. +//go:build windows // +build windows package windows diff --git a/version.go b/version.go index e94db87..08e50ae 100644 --- a/version.go +++ b/version.go @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. +//go:build windows // +build windows package windows diff --git a/version_test.go b/version_test.go index 89a2fbe..cc7b954 100644 --- a/version_test.go +++ b/version_test.go @@ -15,6 +15,7 @@ // specific language governing permissions and limitations // under the License. +//go:build windows // +build windows package windows