Skip to content

Commit da88d74

Browse files
committed
Update build
* Update Go CI to 1.22. * Update Go modules. * Sync files from prometheus/prometheus. Signed-off-by: SuperQ <[email protected]>
1 parent 9eac3ea commit da88d74

File tree

6 files changed

+366
-1450
lines changed

6 files changed

+366
-1450
lines changed

.circleci/config.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2.1
33
executors:
44
golang:
55
docker:
6-
- image: cimg/go:1.18
6+
- image: cimg/go:1.22
77
jobs:
88
test:
99
executor: golang
@@ -104,4 +104,4 @@ workflows:
104104
tags:
105105
only: /v[0-9]+(\.[0-9]+)*(-.*)*/
106106
orbs:
107-
prometheus: prometheus/prometheus@0.11.0
107+
prometheus: prometheus/prometheus@0.17.1

.github/dependabot.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ updates:
33
- package-ecosystem: gomod
44
directory: "/"
55
schedule:
6-
interval: daily
6+
interval: monthly
77
open-pull-requests-limit: 10
88
ignore:
99
- dependency-name: github.com/prometheus/common

.github/workflows/golangci-lint.yml

+29-12
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
1+
---
2+
# This action is synced from https://github.com/prometheus/prometheus
13
name: golangci-lint
24
on:
35
push:
4-
tags:
5-
- v*
6-
branches:
7-
- master
6+
paths:
7+
- "go.sum"
8+
- "go.mod"
9+
- "**.go"
10+
- "scripts/errcheck_excludes.txt"
11+
- ".github/workflows/golangci-lint.yml"
12+
- ".golangci.yml"
813
pull_request:
14+
15+
permissions: # added using https://github.com/step-security/secure-repo
16+
contents: read
17+
918
jobs:
1019
golangci:
20+
permissions:
21+
contents: read # for actions/checkout to fetch code
22+
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
1123
name: lint
1224
runs-on: ubuntu-latest
1325
steps:
14-
- uses: actions/checkout@v3
15-
- name: golangci-lint
16-
uses: golangci/golangci-lint-action@v3
26+
- name: Checkout repository
27+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
28+
- name: Install Go
29+
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
1730
with:
18-
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
19-
version: v1.29
20-
only_new_issues: true
21-
# Optional: golangci-lint command line arguments.
22-
# args: ./the-only-dir-to-analyze/...
31+
go-version: 1.22.x
32+
- name: Install snmp_exporter/generator dependencies
33+
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
34+
if: github.repository == 'prometheus/snmp_exporter'
35+
- name: Lint
36+
uses: golangci/golangci-lint-action@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1
37+
with:
38+
args: --verbose
39+
version: v1.59.1

Makefile.common

+277
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,277 @@
1+
# Copyright 2018 The Prometheus Authors
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
15+
# A common Makefile that includes rules to be reused in different prometheus projects.
16+
# !!! Open PRs only against the prometheus/prometheus/Makefile.common repository!
17+
18+
# Example usage :
19+
# Create the main Makefile in the root project directory.
20+
# include Makefile.common
21+
# customTarget:
22+
# @echo ">> Running customTarget"
23+
#
24+
25+
# Ensure GOBIN is not set during build so that promu is installed to the correct path
26+
unexport GOBIN
27+
28+
GO ?= go
29+
GOFMT ?= $(GO)fmt
30+
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
31+
GOOPTS ?=
32+
GOHOSTOS ?= $(shell $(GO) env GOHOSTOS)
33+
GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH)
34+
35+
GO_VERSION ?= $(shell $(GO) version)
36+
GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))
37+
PRE_GO_111 ?= $(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.(10|[0-9])\.')
38+
39+
PROMU := $(FIRST_GOPATH)/bin/promu
40+
pkgs = ./...
41+
42+
ifeq (arm, $(GOHOSTARCH))
43+
GOHOSTARM ?= $(shell GOARM= $(GO) env GOARM)
44+
GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)v$(GOHOSTARM)
45+
else
46+
GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)
47+
endif
48+
49+
GOTEST := $(GO) test
50+
GOTEST_DIR :=
51+
ifneq ($(CIRCLE_JOB),)
52+
ifneq ($(shell command -v gotestsum 2> /dev/null),)
53+
GOTEST_DIR := test-results
54+
GOTEST := gotestsum --junitfile $(GOTEST_DIR)/unit-tests.xml --
55+
endif
56+
endif
57+
58+
PROMU_VERSION ?= 0.17.0
59+
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
60+
61+
SKIP_GOLANGCI_LINT :=
62+
GOLANGCI_LINT :=
63+
GOLANGCI_LINT_OPTS ?=
64+
GOLANGCI_LINT_VERSION ?= v1.59.1
65+
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
66+
# windows isn't included here because of the path separator being different.
67+
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
68+
ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386 arm64))
69+
# If we're in CI and there is an Actions file, that means the linter
70+
# is being run in Actions, so we don't need to run it here.
71+
ifneq (,$(SKIP_GOLANGCI_LINT))
72+
GOLANGCI_LINT :=
73+
else ifeq (,$(CIRCLE_JOB))
74+
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
75+
else ifeq (,$(wildcard .github/workflows/golangci-lint.yml))
76+
GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
77+
endif
78+
endif
79+
endif
80+
81+
PREFIX ?= $(shell pwd)
82+
BIN_DIR ?= $(shell pwd)
83+
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
84+
DOCKERFILE_PATH ?= ./Dockerfile
85+
DOCKERBUILD_CONTEXT ?= ./
86+
DOCKER_REPO ?= prom
87+
88+
DOCKER_ARCHS ?= amd64
89+
90+
BUILD_DOCKER_ARCHS = $(addprefix common-docker-,$(DOCKER_ARCHS))
91+
PUBLISH_DOCKER_ARCHS = $(addprefix common-docker-publish-,$(DOCKER_ARCHS))
92+
TAG_DOCKER_ARCHS = $(addprefix common-docker-tag-latest-,$(DOCKER_ARCHS))
93+
94+
SANITIZED_DOCKER_IMAGE_TAG := $(subst +,-,$(DOCKER_IMAGE_TAG))
95+
96+
ifeq ($(GOHOSTARCH),amd64)
97+
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux freebsd darwin windows))
98+
# Only supported on amd64
99+
test-flags := -race
100+
endif
101+
endif
102+
103+
# This rule is used to forward a target like "build" to "common-build". This
104+
# allows a new "build" target to be defined in a Makefile which includes this
105+
# one and override "common-build" without override warnings.
106+
%: common-% ;
107+
108+
.PHONY: common-all
109+
common-all: precheck style check_license lint yamllint unused build test
110+
111+
.PHONY: common-style
112+
common-style:
113+
@echo ">> checking code style"
114+
@fmtRes=$$($(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print)); \
115+
if [ -n "$${fmtRes}" ]; then \
116+
echo "gofmt checking failed!"; echo "$${fmtRes}"; echo; \
117+
echo "Please ensure you are using $$($(GO) version) for formatting code."; \
118+
exit 1; \
119+
fi
120+
121+
.PHONY: common-check_license
122+
common-check_license:
123+
@echo ">> checking license header"
124+
@licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \
125+
awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
126+
done); \
127+
if [ -n "$${licRes}" ]; then \
128+
echo "license header checking failed:"; echo "$${licRes}"; \
129+
exit 1; \
130+
fi
131+
132+
.PHONY: common-deps
133+
common-deps:
134+
@echo ">> getting dependencies"
135+
$(GO) mod download
136+
137+
.PHONY: update-go-deps
138+
update-go-deps:
139+
@echo ">> updating Go dependencies"
140+
@for m in $$($(GO) list -mod=readonly -m -f '{{ if and (not .Indirect) (not .Main)}}{{.Path}}{{end}}' all); do \
141+
$(GO) get -d $$m; \
142+
done
143+
$(GO) mod tidy
144+
145+
.PHONY: common-test-short
146+
common-test-short: $(GOTEST_DIR)
147+
@echo ">> running short tests"
148+
$(GOTEST) -short $(GOOPTS) $(pkgs)
149+
150+
.PHONY: common-test
151+
common-test: $(GOTEST_DIR)
152+
@echo ">> running all tests"
153+
$(GOTEST) $(test-flags) $(GOOPTS) $(pkgs)
154+
155+
$(GOTEST_DIR):
156+
@mkdir -p $@
157+
158+
.PHONY: common-format
159+
common-format:
160+
@echo ">> formatting code"
161+
$(GO) fmt $(pkgs)
162+
163+
.PHONY: common-vet
164+
common-vet:
165+
@echo ">> vetting code"
166+
$(GO) vet $(GOOPTS) $(pkgs)
167+
168+
.PHONY: common-lint
169+
common-lint: $(GOLANGCI_LINT)
170+
ifdef GOLANGCI_LINT
171+
@echo ">> running golangci-lint"
172+
$(GOLANGCI_LINT) run $(GOLANGCI_LINT_OPTS) $(pkgs)
173+
endif
174+
175+
.PHONY: common-lint-fix
176+
common-lint-fix: $(GOLANGCI_LINT)
177+
ifdef GOLANGCI_LINT
178+
@echo ">> running golangci-lint fix"
179+
$(GOLANGCI_LINT) run --fix $(GOLANGCI_LINT_OPTS) $(pkgs)
180+
endif
181+
182+
.PHONY: common-yamllint
183+
common-yamllint:
184+
@echo ">> running yamllint on all YAML files in the repository"
185+
ifeq (, $(shell command -v yamllint 2> /dev/null))
186+
@echo "yamllint not installed so skipping"
187+
else
188+
yamllint .
189+
endif
190+
191+
# For backward-compatibility.
192+
.PHONY: common-staticcheck
193+
common-staticcheck: lint
194+
195+
.PHONY: common-unused
196+
common-unused:
197+
@echo ">> running check for unused/missing packages in go.mod"
198+
$(GO) mod tidy
199+
@git diff --exit-code -- go.sum go.mod
200+
201+
.PHONY: common-build
202+
common-build: promu
203+
@echo ">> building binaries"
204+
$(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
205+
206+
.PHONY: common-tarball
207+
common-tarball: promu
208+
@echo ">> building release tarball"
209+
$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)
210+
211+
.PHONY: common-docker-repo-name
212+
common-docker-repo-name:
213+
@echo "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)"
214+
215+
.PHONY: common-docker $(BUILD_DOCKER_ARCHS)
216+
common-docker: $(BUILD_DOCKER_ARCHS)
217+
$(BUILD_DOCKER_ARCHS): common-docker-%:
218+
docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" \
219+
-f $(DOCKERFILE_PATH) \
220+
--build-arg ARCH="$*" \
221+
--build-arg OS="linux" \
222+
$(DOCKERBUILD_CONTEXT)
223+
224+
.PHONY: common-docker-publish $(PUBLISH_DOCKER_ARCHS)
225+
common-docker-publish: $(PUBLISH_DOCKER_ARCHS)
226+
$(PUBLISH_DOCKER_ARCHS): common-docker-publish-%:
227+
docker push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)"
228+
229+
DOCKER_MAJOR_VERSION_TAG = $(firstword $(subst ., ,$(shell cat VERSION)))
230+
.PHONY: common-docker-tag-latest $(TAG_DOCKER_ARCHS)
231+
common-docker-tag-latest: $(TAG_DOCKER_ARCHS)
232+
$(TAG_DOCKER_ARCHS): common-docker-tag-latest-%:
233+
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:latest"
234+
docker tag "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(SANITIZED_DOCKER_IMAGE_TAG)" "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:v$(DOCKER_MAJOR_VERSION_TAG)"
235+
236+
.PHONY: common-docker-manifest
237+
common-docker-manifest:
238+
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create -a "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)" $(foreach ARCH,$(DOCKER_ARCHS),$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$(ARCH):$(SANITIZED_DOCKER_IMAGE_TAG))
239+
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME):$(SANITIZED_DOCKER_IMAGE_TAG)"
240+
241+
.PHONY: promu
242+
promu: $(PROMU)
243+
244+
$(PROMU):
245+
$(eval PROMU_TMP := $(shell mktemp -d))
246+
curl -s -L $(PROMU_URL) | tar -xvzf - -C $(PROMU_TMP)
247+
mkdir -p $(FIRST_GOPATH)/bin
248+
cp $(PROMU_TMP)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM)/promu $(FIRST_GOPATH)/bin/promu
249+
rm -r $(PROMU_TMP)
250+
251+
.PHONY: proto
252+
proto:
253+
@echo ">> generating code from proto files"
254+
@./scripts/genproto.sh
255+
256+
ifdef GOLANGCI_LINT
257+
$(GOLANGCI_LINT):
258+
mkdir -p $(FIRST_GOPATH)/bin
259+
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/$(GOLANGCI_LINT_VERSION)/install.sh \
260+
| sed -e '/install -d/d' \
261+
| sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION)
262+
endif
263+
264+
.PHONY: precheck
265+
precheck::
266+
267+
define PRECHECK_COMMAND_template =
268+
precheck:: $(1)_precheck
269+
270+
PRECHECK_COMMAND_$(1) ?= $(1) $$(strip $$(PRECHECK_OPTIONS_$(1)))
271+
.PHONY: $(1)_precheck
272+
$(1)_precheck:
273+
@if ! $$(PRECHECK_COMMAND_$(1)) 1>/dev/null 2>&1; then \
274+
echo "Execution of '$$(PRECHECK_COMMAND_$(1))' command failed. Is $(1) installed?"; \
275+
exit 1; \
276+
fi
277+
endef

go.mod

+25-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,41 @@
11
module github.com/prometheus-community/promql-langserver
22

3-
go 1.13
3+
go 1.21
44

55
require (
66
github.com/blang/semver v3.5.1+incompatible
77
github.com/go-kit/kit v0.12.0
88
github.com/google/uuid v1.3.0
9-
github.com/hashicorp/errwrap v1.1.0 // indirect
109
github.com/kelseyhightower/envconfig v1.4.0
1110
github.com/pkg/errors v0.9.1
12-
github.com/prometheus/client_golang v1.12.2
13-
github.com/prometheus/common v0.35.0
11+
github.com/prometheus/client_golang v1.19.1
12+
github.com/prometheus/common v0.48.0
1413
github.com/prometheus/prometheus v0.36.2
1514
github.com/rakyll/statik v0.1.7
1615
github.com/sahilm/fuzzy v0.1.0
1716
github.com/stretchr/testify v1.8.0
1817
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f
1918
gopkg.in/yaml.v3 v3.0.1
2019
)
20+
21+
require (
22+
github.com/beorn7/perks v1.0.1 // indirect
23+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
24+
github.com/davecgh/go-spew v1.1.1 // indirect
25+
github.com/dennwc/varint v1.0.0 // indirect
26+
github.com/go-kit/log v0.2.1 // indirect
27+
github.com/go-logfmt/logfmt v0.5.1 // indirect
28+
github.com/grafana/regexp v0.0.0-20220304095617-2e8d9baf4ac2 // indirect
29+
github.com/json-iterator/go v1.1.12 // indirect
30+
github.com/julienschmidt/httprouter v1.3.0 // indirect
31+
github.com/kylelemons/godebug v1.1.0 // indirect
32+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
33+
github.com/modern-go/reflect2 v1.0.2 // indirect
34+
github.com/pmezard/go-difflib v1.0.0 // indirect
35+
github.com/prometheus/client_model v0.5.0 // indirect
36+
github.com/prometheus/procfs v0.12.0 // indirect
37+
go.uber.org/atomic v1.9.0 // indirect
38+
go.uber.org/goleak v1.1.12 // indirect
39+
golang.org/x/sys v0.17.0 // indirect
40+
google.golang.org/protobuf v1.33.0 // indirect
41+
)

0 commit comments

Comments
 (0)