Skip to content

Commit

Permalink
feat: add github CI and Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
inchori committed Nov 26, 2023
1 parent 65b46f5 commit 908c170
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 3 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

on:
push:
branches:
- main
- releases/v*.*.*
pull_request:

jobs:
build:
name: Build and Test
runs-on: ubuntu-latest

steps:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
id: go

- name: Checkout code into the Go module directory
uses: actions/checkout@v3

- name: Make .env file
run: |
touch ./.env
echo "${{ secrets.DOT_ENV }}" > ./.env
- name: Build
env:
CGO_ENABLED: 0
GOOS: linux
GOARCH: amd64
run: make build

- name: Test
run: make test

- name: Publish coverage.html as an artifact
uses: actions/upload-artifact@master
with:
name: coverage
path: artifacts/coverage.html
28 changes: 28 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: golang linter

on:
pull_request:
push:
branches:
- main
- releases/v*.*.*

jobs:
golangci:
name: golangci-lint
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
id: go

- name: Checkout code into the Go module directory
uses: actions/checkout@v3

- name: Lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=5m
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ build
artifacts

# binary
customerd
main
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ARTIFACT_DIR := artifacts

build: go.sum
go build -mod=readonly -o main main.go

test:
mkdir -p $(ARTIFACT_DIR)
go test -covermode=count -coverprofile=$(ARTIFACT_DIR)/coverage.out ./...
go tool cover -html=$(ARTIFACT_DIR)/coverage.out -o $(ARTIFACT_DIR)/coverage.html

lint:
golangci-lint run --timeout 5m0s --allow-parallel-runners
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
go mod verify

clean:
rm -rf build/
6 changes: 6 additions & 0 deletions handler/user_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ func UpdateUser(ctx context.Context, userService service.IUserService) fiber.Han
})
}
password, err := utils.HashPassword(userUpdateRequest.Password)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": err.Error(),
})
}

userResponse, err := userService.UpdateUser(ctx, userUpdateRequest.Name, password, id)
if err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
dbClient := database.ConnectDB(loadConfig)
ctx := context.Background()
if err := dbClient.Schema.Create(ctx); err != nil {
logrus.Fatal("failed to migrate database schema: %v", err)
logrus.Fatalf("failed to migrate database schema: %v", err)
}

userRepository := repository.NewUserRepository(dbClient.User)
Expand Down Expand Up @@ -71,7 +71,7 @@ func main() {
go func() {
logrus.Infof("gRPC server is running on %s port", loadConfig.GRPCPort)
if err := grpcSvr.Serve(lis); err != nil {
logrus.Fatal("failed to serve gRPC server: %v", err)
logrus.Fatalf("failed to serve gRPC server: %v", err)
}
}()

Expand Down

0 comments on commit 908c170

Please sign in to comment.