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

add workflow for golang code quality #4

Merged
merged 3 commits into from
Aug 4, 2024
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
50 changes: 50 additions & 0 deletions .github/workflows/golang_quality.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
on:
workflow_call:
inputs:
workdir:
required: false
default: "./"
type: string

jobs:
golangci:
runs-on: ubuntu-latest
if: "!startsWith(github.ref, 'refs/tags/')"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: v1.22.5
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59
working-directory: "${{ inputs.workdir }}"
go_tidy:
runs-on: ubuntu-latest
if: "!startsWith(github.ref, 'refs/tags/')"
container:
image: cubicrootxyz/golang-ci:v1.22.5-3
options: --user root
steps:
- uses: actions/checkout@v4
- run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Run go mod tidy
run: (cd ${{ inputs.workdir }} && go mod tidy)
- name: Run git diff
run: git diff --exit-code
go_generate:
runs-on: ubuntu-latest
if: "!startsWith(github.ref, 'refs/tags/')"
container:
image: cubicrootxyz/golang-ci:v1.22.5-3
options: --user root
steps:
- uses: actions/checkout@v4
- run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Install mockgen
run: go install github.com/golang/mock/[email protected]
- name: Run go generate
run: go generate ${{ inputs.workdir }}...
- name: Run git diff
run: git diff --exit-code
7 changes: 7 additions & 0 deletions .github/workflows/golang_quality_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
on: push

jobs:
golang_quality:
uses: ./.github/workflows/golang_quality.yaml
with:
workdir: "tests/golang_quality"
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,17 @@ jobs:
dockerhub_user: ${{ secrets.DOCKERHUB_USERNAME }}
dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }}
```

## Golang

### Code Quality

To ensure code quality use the provided `golang_quality` workflow. It runs multiple analysis tools.

```yaml
jobs:
golang_quality:
uses: ./.github/workflows/golang_quality.yaml
with:
workdir: "golang/application/subfolder"
```
3 changes: 3 additions & 0 deletions tests/golang_quality/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module golang_quality

go 1.22.1
7 changes: 7 additions & 0 deletions tests/golang_quality/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("I am used for testing CI workflows")
}
Loading