diff --git a/.circleci/config.yml b/.circleci/config.yml index 54ff4e8..965b273 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,85 +1,33 @@ --- -version: 2.1 +# 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. -orbs: - prometheus: prometheus/prometheus@0.16.0 +version: 2.1 executors: - test: - parameters: - consul_version: - type: string + golang: docker: - # Whenever the Go version is updated here, .promu.yml should also be updated. - - image: cimg/go:1.19 - - image: consul:<< parameters.consul_version >> - name: consul - environment: - CONSUL_LOCAL_CONFIG: '{"node_name":"test"}' - environment: - CONSUL_SERVER: consul:8500 - CONSUL_NODE_NAME: test + - image: busybox jobs: - test: - parameters: - exec: - type: executor - - executor: << parameters.exec >> + noopjob: + executor: golang steps: - - prometheus/setup_environment - - run: go mod download - - run: make - - run: git diff --exit-code - - prometheus/store_artifact: - file: consul_exporter - - store_test_results: - path: test-results + - run: + command: "true" workflows: version: 2 prometheus: jobs: - - test: - name: test-penultimate - exec: - name: test - consul_version: "1.7" - filters: - tags: - only: /.*/ - - test: - name: test-latest - exec: - name: test - consul_version: "1.8" - filters: - tags: - only: /.*/ - - prometheus/build: - name: build - filters: - tags: - only: /.*/ - - prometheus/publish_master: - context: org-context - requires: - - test-penultimate - - test-latest - - build - filters: - branches: - only: master - - prometheus/publish_release: - context: org-context - requires: - - test-penultimate - - test-latest - - build - filters: - tags: - only: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/ - branches: - ignore: /.*/ + - noopjob + triggers: + - schedule: + cron: "0 0 30 2 *" + filters: + branches: + only: + - main diff --git a/.github/actions/setup_consul/action.yml b/.github/actions/setup_consul/action.yml new file mode 100644 index 0000000..4629513 --- /dev/null +++ b/.github/actions/setup_consul/action.yml @@ -0,0 +1,16 @@ +name: Setup consul +inputs: + version: + type: string + description: Consul version +runs: + using: composite + steps: + - run: curl -Lo consul.zip https://releases.hashicorp.com/consul/${{ inputs.version }}/consul_${{ inputs.version }}_linux_amd64.zip + shell: bash + - run: unzip consul.zip + shell: bash + - run: ./consul agent -dev & + shell: bash + env: + CONSUL_LOCAL_CONFIG: '{"node_name":"test"}' diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml new file mode 100644 index 0000000..28425ad --- /dev/null +++ b/.github/actions/test/action.yml @@ -0,0 +1,18 @@ +name: Test +inputs: + consul_version: + type: string + description: Consul version +runs: + using: composite + steps: + - uses: prometheus/promci@v0.0.2 + - uses: ./.github/promci/actions/setup_environment + - uses: ./.github/actions/setup_consul + with: + version: ${{ inputs.consul_version }} + - run: make + shell: bash + env: + CONSUL_SERVER: localhost:8500 + CONSUL_NODE_NAME: test diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5f6d284 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,90 @@ +--- +name: CI +on: # yamllint disable-line rule:truthy + pull_request: + push: +jobs: + test_latest: + name: Test with latest consul + 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: ./.github/actions/test + with: + consul_version: 1.14.3 + test_older: + name: Test with older consul + 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: ./.github/actions/test + with: + consul_version: 1.12.18 + + build: + name: Build Consul Exporter + 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.19' + - name: Lint + uses: golangci/golangci-lint-action@v3.2.0 + with: + version: v1.49.0 + + publish_main: + name: Publish main branch artifacts + runs-on: ubuntu-latest + needs: [test_latest, test_older, 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_latest, test_older, 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 }}