diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..b73ed94 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,42 @@ +name: Lint + +on: + push: + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + env: + GO_VERSION: "1.16" + steps: + - name: Set up Go ${{ env.GO_VERSION }} + uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: | + ~/go/pkg/mod # Module download cache + ~/.cache/go-build # Build cache (Linux) + key: ${{ runner.os }}-${{ env.GO_VERSION }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-${{ env.GO_VERSION }}-go- + + - name: Check and get dependencies + run: | + go mod tidy + git diff --exit-code go.mod + git diff --exit-code go.sum + go mod download + + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: v1.38 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 491a69c..c6176a1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,21 +1,33 @@ +name: Release + on: push: tags: - '*.*.*' -name: Release jobs: goreleaser: name: Create Release runs-on: ubuntu-latest + env: + GO_VERSION: "1.16" steps: - name: Checkout code uses: actions/checkout@v2 - - name: Set up Go + - name: Set up Go ${{ env.GO_VERSION }} uses: actions/setup-go@v2 with: - go-version: 1.16 + go-version: ${{ env.GO_VERSION }} + + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: | + ~/go/pkg/mod # Module download cache + ~/.cache/go-build # Build cache (Linux) + key: ${{ runner.os }}-${{ env.GO_VERSION }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-${{ env.GO_VERSION }}-go- - name: Run GoReleaser uses: goreleaser/goreleaser-action@v2 @@ -23,4 +35,3 @@ jobs: args: release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 957dccb..b0ee94b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,28 +1,42 @@ +name: Test + on: push: - branches: - - master pull_request: - branches: - - master -name: Test jobs: test: strategy: matrix: go-version: [1.16.x] platform: [ubuntu-latest, macos-latest, windows-latest] - runs-on: ${{ matrix.platform }} + runs-on: "${{ matrix.platform }}" + env: + CGO_ENABLED: 0 steps: - - name: Install Go - if: success() - uses: actions/setup-go@v2 - with: - go-version: ${{ matrix.go-version }} - - name: Checkout code - uses: actions/checkout@v2 - - name: Build - run: go build - - name: Run tests - run: go test ./... -v -covermode=count + - name: Setup Go ${{ matrix.go-version }} + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: | + ~/go/pkg/mod # Module download cache + ~/.cache/go-build # Build cache (Linux) + ~/Library/Caches/go-build # Build cache (Mac) + '%LocalAppData%\go-build' # Build cache (Windows) + key: ${{ runner.os }}-${{ matrix.go-version }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-${{ matrix.go-version }}-go- + + - name: Build + run: go build -v -ldflags="-s -w" -trimpath -o ping_exporter + + - name: Test + run: go test ./... -v -covermode=count diff --git a/README.md b/README.md index df5789e..2cdf2c2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # ping_exporter +[![Test results](https://github.com/github.com/czerwonk/ping_exporter/workflows/Test/badge.svg)](https://github.com/github.com/czerwonk/ping_exporter/actions?query=workflow%3ATest) [![Docker Build Statu](https://img.shields.io/docker/build/czerwonk/ping_exporter.svg)](https://hub.docker.com/r/czerwonk/ping_exporter/builds) [![Go Report Card](https://goreportcard.com/badge/github.com/czerwonk/ping_exporter)](https://goreportcard.com/report/github.com/czerwonk/ping_exporter) @@ -23,7 +24,7 @@ targets: - 2001:4860:4860::8888 - 2001:4860:4860::8844 - google.com - + dns: refresh: 2m15s nameserver: 1.1.1.1