Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds CI pipeline for Github workflows. #9

Merged
merged 7 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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