Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Action #256

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 19 additions & 71 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions .github/actions/setup_consul/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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 -node test &
shell: bash
18 changes: 18 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -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
90 changes: 90 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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.8

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 }}