Skip to content

Commit

Permalink
feat: modernize CI
Browse files Browse the repository at this point in the history
  • Loading branch information
robinmuhia committed Sep 5, 2024
1 parent c00a30c commit 1d58e5e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 65 deletions.
51 changes: 29 additions & 22 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,56 @@ env:
HEALTH_CRM_BASE_URL: ${{ secrets.HEALTH_CRM_BASE_URL }}

jobs:
lint_and_test:
golangci:
strategy:
fail-fast: true
matrix:
go-version: [1.18.x]
go-version: [1.23.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest

lint_and_test:
needs: [golangci]
strategy:
matrix:
go-version: [1.23.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
timeout-minutes: 80
steps:
- uses: actions/checkout@v3.1.0
- uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v3.3.1
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Install Go dependencies
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.37.1
curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.13.1
go install honnef.co/go/tools/cmd/[email protected]
go install github.com/ory/go-acc@latest
go install github.com/axw/gocov/gocov@latest
go install github.com/kisielk/errcheck@latest
go mod download
go get github.com/axw/gocov/gocov
go get github.com/ory/go-acc
go install github.com/ory/go-acc
go install github.com/axw/gocov/gocov
- name: Run lint and test
- name: Run tests
run: |
staticcheck ./...
go fmt $(go list ./... | grep -v /vendor/)
go vet $(go list ./... | grep -v /vendor/)
errcheck -ignore 'os:.*,' $(go list ./... | grep -v /vendor/)
gosec -exclude=G304,G101 ./...
go-acc -o coverage.txt --ignore generated,cmd ./... -- -timeout 60m
grep -v "generated.go" coverage.txt > coverage.out
go tool cover -html=coverage.out -o coverage.html
gocov convert coverage.out > coverage.json
gocov report coverage.json > coverage_report.txt
tail coverage_report.txt
- name: Install goveralls
env:
GO111MODULE: off
run: go get github.com/mattn/goveralls
- name: Install goveralls
run: GO111MODULE=on go install github.com/mattn/goveralls@latest
- name: Send coverage
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
82 changes: 42 additions & 40 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
# Options for analysis running.
run:
skip-dirs:
- pkg/mycarehub/presentation/graph/
linters:
disable-all: true
enable:
- deadcode
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- structcheck
- typecheck
- unused
- varcheck
- asciicheck
- bodyclose
- dogsled
- exhaustive
- exportloopref
- gocognit
- goconst
- gofmt
- goheader
- goimports
- gosec
- misspell
- nakedret
- nestif
- noctx
- rowserrcheck
- sqlclosecheck
- unconvert
- unparam
- whitespace
- gocyclo
- golint
timeout: 10m
concurrency: 4

linters:
disable-all: true
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
- asciicheck
- bodyclose
- dogsled
- exhaustive
- gocognit
- gofmt
- goheader
- goimports
- gosec
- misspell
- nakedret
- nestif
- noctx
- rowserrcheck
- sqlclosecheck
- unconvert
- unparam
- whitespace
- gocyclo

linters-settings:
staticcheck:
checks: ["all"]
linters-settings:
staticcheck:
checks: ["all"]
funlen:
lines: -1
statements: -1
gosec:
excludes:
- G601
- G304
- G101
2 changes: 0 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,13 @@ func (cl *client) MakeRequest(ctx context.Context, method, path string, queryPar

default:
return nil, fmt.Errorf("s.MakeRequest() unsupported http method: %s", method)

}

request.Header.Set("Accept", "application/json")
request.Header.Set("Content-Type", "application/json")
request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", oauthResponse.AccessToken))

if queryParams != nil {

request.URL.RawQuery = queryParams.Encode()
}

Expand Down
3 changes: 3 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,11 @@ func TestMakeRequest(t *testing.T) {
response, err := mockClient.MakeRequest(ctx, tt.method, tt.path, tt.queryParams, tt.body)
if err != nil {
t.Errorf("Error making request: %v", err)
return
}

defer response.Body.Close()

if response.StatusCode != tt.want {
t.Errorf("Expected status code %d, got %d", tt.want, response.StatusCode)
}
Expand Down
1 change: 0 additions & 1 deletion healthcrm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ func TestHealthCRMLib_GetFacilities(t *testing.T) {
if tt.name == "Happy case: fetch facilities" {
path := fmt.Sprintf("%s/v1/facilities/facilities/", BaseURL)
httpmock.RegisterResponder(http.MethodGet, path, func(r *http.Request) (*http.Response, error) {

service1 := &FacilityOutput{
ID: gofakeit.UUID(),
Name: gofakeit.BeerName(),
Expand Down

0 comments on commit 1d58e5e

Please sign in to comment.