Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
Merge pull request #21 from andrerun/golang-1-8
Browse files Browse the repository at this point in the history
Update to golang 1.18, replace linter, update project structure
  • Loading branch information
istvanballok authored Sep 6, 2022
2 parents acedfb2 + 25f9768 commit de1728b
Show file tree
Hide file tree
Showing 2,114 changed files with 501,500 additions and 329,869 deletions.
2 changes: 1 addition & 1 deletion .ci/build
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ GIT_SHA=$(git rev-parse --short HEAD || echo "GitNotFound")
CGO_ENABLED=0 GO111MODULE=off go build \
-v \
-o ${BINARY_PATH}/vpa-exporter \
main.go
cmd/main.go
39 changes: 2 additions & 37 deletions .ci/check
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,6 @@ else
export SOURCE_PATH="$(readlink -f ${SOURCE_PATH})"
fi

VCS="github.com"
ORGANIZATION="gardener"
PROJECT="vpa-exporter"
REPOSITORY=${VCS}/${ORGANIZATION}/${PROJECT}
cd "${SOURCE_PATH}"

# The `go <cmd>` commands requires to see the target repository to be part of a
# Go workspace. Thus, if we are not yet in a Go workspace, let's create one
# temporarily by using symbolic links.
if [[ "${SOURCE_PATH}" != *"src/${REPOSITORY}" ]]; then
SOURCE_SYMLINK_PATH="${SOURCE_PATH}/tmp/src/${REPOSITORY}"
if [[ -d "${SOURCE_PATH}/tmp" ]]; then
rm -rf "${SOURCE_PATH}/tmp"
fi
mkdir -p "${SOURCE_PATH}/tmp/src/${VCS}/${ORGANIZATION}"
ln -s "${SOURCE_PATH}" "${SOURCE_SYMLINK_PATH}"
cd "${SOURCE_SYMLINK_PATH}"

export GOPATH="${SOURCE_PATH}/tmp"
export GOBIN="${SOURCE_PATH}/tmp/bin"
export PATH="${GOBIN}:${PATH}"
fi

# Install Golint (linting tool).
go get -u golang.org/x/lint/golint

###############################################################################

PACKAGES="$(go list -e ./... | grep -vE '/tmp/|/vendor/')"
LINT_FOLDERS="$(echo ${PACKAGES} | sed "s|github.com/gardener/vpa-exporter|.|g")"

# Execute static code checks.
go vet ${PACKAGES}

# Execute automatic code formatting directive.
go fmt ${PACKAGES}

# Execute lint checks.
golint -set_exit_status ${LINT_FOLDERS}
make check
5 changes: 1 addition & 4 deletions .ci/test
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ if [[ "${SOURCE_PATH}" != *"src/${REPOSITORY}" ]]; then
export PATH="${GOBIN}:${PATH}"
fi

# Install Ginkgo (test framework) to be able to execute the tests.
go get -u github.com/onsi/ginkgo/ginkgo

###############################################################################

function test_with_coverage() {
Expand All @@ -70,7 +67,7 @@ function test_with_coverage() {
################################################################################

TEST_PACKAGES="."
GINKGO_COMMON_FLAGS="-r -timeout=1h0m0s --randomizeAllSpecs --randomizeSuites --failOnPending --progress"
GINKGO_COMMON_FLAGS="-r -timeout=1h0m0s --randomize-all --randomize-suites --fail-on-pending --progress"
if [ -z $COVER ] || [ "$COVER" = false ] ; then
echo "[INFO] Test coverage is disabled."
ginkgo -race -trace $GINKGO_COMMON_FLAGS ${TEST_PACKAGES}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test/output
test/e2e_test_data

# IDE config
.idea
.vscode

# developers workspace
Expand Down
22 changes: 22 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
run:
concurrency: 4
deadline: 10m
# some of the linters don't work correctly with 1.18, ref https://github.com/golangci/golangci-lint/issues/2649
# we are not using generics, so let's pin this to 1.17 until 1.18 is fully supported
go: "1.17"

linters:
enable:
- gocritic
- gosec
- revive

skip-files:
- "zz_generated\\..*\\.go$"

issues:
exclude-use-default: false
exclude:
# - var-naming # ((var|const|struct field|func) .* should be .*
- dot-imports # should not use dot imports
- "exported: (type|func) name will be used as .* by other packages, and that stutters;"
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ IMAGE_TAG := $(VERSION)
BUILD_DIR := build
BIN_DIR := bin

TOOLS_DIR := hack/tools
include hack/tools.mk

.PHONY: revendor
revendor:
@dep ensure -update -v
@GO111MODULE=on go mod tidy
@GO111MODULE=on go mod vendor

.PHONY: build
build:
Expand All @@ -41,11 +45,13 @@ clean:
@rm -rf $(BIN_DIR)/

.PHONY: check
check:
@.ci/check
check: $(GOLANGCI_LINT)
@go vet ./cmd/...
@go fmt ./cmd/...
@hack/check.sh --golangci-lint-config=./.golangci.yaml ./cmd/...

.PHONY: test
test:
test: $(GINKGO)
@.ci/test

.PHONY: verify
Expand Down
2 changes: 1 addition & 1 deletion build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.18 as builder
FROM golang:1.18.5 as builder
WORKDIR /go/src/github.com/gardener/vpa-exporter
COPY . .

Expand Down
Loading

0 comments on commit de1728b

Please sign in to comment.