Skip to content

Commit

Permalink
Merge pull request #43 from digineo/gh-actions
Browse files Browse the repository at this point in the history
ci: improve Github actions
  • Loading branch information
czerwonk authored Mar 19, 2021
2 parents 5fdbccb + 211a04b commit b373dca
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 22 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 15 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
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
with:
args: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

48 changes: 31 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -23,7 +24,7 @@ targets:
- 2001:4860:4860::8888
- 2001:4860:4860::8844
- google.com

dns:
refresh: 2m15s
nameserver: 1.1.1.1
Expand Down

0 comments on commit b373dca

Please sign in to comment.