Skip to content

Instantly share code, notes, and snippets.

@ledongthuc
Last active March 23, 2020 08:19
Show Gist options
  • Save ledongthuc/9f3c23018ceca9e993d7ef891b1571e8 to your computer and use it in GitHub Desktop.
Save ledongthuc/9f3c23018ceca9e993d7ef891b1571e8 to your computer and use it in GitHub Desktop.
[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
@Humbalaba
Copy link

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