Skip to content

Instantly share code, notes, and snippets.

@Harold2017
Created September 16, 2019 09:56
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Harold2017/d98607f242659ca65e731c688cb92707 to your computer and use it in GitHub Desktop.
Save Harold2017/d98607f242659ca65e731c688cb92707 to your computer and use it in GitHub Desktop.
github actions golang, build, test, codecov

build

name: build
on: [push]
jobs:

  build:
    name: Build
    runs-on: ubuntu-latest
    steps:

    - name: Set up Go 1.12
      uses: actions/setup-go@v1
      with:
        go-version: 1.12
      id: go

    - name: Check out code into the Go module directory
      uses: actions/checkout@v1

    - name: Get dependencies
      run: |
        go get -v -t -d ./...
        if [ -f Gopkg.toml ]; then
            curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
            dep ensure
        fi

    - name: Build
      run: go build -v .

codecov

name: codecov
on: [push]
jobs:

  codecov:
    name: codecov
    runs-on: ubuntu-latest
    steps:

      - name: Set up Go 1.12
        uses: actions/setup-go@v1
        with:
          go-version: 1.12
        id: go

      - name: Check out code into the Go module directory
        uses: actions/checkout@v1

      - name: Get dependencies
        run: |
          go get -v -t -d ./...
          if [ -f Gopkg.toml ]; then
              curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
              dep ensure
          fi

      - name: Generate coverage report
        run: |
          go test `go list ./... | grep -v examples` -coverprofile=coverage.txt -covermode=atomic

      - name: Upload coverage report
        uses: codecov/codecov-action@v1.0.2
        with:
          token: {{your codecov token, can be found at https://codecov.io/gh/<github_username>/<repo>/settings/badge}}
          file: ./coverage.txt
          flags: unittests
          name: codecov-umbrella

add badges to README.md

[![Actions Status](https://github.com/<github_username>/<repo>/workflows/build/badge.svg)](https://github.com/<github_username>/<repo>/actions)
[![codecov](https://codecov.io/gh/<github_username>/<repo>/branch/master/graph/badge.svg)](https://codecov.io/gh/<github_username>/<repo>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment