Skip to content

Commit

Permalink
chore: add codacy coverage.
Browse files Browse the repository at this point in the history
chore: add codacy coverage.

chore: add codacy coverage.

chore: add codacy coverage.

chore: add codacy coverage.

chore: add codacy coverage.

chore: add codacy coverage.

chore: add codacy coverage.

chore: add codacy coverage.

chore: add codacy coverage.

chore: add codacy coverage.

chore: add codacy coverage.

chore: add codacy coverage.

chore: add codacy coverage.

chore: add codacy coverage.

chore: add codacy coverage.
  • Loading branch information
auula committed Sep 10, 2023
1 parent 71ab4a6 commit 837e27f
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 79 deletions.
6 changes: 6 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
coverage:
enabled: yes
input:
- ./coverage.out # 用于指定覆盖率报告文件的路径
parsers:
- go
40 changes: 40 additions & 0 deletions .github/workflows/codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Codacy and Codecov Integration

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build-and-report:
runs-on: ubuntu-latest
name: Build, Test, and Report Coverage
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "1.20"

- name: Build
run: go build -v ./...

- name: Test
run: ./test.sh 1

- name: Test Coverage
run: ./test.sh 4

- name: Codacy Coverage Reporter
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: coverage.out # Replace with the actual path to your coverage report file

- name: Upload coverage to Codecov
run: bash <(curl -s https://codecov.io/bash) -t ${{ secrets.CODECOV_TOKEN }}
30 changes: 0 additions & 30 deletions .github/workflows/go.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.dylib
./cmd/vasedb
vasedb
_temp

# Test binary, built with `go test -c`
*.test
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ VaseDB is a NoSQL that supports multiple data types and transactions.
---

[![Go Report Card](https://goreportcard.com/badge/github.com/auula/vasedb)](https://goreportcard.com/report/github.com/auula/vasedb)
[![Release](https://img.shields.io/github/v/release/auula/vasedb.svg?style=flat-square)](https://github.com/auula/vasedb)
[![License](https://img.shields.io/badge/license-Apache%202-blue)](github.com/auula/vasedb/blob/master/LICENSE)
[![Go Reference](https://pkg.go.dev/badge/github.com/auula/vasedb.svg)](https://pkg.go.dev/github.com/auula/vasedb)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/55bc449808ca4d0c80c0122f170d7313)](https://app.codacy.com/gh/auula/vasedb/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[![codecov](https://codecov.io/gh/auula/vasedb/graph/badge.svg?token=ekQ3KzyXtm)](https://codecov.io/gh/auula/vasedb)
[![DeepSource](https://deepsource.io/gh/auula/vasedb.svg/?label=active+issues&token=rdl-7kKKCfR0F8b0dojJd50U)](https://deepsource.io/gh/auula/vasedb/?ref=repository-badge)

Expand Down
2 changes: 1 addition & 1 deletion clog/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
caw = os.O_CREATE | os.O_APPEND | os.O_WRONLY

// fix: clog import cycle not allowed.
permissions = fs.FileMode(0600)
permissions = fs.FileMode(0755)
)

var (
Expand Down
41 changes: 2 additions & 39 deletions cmd/vasedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"fmt"
"os"
"os/exec"
"strings"

"github.com/auula/vasedb/clog"
"github.com/auula/vasedb/conf"
"github.com/auula/vasedb/server"
"github.com/auula/vasedb/utils"
"github.com/auula/vasedb/vfs"
"github.com/fatih/color"
)
Expand Down Expand Up @@ -111,48 +111,11 @@ func parseFlags() (fl *flags) {
return
}

// trimDaemon 从 os.Args 中移除 "-daemon" 参数
func trimDaemon(args []string) []string {
var newArgs []string

// 遍历 args 切片
for i := 1; i < len(args); i++ {
// 巨坑无比,无法知道用户输入的参数是 -- 还是 - 开头
if args[i] == "-daemon" || args[i] == "--daemon" {
// 当发现 "-daemon" 参数时,跳过当前参数
continue
}
newArgs = append(newArgs, args[i])
}

return newArgs
}

func splitArgs(args []string) []string {
var newArgs []string
// i = 1 避免处理 ./vasedb 本身
for i := 1; i < len(args); i++ {
// 巨坑无比,如果没有这段代码 newArgs 元素中会出现 --port=2468 元素
// 而不是分割好的 [--port , 2468] 这样的元素,否则命令行解析错误
if strings.Contains(args[i], "=") && strings.Count(args[i], "=") == 1 {
newArgs = append(newArgs, strings.Split(args[i], "=")...)
} else {
// 如果是 --port==8080 ,过滤掉 == 不合法过滤掉
if strings.Count(args[i], "=") > 1 {
continue
}
newArgs = append(newArgs, strings.Split(args[i], "=")...)
}
}

return newArgs
}

func main() {
// 检查是否启用了守护进程模式
if daemon {
// 后台守护进程模式启动,创建一个与当前程序相同的命令
cmd := exec.Command(os.Args[0], splitArgs(trimDaemon(os.Args))...)
cmd := exec.Command(os.Args[0], utils.SplitArgs(utils.TrimDaemon(os.Args))...)

// 如果需要传递环境变量信息
cmd.Env = os.Environ()
Expand Down
10 changes: 6 additions & 4 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ if [ -z "$case_num" ]; then
exit 1
fi

if [ ""$case_num"" -eq 1 ]; then
cd cmd && go test -c && ./cmd.test
rm -rf ./_temp
mkdir -p ./_temp

if [ "$case_num" -eq 1 ]; then
cd cmd && go test -c && sudo -S ./cmd.test
elif [ "$case_num" -eq 2 ]; then
echo "Testing conf package"
elif [ "$case_num" -eq 3 ]; then
echo "Testing server package"
elif [ "$case_num" -eq 4 ]; then
cd cmd && go test -c -race -coverprofile=coverage.txt -covermode=atomic -v
./cmd.test
go test ./... -race -coverprofile=coverage.out -covermode=atomic -v
else
echo "Invalid option. Please provide a valid option (1, 2, or 3)."
fi
40 changes: 40 additions & 0 deletions utils/string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package utils

import "strings"

// trimDaemon 从 os.Args 中移除 "-daemon" 参数
func TrimDaemon(args []string) []string {
var newArgs []string

// 遍历 args 切片
for i := 1; i < len(args); i++ {
// 巨坑无比,无法知道用户输入的参数是 -- 还是 - 开头
if args[i] == "-daemon" || args[i] == "--daemon" {
// 当发现 "-daemon" 参数时,跳过当前参数
continue
}
newArgs = append(newArgs, args[i])
}

return newArgs
}

func SplitArgs(args []string) []string {
var newArgs []string
// i = 1 避免处理 ./vasedb 本身
for i := 1; i < len(args); i++ {
// 巨坑无比,如果没有这段代码 newArgs 元素中会出现 --port=2468 元素
// 而不是分割好的 [--port , 2468] 这样的元素,否则命令行解析错误
if strings.Contains(args[i], "=") && strings.Count(args[i], "=") == 1 {
newArgs = append(newArgs, strings.Split(args[i], "=")...)
} else {
// 如果是 --port==8080 ,过滤掉 == 不合法过滤掉
if strings.Count(args[i], "=") > 1 {
continue
}
newArgs = append(newArgs, strings.Split(args[i], "=")...)
}
}

return newArgs
}
6 changes: 3 additions & 3 deletions cmd/vasedb_test.go → utils/string_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package utils

import (
"reflect"
Expand Down Expand Up @@ -26,7 +26,7 @@ func TestSplitArgs(t *testing.T) {

for _, testCase := range testCases {
t.Run("", func(t *testing.T) {
result := splitArgs(testCase.input)
result := SplitArgs(testCase.input)
if !reflect.DeepEqual(result, testCase.expected) {
t.Errorf("Expected %v, but got %v", testCase.expected, result)
}
Expand All @@ -53,7 +53,7 @@ func TestTrimDaemon(t *testing.T) {

for _, test := range tests {
t.Run("", func(t *testing.T) {
result := trimDaemon(test.input)
result := TrimDaemon(test.input)
if !reflect.DeepEqual(result, test.expected) {
t.Errorf("Expected %v, but got %v", test.expected, result)
}
Expand Down

0 comments on commit 837e27f

Please sign in to comment.