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

[CI] add basic static check, complie, test #292

Merged
merged 1 commit into from
Oct 7, 2023
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
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 ./...
5 changes: 2 additions & 3 deletions cli/cli/cli.go
Original file line number Diff line number Diff line change
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 @@ -551,8 +551,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 @@ -229,9 +229,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 cli/command/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func NewStatusCommand(curveadm *cli.CurveAdm) *cobra.Command {
flags.StringVar(&options.role, "role", "*", "Specify service role")
flags.StringVar(&options.host, "host", "*", "Specify service host")
flags.BoolVarP(&options.verbose, "verbose", "v", false, "Verbose output for status")
flags.BoolVarP(&options.showInstances, "show-instances", "s", false, "Display service instances")
flags.BoolVarP(&options.showInstances, "show-instances", "s", false, "Display service instances")

return cmd
}
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
11 changes: 5 additions & 6 deletions internal/configure/topology/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ const (
)

type Var struct {
name string
kind []string // kind limit for register variable
role []string // role limit for register variable
lookup bool // whether need to lookup host
resolved bool
name string
kind []string // kind limit for register variable
role []string // role limit for register variable
lookup bool // whether need to lookup host
}

/*
Expand Down Expand Up @@ -141,7 +140,7 @@ func skip(dc *DeployConfig, v Var) bool {
func addVariables(dcs []*DeployConfig, idx int, vars []Var) error {
dc := dcs[idx]
for _, v := range vars {
if skip(dc, v) == true {
if skip(dc, v) {
continue
}

Expand Down
Loading