Skip to content

Commit

Permalink
Adds CI pipeline for Github workflows. (#9)
Browse files Browse the repository at this point in the history
* Implements CI pipelin for Github Actions
  • Loading branch information
wraix authored Nov 10, 2021
1 parent 5040e19 commit 9e4e031
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 4 deletions.
143 changes: 143 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
name: CI
on: [pull_request]
jobs:

gofmt:
name: runner / gofmt
strategy:
matrix:
go-version:
- 1.17.x
os:
- ubuntu-18.04
runs-on: ${{ matrix.os }}
steps:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2

- name: Run gofmt
run: gofmt -w -s .

- name: Run reviewdog (github-pr-suggest)
uses: reviewdog/action-suggester@v1
with:
level: error
fail_on_error: true
tool_name: gofmt
filter_mode: diff_context

govet:
# No need to run govet if gofmt fails...
needs: gofmt
name: runner / govet
strategy:
matrix:
go-version:
- 1.17.x
os:
- ubuntu-18.04
runs-on: ${{ matrix.os }}
steps:

- name: Checkout code
uses: actions/checkout@v2

- name: Check for go.mod
run: test -f go.mod

- uses: reviewdog/action-setup@v1
with:
reviewdog_version: v0.13.0 # Optional. [latest,nightly,v.X.Y.Z]
- name: Run reviewdog govet
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
go vet $(go list ./... | grep -v /vendor/) 2>&1 | reviewdog -efm="vet: %f:%l:%c: %m" -level=error -fail-on-error -reporter=github-pr-review
staticcheck:
needs: govet
name: runner / staticcheck
strategy:
matrix:
go-version:
- 1.17.x
os:
- ubuntu-18.04
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: reviewdog/action-staticcheck@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
reporter: github-pr-review
# Report all results.
filter_mode: nofilter
# Exit with 1 when it find at least one finding.
fail_on_error: false
level: warning
staticcheck_flags: -checks=all -fail none

build:
needs: govet
strategy:
matrix:
go-version:
- 1.17.x
os:
- ubuntu-18.04
goos-arch:
- 'linux/amd64'
- 'linux/arm64'
- 'darwin/amd64'
- 'darwin/arm64'
runs-on: ${{ matrix.os }}
steps:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/[email protected]

- name: Get OS and arch info
run: |
GOOSARCH=${{matrix.goos-arch}}
GOOS=${GOOSARCH%/*}
GOARCH=${GOOSARCH#*/}
BINARY_NAME=${{github.repository}}-$GOOS-$GOARCH
echo "BINARY_NAME=$BINARY_NAME" >> $GITHUB_ENV
echo "GOOS=$GOOS" >> $GITHUB_ENV
echo "GOARCH=$GOARCH" >> $GITHUB_ENV
- name: Build
run: |
go build -o "$BINARY_NAME" -v
test:
needs: build
strategy:
matrix:
go-version:
- 1.17.x
os:
- ubuntu-18.04
runs-on: ${{ matrix.os }}
steps:
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/[email protected]

- name: Build
run: |
go test -v ./...
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
After cloning repo, run:

```
go mod init <new repo eg. github.com/charmixer/golang-api-template>
find . -type f \( -name "*.go" \) -exec sed -i '' 's/charmixer\/golang-api-template/your-repo-name/g' {} +;
go mod init <new repo eg. github.com/username/your-repo-name>
go mod tidy
go run main.go serve
```
Expand Down
6 changes: 3 additions & 3 deletions middleware/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/rs/zerolog/log"
)

func WithLogging() (MiddlewareHandler) {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
func WithLogging() MiddlewareHandler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
tr := otel.Tracer("request")
ctx, span := tr.Start(ctx, "middleware.logging")
Expand Down

0 comments on commit 9e4e031

Please sign in to comment.