Skip to content

Commit

Permalink
[CI] add basic static check, compile, test
Browse files Browse the repository at this point in the history
Signed-off-by: xiaoming <[email protected]>
  • Loading branch information
357447923 committed Sep 27, 2023
1 parent 3b6b0a1 commit c6f9757
Show file tree
Hide file tree
Showing 56 changed files with 238 additions and 180 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/CodeQL.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: "CodeQL"

on:
push:
branches: [ "master","develop" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master","develop" ]
schedule:
- cron: '0 17 * * 5'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
# timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
22 changes: 18 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,23 @@ on:
branches: [ $default-branch, "develop" ]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: '1.19'
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup golangci-lint
uses: golangci/[email protected]
with:
version: v1.52.2
args: --verbose

test:
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -21,15 +37,13 @@ jobs:
run: make test

build:
needs: test
needs: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Set dependencies
run: sudo apt update && sudo apt install musl-tools
- name: Build
run: make build
run: go build -v ./...
38 changes: 38 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
run:
timeout: 5m
linters:
enable:
# Simple linter to check that your code does not contain non-ASCII identifiers.
- asciicheck
# Go linter that checks if package imports are in a list of acceptable packages.
- depguard
# Checks for pointers to enclosing loop variables.
- exportloopref
# Gofmt checks whether code was gofmt-ed
- gofmt
# Inspects source code for security problems.
- gosec
# Finds naked returns in functions greater than a specified function length.
- nakedret
# Reports ill-formed or insufficient nolint directives.
- nolintlint
# Checks for dangerous unicode character sequences.
- bidichk
disable:
# ignore errcheck
- errcheck
linters-settings:
gosec:
# Available rules: https://github.com/securego/gosec#available-rules
excludes:
- G101 # Look for hard coded credentials
- G204 # Audit use of command execution
- G401 # Detect the usage of DES, RC4, MD5 or SHA1
- G403 # Ensure minimum RSA key length of 2048 bits
- G404 # Insecure random number source (rand)
- G501 # Import blocklist: crypto/md5
- G502 # Import blocklist: crypto/des
- G503 # Import blocklist: crypto/rc4
- G504 # Import blocklist: net/http/cgi
- G505 # Import blocklist: crypto/sha1
- G601 # Implicit memory aliasing of items from a range statement
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ SERVER_PACKAGES := $(PWD)/cmd/service/main.go
# tar
VERSION := "unknown"

build:
build: fmt vet
$(GOENV) $(GO) build -o $(OUTPUT) $(BUILD_FLAGS) $(PACKAGES)
$(GOENV) $(GO) build -o $(SERVER_OUTPUT) $(BUILD_FLAGS) $(SERVER_PACKAGES)

debug:

debug: fmt vet
$(GOENV) $(GO) build -o $(OUTPUT) $(DEBUG_FLAGS) $(PACKAGES)
$(GOENV) $(GO) build -o $(SERVER_OUTPUT) $(DEBUG_FLAGS) $(SERVER_PACKAGES)


test:
$(GO_TEST) $(TEST_FLAGS) ./...

Expand All @@ -74,3 +76,8 @@ lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCILINT_VERSION)
$(GOBIN_GOLANGCILINT) run -v

fmt:
go fmt ./...

vet:
go vet ./...
15 changes: 7 additions & 8 deletions cli/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ func NewCurveAdm() (*CurveAdm, error) {

rootDir := fmt.Sprintf("%s/.curveadm", home)
curveadm := &CurveAdm{
rootDir: rootDir,
dataDir: path.Join(rootDir, "data"),
pluginDir: path.Join(rootDir, "plugins"),
logDir: path.Join(rootDir, "logs"),
tempDir: path.Join(rootDir, "temp"),
rootDir: rootDir,
dataDir: path.Join(rootDir, "data"),
pluginDir: path.Join(rootDir, "plugins"),
logDir: path.Join(rootDir, "logs"),
tempDir: path.Join(rootDir, "temp"),
httpConfPath: path.Join(rootDir, "http/conf"),
httpLogPath: path.Join(rootDir, "http/logs"),
}
Expand Down Expand Up @@ -248,7 +248,7 @@ func (curveadm *CurveAdm) detectVersion() {
}

func (curveadm *CurveAdm) Upgrade() (bool, error) {
if curveadm.config.GetAutoUpgrade() == false {
if !curveadm.config.GetAutoUpgrade() {
return false, nil
}

Expand Down Expand Up @@ -549,8 +549,7 @@ func (curveadm *CurveAdm) PostAudit(id int64, ec error) {
return
}

auditLog := auditLogs[0]
status := auditLog.Status
var status int
errorCode := 0
if ec == nil {
status = comm.AUDIT_STATUS_SUCCESS
Expand Down
2 changes: 1 addition & 1 deletion cli/command/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func genCleanPlaybook(curveadm *cli.CurveAdm,
Configs: dcs,
Options: map[string]interface{}{
comm.KEY_CLEAN_ITEMS: options.only,
comm.KEY_CLEAN_BY_RECYCLE: options.withoutRecycle == false,
comm.KEY_CLEAN_BY_RECYCLE: !options.withoutRecycle,
},
})
}
Expand Down
1 change: 0 additions & 1 deletion cli/command/client/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"strings"

"github.com/dustin/go-humanize"

"github.com/fatih/color"
"github.com/opencurve/curveadm/cli/cli"
comm "github.com/opencurve/curveadm/internal/common"
Expand Down
5 changes: 2 additions & 3 deletions cli/command/cluster/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,8 @@ func readDatabase(filename string) (storage.Cluster, []storage.Service, error) {
switch id {
case CLUSTER_DESCRIPTION:
cluster.Description = value
break
case CLUSTER_TOPOLOGY:
cluster.Topology = value
break
case SERVICE:
items := strings.Split(value, " ")
if len(items) != 2 {
Expand All @@ -166,7 +164,8 @@ func importCluster(storage *storage.Storage, name, dbfile string) error {
}

// insert cluster
if storage.InsertCluster(name, cluster.Description, cluster.Topology); err != nil {
err = storage.InsertCluster(name, cluster.Description, cluster.Topology)
if err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cli/command/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ PowerShell:
`, "curveadm"),
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.ExactValidArgs(1),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
Expand Down
4 changes: 2 additions & 2 deletions cli/command/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ func genDeployPlaybook(curveadm *cli.CurveAdm,
role := DEPLOY_FILTER_ROLE[step]
config = curveadm.FilterDeployConfigByRole(config, role)
}
n := len(config)

if DEPLOY_LIMIT_SERVICE[step] > 0 {
n = DEPLOY_LIMIT_SERVICE[step]
n := DEPLOY_LIMIT_SERVICE[step]
config = config[:n]
}

Expand Down
1 change: 0 additions & 1 deletion cli/command/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func NewExecCommand(curveadm *cli.CurveAdm) *cobra.Command {
PreRunE: func(cmd *cobra.Command, args []string) error {
options.id = args[0]
options.cmd = strings.Join(args[1:], " ")
args = args[:1]
return curveadm.CheckId(options.id)
},
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
2 changes: 1 addition & 1 deletion http/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func GetClusterServicesAddr(r *pigeon.Request, ctx *Context) bool {
pigeon.Field("error", err))
return core.ExitSuccessWithData(r, servicesAddr)
}
}
}
servicesAddr.ClusterId = adm.ClusterId()
servicesAddr.Addrs = getServicesAddrFromConf(dcs, mcs)
return core.ExitSuccessWithData(r, servicesAddr)
Expand Down
9 changes: 0 additions & 9 deletions internal/configure/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ type (
config map[string]interface{}
serviceConfig map[string]string
variables *variable.Variables
data string // configure file content
}
)

Expand Down Expand Up @@ -167,14 +166,6 @@ func (cc *ClientConfig) getString(key string) string {
return v.(string)
}

func (cc *ClientConfig) getBool(key string) bool {
v := cc.config[strings.ToLower(key)]
if v == nil {
return false
}
return v.(bool)
}

func (cc *ClientConfig) GetKind() string { return cc.getString(KEY_KIND) }
func (cc *ClientConfig) GetDataDir() string { return cc.getString(KEY_DATA_DIR) }
func (cc *ClientConfig) GetLogDir() string { return cc.getString(KEY_LOG_DIR) }
Expand Down
2 changes: 1 addition & 1 deletion internal/configure/hosts/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (hc *HostConfig) Build() error {
F("hosts[%d].private_key_file = %s", hc.sequence, privateKeyFile)
}

if hc.GetForwardAgent() == false {
if !hc.GetForwardAgent() {
if !utils.PathExist(privateKeyFile) {
return errno.ERR_PRIVATE_KEY_FILE_NOT_EXIST.
F("%s: no such file", privateKeyFile)
Expand Down
12 changes: 3 additions & 9 deletions internal/configure/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,7 @@ func ScaleOutClusterPool(old *CurveClusterTopo, dcs []*topology.DeployConfig, po
npools := old.NPools
topo := generateClusterPool(dcs, fmt.Sprintf("pool%d", npools+1), poolset, diskType)
if dcs[0].GetKind() == KIND_CURVEBS {
for _, pool := range topo.LogicalPools {
old.LogicalPools = append(old.LogicalPools, pool)
}
old.LogicalPools = append(old.LogicalPools, topo.LogicalPools...)
for _, newPst := range topo.Poolsets {
isExist := false
for _, oldPst := range old.Poolsets {
Expand All @@ -256,13 +254,9 @@ func ScaleOutClusterPool(old *CurveClusterTopo, dcs []*topology.DeployConfig, po
}
}
} else {
for _, pool := range topo.Pools {
old.Pools = append(old.Pools, pool)
}
}
for _, server := range topo.Servers {
old.Servers = append(old.Servers, server)
old.Pools = append(old.Pools, topo.Pools...)
}
old.Servers = append(old.Servers, topo.Servers...)
old.NPools = old.NPools + 1
}

Expand Down
8 changes: 4 additions & 4 deletions internal/configure/topology/dc.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func formatName(name string, hostSequence int) string {

func newVariables(m map[string]interface{}) (*variable.Variables, error) {
vars := variable.NewVariables()
if m == nil || len(m) == 0 {
if len(m) == 0 {
return vars, nil
}

Expand Down Expand Up @@ -182,8 +182,8 @@ func (dc *DeployConfig) renderVariables() error {
}
dc.config[k] = realv
build.DEBUG(build.DEBUG_TOPOLOGY,
build.Field{k, v},
build.Field{k, realv})
build.Field{Key: k, Value: v},
build.Field{Key: k, Value: realv})
}
return nil
}
Expand All @@ -192,7 +192,7 @@ func (dc *DeployConfig) convert() error {
// init service config
for k, v := range dc.config {
item := itemset.get(k)
if item == nil || item.exclude == false {
if item == nil || !item.exclude {
dc.serviceConfig[k] = v.(string)
}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/configure/topology/dc_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ var (
DefaultCurveFSDeployConfig = &DeployConfig{kind: KIND_CURVEFS}

ServiceConfigs = map[string][]string{
ROLE_ETCD: []string{"etcd.conf"},
ROLE_MDS: []string{"mds.conf"},
ROLE_CHUNKSERVER: []string{"chunkserver.conf", "cs_client.conf", "s3.conf"},
ROLE_SNAPSHOTCLONE: []string{"snapshotclone.conf", "snap_client.conf", "s3.conf", "nginx.conf"},
ROLE_METASERVER: []string{"metaserver.conf"},
ROLE_ETCD: {"etcd.conf"},
ROLE_MDS: {"mds.conf"},
ROLE_CHUNKSERVER: {"chunkserver.conf", "cs_client.conf", "s3.conf"},
ROLE_SNAPSHOTCLONE: {"snapshotclone.conf", "snap_client.conf", "s3.conf", "nginx.conf"},
ROLE_METASERVER: {"metaserver.conf"},
}
)

Expand Down
Loading

0 comments on commit c6f9757

Please sign in to comment.