From 76c3ae19528f942d42750ca6042f5421d28ef08e Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Wed, 20 Dec 2023 22:57:09 +0100 Subject: [PATCH] Update CI (#183) * Split golangci-lint to separate action file so it's auto-updated. * Update Go version in CI. * Update minimum Go version. * Remove deprecated rand.Seed(). Signed-off-by: SuperQ --- .github/workflows/ci.yml | 30 +++++++++------------------ .github/workflows/golangci-lint.yml | 32 +++++++++++++++++++++++++++++ .golangci.yml | 7 ++++++- go.mod | 2 +- web/cache.go | 5 ----- 5 files changed, 49 insertions(+), 27 deletions(-) create mode 100644 .github/workflows/golangci-lint.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4382f7c9..8a6f3aae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,31 +1,21 @@ ---- name: CI -on: # yamllint disable-line rule:truthy - pull_request: +on: push: jobs: test: name: Test runs-on: ubuntu-latest + strategy: + matrix: + go_version: ["1.20", "1.21"] container: - image: quay.io/prometheus/golang-builder:1.20-base + image: quay.io/prometheus/golang-builder:${{ matrix.go_version }}-base + env: + # Override Go 1.18 security deprecations. + GODEBUG: "x509sha1=1,tls10default=1" steps: - - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: prometheus/promci@v0.0.2 - uses: ./.github/promci/actions/setup_environment - run: make test - - golangci: - name: golangci-lint - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - name: Install Go - uses: actions/setup-go@v3 - with: - go-version: '1.20' - - name: Lint - uses: golangci/golangci-lint-action@v3.4.0 - with: - version: v1.51.2 diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 00000000..ffa6b309 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,32 @@ +--- +# This action is synced from https://github.com/prometheus/prometheus +name: golangci-lint +on: + push: + paths: + - "go.sum" + - "go.mod" + - "**.go" + - "scripts/errcheck_excludes.txt" + - ".github/workflows/golangci-lint.yml" + - ".golangci.yml" + pull_request: + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + - name: install Go + uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0 + with: + go-version: 1.21.x + - name: Install snmp_exporter/generator dependencies + run: sudo apt-get update && sudo apt-get -y install libsnmp-dev + if: github.repository == 'prometheus/snmp_exporter' + - name: Lint + uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0 + with: + version: v1.54.2 diff --git a/.golangci.yml b/.golangci.yml index a1265d5f..eab4efe0 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -17,4 +17,9 @@ linters-settings: - (net/http.ResponseWriter).Write # Never check for logger errors. - (github.com/go-kit/log.Logger).Log - + revive: + rules: + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter + - name: unused-parameter + severity: warning + disabled: true diff --git a/go.mod b/go.mod index a8dd26bc..82ed21f6 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/prometheus/exporter-toolkit -go 1.18 +go 1.20 require ( github.com/alecthomas/kingpin/v2 v2.4.0 diff --git a/web/cache.go b/web/cache.go index 9425e7ac..252928ee 100644 --- a/web/cache.go +++ b/web/cache.go @@ -18,15 +18,10 @@ package web import ( weakrand "math/rand" "sync" - "time" ) var cacheSize = 100 -func init() { - weakrand.Seed(time.Now().UnixNano()) -} - type cache struct { cache map[string]bool mtx sync.Mutex