From cfec208ebfdc3ba3751173182348e2f287b2892e Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Tue, 17 Jan 2023 14:02:29 +0100 Subject: [PATCH] Switch to github action Signed-off-by: Julien Pivotto --- .circleci/config.yml | 57 +++++++++++------------------ .github/workflows/ci.yml | 77 ++++++++++++++++++++++++++++++++++++++++ .yamllint | 28 +++++++++++++++ main.go | 6 ++-- 4 files changed, 129 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .yamllint diff --git a/.circleci/config.yml b/.circleci/config.yml index 3387e94..965b273 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,48 +1,33 @@ +--- +# Prometheus has switched to GitHub action. +# Circle CI is not disabled repository-wise so that previous pull requests +# continue working. +# This file does not generate any CircleCI workflow. + version: 2.1 -orbs: - prometheus: prometheus/prometheus@0.16.0 + executors: - # Whenever the Go version is updated here, .promu.yml should also be updated. golang: docker: - - image: cimg/go:1.19 + - image: busybox + jobs: - test: + noopjob: executor: golang + steps: - - prometheus/setup_environment - - run: make - - run: git diff --exit-code - - prometheus/store_artifact: - file: influxdb_exporter + - run: + command: "true" + workflows: version: 2 - influxdb_exporter: + prometheus: jobs: - - test: + - noopjob + triggers: + - schedule: + cron: "0 0 30 2 *" filters: - tags: - only: /.*/ - - prometheus/build: - name: build - filters: - tags: - only: /.*/ - - prometheus/publish_master: - context: org-context - requires: - - test - - build - filters: - branches: - only: master - - prometheus/publish_release: - context: org-context - requires: - - test - - build - filters: - tags: - only: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/ branches: - ignore: /.*/ + only: + - main diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6d474dc --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,77 @@ +--- +name: CI +on: # yamllint disable-line rule:truthy + pull_request: + push: +jobs: + test: + name: Test + runs-on: ubuntu-latest + # Whenever the Go version is updated here, .promu.yml + # should also be updated. + container: + image: quay.io/prometheus/golang-builder:1.19-base + steps: + - uses: actions/checkout@v3 + - uses: prometheus/promci@v0.0.2 + - uses: ./.github/promci/actions/setup_environment + - run: make SKIP_GOLANGCI_LINT=1 + build: + name: Build + runs-on: ubuntu-latest + strategy: + matrix: + thread: [ 0, 1, 2, 3, 4, 5 ] + steps: + - uses: actions/checkout@v3 + - uses: prometheus/promci@v0.0.2 + - uses: ./.github/promci/actions/build + with: + parallelism: 6 + thread: ${{ matrix.thread }} + + 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.18' + - name: Lint + uses: golangci/golangci-lint-action@v3.2.0 + with: + version: v1.50.1 + + publish_main: + name: Publish main branch artifacts + runs-on: ubuntu-latest + needs: [test, build] + if: github.event_name == 'push' && github.event.ref == 'refs/heads/main' + steps: + - uses: actions/checkout@v3 + - uses: prometheus/promci@v0.0.2 + - uses: ./.github/promci/actions/publish_main + with: + docker_hub_login: ${{ secrets.docker_hub_login }} + docker_hub_password: ${{ secrets.docker_hub_password }} + quay_io_login: ${{ secrets.quay_io_login }} + quay_io_password: ${{ secrets.quay_io_password }} + + publish_release: + name: Publish release arfefacts + runs-on: ubuntu-latest + needs: [test, build] + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + steps: + - uses: actions/checkout@v3 + - uses: prometheus/promci@v0.0.2 + - uses: ./.github/promci/actions/publish_release + with: + docker_hub_login: ${{ secrets.docker_hub_login }} + docker_hub_password: ${{ secrets.docker_hub_password }} + quay_io_login: ${{ secrets.quay_io_login }} + quay_io_password: ${{ secrets.quay_io_password }} + github_token: ${{ secrets.PROMBOT_GITHUB_TOKEN }} diff --git a/.yamllint b/.yamllint new file mode 100644 index 0000000..3878a31 --- /dev/null +++ b/.yamllint @@ -0,0 +1,28 @@ +--- +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + commas: disable + comments: disable + comments-indentation: disable + document-start: disable + indentation: + spaces: consistent + indent-sequences: consistent + key-duplicates: + ignore: | + config/testdata/section_key_dup.bad.yml + line-length: disable + truthy: + ignore: | + .github/workflows/codeql-analysis.yml + .github/workflows/funcbench.yml + .github/workflows/fuzzing.yml + .github/workflows/prombench.yml + .github/workflows/golangci-lint.yml diff --git a/main.go b/main.go index d2691b5..1364670 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ import ( "compress/gzip" "encoding/json" "fmt" - "io/ioutil" + "io" "net" "net/http" "os" @@ -143,7 +143,7 @@ func (c *influxDBCollector) influxDBPost(w http.ResponseWriter, r *http.Request) JSONErrorResponse(w, fmt.Sprintf("error reading compressed body: %s", err), 500) return } - *bufPointer, err = ioutil.ReadAll(gunzip) + *bufPointer, err = io.ReadAll(gunzip) if err != nil { JSONErrorResponse(w, fmt.Sprintf("error decompressing data: %s", err), 500) return @@ -151,7 +151,7 @@ func (c *influxDBCollector) influxDBPost(w http.ResponseWriter, r *http.Request) } else { bufPointer := &buf var err error - *bufPointer, err = ioutil.ReadAll(r.Body) + *bufPointer, err = io.ReadAll(r.Body) if err != nil { JSONErrorResponse(w, fmt.Sprintf("error reading body: %s", err), 500)