Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Github Actions][Go] Check pull requests before merging

Create template actions that's used to verify Go language pull requests before merging. It's easy to custom the flow, tools with your case.

Put pr_checker.yml or pr_checker_simple.yml to .github/workflows/ and see how it works with your pull requests. Make sure you are allows to use actions of Github.

  • pr_checker.yml is using by mine with full checking tools. It will make sure every Go langauge pull requests will be buildable, testable, passed security checking and error-able code checking.
  • pr_checker_simple.yml is more simpler with buildable, testable.

References:

name: Go
on:
pull_request:
branches:
- feature/*
push:
branches:
- feature/*
jobs:
review:
name: Review code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Check styling error
uses: "cedrickring/golang-action@1.3.0"
with:
args: go get -u golang.org/x/lint/golint; go list ./... | grep -v /vendor/ | xargs -L1 golint -set_exit_status
- name: Check missing error check
uses: "cedrickring/golang-action@1.3.0"
with:
args: go get -u github.com/kisielk/errcheck; ls -la; errcheck ./...
- name: Check suspicious constructs (1)
uses: "cedrickring/golang-action@1.3.0"
with:
args: go get honnef.co/go/tools/cmd/staticcheck; staticcheck -checks all ./... # https://staticcheck.io/docs/checks
- name: Check suspicious constructs (2)
uses: "cedrickring/golang-action@1.3.0"
with:
args: go vet ./...
security:
name: Review security
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Check missing error check
uses: "cedrickring/golang-action@1.3.0"
with:
args: go get github.com/securego/gosec/cmd/gosec; gosec ./... # https://github.com/securego/gosec
testable:
name: Testable
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: build
uses: "cedrickring/golang-action@1.3.0"
with:
args: go test ./...
buildable:
name: Buildable
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: build
uses: "cedrickring/golang-action@1.3.0"
with:
args: go build ./cmd/api/main.go
name: Go
on:
pull_request:
branches:
- feature/*
push:
branches:
- feature/*
jobs:
testable:
name: Testable
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: build
uses: "cedrickring/golang-action@1.3.0"
with:
args: go test ./...
buildable:
name: Buildable
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: build
uses: "cedrickring/golang-action@1.3.0"
with:
args: go build ./cmd/api/main.go
@lebaviethung

This comment has been minimized.

Copy link

commented Aug 22, 2019

very handy, thanks a ton and love much! 😚

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.