diff --git a/.gitignore b/.gitignore
index d833575f..7c33c3bf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,3 +34,4 @@ coverage
/.vscode
go.sum
+hamster-develop
diff --git a/README.md b/README.md
index 17bc4e0f..94ab851d 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@
-[https://github.com/hamster-shared/a-line/tree/develop](https://vvbin.cn/next/)
+[https://github.com/hamster-shared/hamster-develop/tree/develop](https://vvbin.cn/next/)
This template should help get you started developing with Vue 3 in Vite.
@@ -55,8 +55,8 @@ yarn build
Thank you for considering your contribution to ALine!
-
-
+
+
---
@@ -153,7 +153,7 @@ Thank you for considering your contribution to ALine!
- 从远程仓库 clone 代码到本地
```shell
- git clone -b develop https://github.com/hamster-shared/a-line.git
+ git clone -b develop https://github.com/hamster-shared/hamster-develop.git
```
- 编译构建
diff --git a/cmd/daemon.go b/cmd/daemon.go
index 10635b85..ab83fab1 100644
--- a/cmd/daemon.go
+++ b/cmd/daemon.go
@@ -5,10 +5,10 @@ package cmd
import (
"fmt"
- "github.com/hamster-shared/a-line/engine"
- "github.com/hamster-shared/a-line/pkg/application"
- "github.com/hamster-shared/a-line/pkg/controller"
- "github.com/hamster-shared/a-line/pkg/service"
+ engine "github.com/hamster-shared/aline-engine"
+ "github.com/hamster-shared/hamster-develop/pkg/application"
+ "github.com/hamster-shared/hamster-develop/pkg/controller"
+ "github.com/hamster-shared/hamster-develop/pkg/service"
"github.com/spf13/cobra"
"gorm.io/driver/mysql"
"gorm.io/gorm"
diff --git a/cmd/executor.go b/cmd/executor.go
index e5d3eed1..e95c011a 100644
--- a/cmd/executor.go
+++ b/cmd/executor.go
@@ -4,7 +4,7 @@ Copyright © 2022 NAME HERE
package cmd
import (
- "github.com/hamster-shared/a-line/pkg/controller"
+ "github.com/hamster-shared/hamster-develop/pkg/controller"
"github.com/spf13/cobra"
)
diff --git a/cmd/root.go b/cmd/root.go
index 13b5d194..d1b5973a 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -5,12 +5,12 @@ package cmd
import (
"fmt"
- "github.com/hamster-shared/a-line/engine"
- "github.com/hamster-shared/a-line/engine/logger"
- "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/pipeline"
- "github.com/hamster-shared/a-line/pkg/controller"
- service2 "github.com/hamster-shared/a-line/pkg/service"
+ engine "github.com/hamster-shared/aline-engine"
+ "github.com/hamster-shared/aline-engine/logger"
+ "github.com/hamster-shared/aline-engine/model"
+ "github.com/hamster-shared/aline-engine/pipeline"
+ "github.com/hamster-shared/hamster-develop/pkg/controller"
+ service2 "github.com/hamster-shared/hamster-develop/pkg/service"
"io"
"os"
"path"
diff --git a/engine/action/action_artifactory.go b/engine/action/action_artifactory.go
deleted file mode 100644
index 399cd320..00000000
--- a/engine/action/action_artifactory.go
+++ /dev/null
@@ -1,173 +0,0 @@
-package action
-
-import (
- "context"
- "errors"
- "fmt"
- "github.com/hamster-shared/a-line/engine/consts"
- "github.com/hamster-shared/a-line/engine/logger"
- model2 "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/output"
- "github.com/hamster-shared/a-line/engine/utils"
- "io"
- "os"
- path2 "path"
- "path/filepath"
- "strconv"
- "strings"
-)
-
-// ArtifactoryAction Storage building
-type ArtifactoryAction struct {
- name string
- path []string
- compress bool
- output *output.Output
- ctx context.Context
-}
-
-func NewArtifactoryAction(step model2.Step, ctx context.Context, output *output.Output) *ArtifactoryAction {
- var path string
- s := step.With["path"]
- if s != "" {
- if s[len(s)-1:] == "\n" {
- path = s[:len(s)-1]
- } else {
- path = s
- }
- }
-
- compress := true
-
- val, ok := step.With["compress"]
- if ok {
- compress, _ = strconv.ParseBool(val)
- }
-
- return &ArtifactoryAction{
- name: step.With["name"],
- path: strings.Split(path, "\n"),
- ctx: ctx,
- compress: compress,
- output: output,
- }
-}
-
-func (a *ArtifactoryAction) Pre() error {
- if !(len(a.path) > 0 && a.path[0] != "") {
- return errors.New("the path parameter of the save artifact is required")
- }
- if a.name == "" {
- return errors.New("the name parameter of the save artifact is required")
- }
- stack := a.ctx.Value(STACK).(map[string]interface{})
- workdir, ok := stack["workdir"].(string)
- if !ok {
- return errors.New("get workdir error")
- }
- var fullPathList []string
- for _, path := range a.path {
- absPath := path2.Join(workdir, path)
- fullPathList = append(fullPathList, absPath)
- }
- var absPathList []string
- a.path = GetFiles(workdir, fullPathList, absPathList)
- return nil
-}
-
-func (a *ArtifactoryAction) Hook() (*model2.ActionResult, error) {
- a.output.NewStage("artifactory")
- stack := a.ctx.Value(STACK).(map[string]interface{})
- jobName, ok := stack["name"].(string)
- if !ok {
- return nil, errors.New("get job name error")
- }
- jobId, ok := stack["id"].(string)
- if !ok {
- return nil, errors.New("get job id error")
- }
- userHomeDir, err := os.UserHomeDir()
- if err != nil {
- logger.Errorf("Failed to get home directory, the file will be saved to the current directory, err is %s", err.Error())
- userHomeDir = "."
- }
-
- // compress
- if a.compress {
- dest := path2.Join(userHomeDir, consts.ArtifactoryDir, jobName, consts.ArtifactoryName, jobId, a.name)
- var files []*os.File
- for _, path := range a.path {
- file, err := os.Open(path)
- if err != nil {
- return nil, errors.New("file open fail")
- }
- files = append(files, file)
- }
- err = utils.CompressZip(files, dest)
- if err != nil {
- return nil, errors.New("compression failed")
- }
- logger.Infof("File saved to %s", dest)
- actionResult := model2.ActionResult{
- Artifactorys: []model2.Artifactory{
- {
- Name: a.name,
- Url: dest,
- },
- },
- Reports: nil,
- }
- return &actionResult, nil
- } else {
- actionResult := &model2.ActionResult{
- Artifactorys: []model2.Artifactory{},
- }
- basePath := path2.Join(userHomeDir, consts.ArtifactoryDir, jobName, consts.ArtifactoryName, jobId)
- os.MkdirAll(basePath, os.ModePerm)
- for _, path := range a.path {
- src, err := os.Open(path)
- if err != nil {
- continue
- }
- dest := path2.Join(basePath, path2.Base(path))
- dst, err := os.OpenFile(dest, os.O_WRONLY|os.O_CREATE, os.ModePerm)
- if err != nil {
- continue
- }
- io.Copy(dst, src)
- _ = src.Close()
- _ = dst.Close()
-
- actionResult.Artifactorys = append(actionResult.Artifactorys, model2.Artifactory{
- Name: path2.Base(dest),
- Url: dest,
- })
- }
-
- return actionResult, nil
- }
-}
-
-func (a *ArtifactoryAction) Post() error {
- fmt.Println("artifactory Post end")
- return nil
-}
-
-func GetFiles(workdir string, fuzzyPath []string, pathList []string) []string {
- files, _ := os.ReadDir(workdir)
- flag := false
- for _, file := range files {
- currentPath := workdir + "/" + file.Name()
- for _, path := range fuzzyPath {
- matched, err := filepath.Match(path, currentPath)
- flag = matched
- if matched && err == nil {
- pathList = append(pathList, currentPath)
- }
- }
- if file.IsDir() && !flag {
- pathList = GetFiles(currentPath, fuzzyPath, pathList)
- }
- }
- return pathList
-}
diff --git a/engine/action/action_check_aggregation.go b/engine/action/action_check_aggregation.go
deleted file mode 100644
index c197ca63..00000000
--- a/engine/action/action_check_aggregation.go
+++ /dev/null
@@ -1,184 +0,0 @@
-package action
-
-import (
- "context"
- "encoding/json"
- "errors"
- "github.com/hamster-shared/a-line/engine/consts"
- "github.com/hamster-shared/a-line/engine/logger"
- "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/output"
- "github.com/hamster-shared/a-line/pkg/utils"
- "os"
- path2 "path"
- "strconv"
- "strings"
-)
-
-// CheckAggregationAction 合约聚合
-type CheckAggregationAction struct {
- path string
- ctx context.Context
- output *output.Output
-}
-
-func NewCheckAggregationAction(step model.Step, ctx context.Context, output *output.Output) *CheckAggregationAction {
- return &CheckAggregationAction{
- path: step.With["path"],
- ctx: ctx,
- output: output,
- }
-}
-
-func (a *CheckAggregationAction) Pre() error {
- return nil
-}
-
-func (a *CheckAggregationAction) Hook() (*model.ActionResult, error) {
- a.output.NewStep("check-aggregation")
-
- stack := a.ctx.Value(STACK).(map[string]interface{})
- jobName, ok := stack["name"].(string)
- if !ok {
- return nil, errors.New("get job name error")
- }
- jobId, ok := stack["id"].(string)
- if !ok {
- return nil, errors.New("get job id error")
- }
- userHomeDir, err := os.UserHomeDir()
- if err != nil {
- logger.Errorf("Failed to get home directory, the file will be saved to the current directory, err is %s", err.Error())
- userHomeDir = "."
- }
-
- var absPathList []string
- destDir := path2.Join(userHomeDir, consts.ArtifactoryDir, jobName, consts.CheckName, jobId)
- absPathList = utils.GetSameFileNameFiles(destDir, consts.CheckResult, absPathList)
- _, err = os.Stat(destDir)
- if os.IsNotExist(err) {
- err := os.MkdirAll(destDir, os.ModePerm)
- if err != nil {
- return nil, err
- }
- }
- var contractCheckResultList []model.ContractCheckResult[json.RawMessage]
- //var styleGuideValidationsReportList model.ContractCheckResult[[]model.ContractStyleGuideValidationsReportDetails]
- //var securityAnalysisReportList model.ContractCheckResult[[]model.ContractStyleGuideValidationsReportDetails]
- for _, path := range absPathList {
- file, err := os.ReadFile(path)
- if err != nil {
- return nil, errors.New("file open fail")
- }
- result := string(file)
- if strings.Contains(result, consts.ContractMethodsPropertiesReport.Name) {
- var methodsPropertiesReport model.ContractCheckResult[[]model.ContractMethodsPropertiesReportDetails]
- err := json.Unmarshal(file, &methodsPropertiesReport)
- if err != nil {
- continue
- }
- var methodsPropertiesReportRaw model.ContractCheckResult[json.RawMessage]
- methodsPropertiesReportRaw.Tool = methodsPropertiesReport.Tool
- methodsPropertiesReportRaw.Name = methodsPropertiesReport.Name
- methodsPropertiesReportRaw.Result = methodsPropertiesReport.Result
- var contractCheckResultDetailsList []model.ContractCheckResultDetails[json.RawMessage]
- for _, report := range methodsPropertiesReport.Context {
- var contractCheckResultDetails model.ContractCheckResultDetails[json.RawMessage]
- contractCheckResultDetails.Name = report.Name
- contractCheckResultDetails.Issue = report.Issue
- marshal, err := json.Marshal(report.Message)
- if err != nil {
- continue
- }
- contractCheckResultDetails.Message = []byte(strings.ReplaceAll(string(marshal), "\\u001b", ""))
- contractCheckResultDetailsList = append(contractCheckResultDetailsList, contractCheckResultDetails)
- }
- methodsPropertiesReportRaw.Context = contractCheckResultDetailsList
- contractCheckResultList = append(contractCheckResultList, methodsPropertiesReportRaw)
- }
- if strings.Contains(result, consts.ContractStyleGuideValidationsReport.Name) {
- var styleGuideValidationsReport model.ContractCheckResult[[]model.ContractStyleGuideValidationsReportDetails]
- err := json.Unmarshal(file, &styleGuideValidationsReport)
- if err != nil {
- continue
- }
- var styleGuideValidationsReportRaw model.ContractCheckResult[json.RawMessage]
- styleGuideValidationsReportRaw.Tool = styleGuideValidationsReport.Tool
- styleGuideValidationsReportRaw.Name = styleGuideValidationsReport.Name
- styleGuideValidationsReportRaw.Result = styleGuideValidationsReport.Result
- var contractCheckResultDetailsList []model.ContractCheckResultDetails[json.RawMessage]
- for _, report := range styleGuideValidationsReport.Context {
- var contractCheckResultDetails model.ContractCheckResultDetails[json.RawMessage]
- contractCheckResultDetails.Name = report.Name
- contractCheckResultDetails.Issue = report.Issue
- marshal, err := json.Marshal(report.Message)
- if err != nil {
- continue
- }
- contractCheckResultDetails.Message = marshal
- contractCheckResultDetailsList = append(contractCheckResultDetailsList, contractCheckResultDetails)
- }
- styleGuideValidationsReportRaw.Context = contractCheckResultDetailsList
- contractCheckResultList = append(contractCheckResultList, styleGuideValidationsReportRaw)
- }
- if strings.Contains(result, consts.ContractSecurityAnalysisReport.Name) {
- var securityAnalysisReport model.ContractCheckResult[[]model.ContractStyleGuideValidationsReportDetails]
- err := json.Unmarshal(file, &securityAnalysisReport)
- if err != nil {
- continue
- }
- var securityAnalysisReportRaw model.ContractCheckResult[json.RawMessage]
- securityAnalysisReportRaw.Tool = securityAnalysisReport.Tool
- securityAnalysisReportRaw.Name = securityAnalysisReport.Name
- securityAnalysisReportRaw.Result = securityAnalysisReport.Result
- var contractCheckResultDetailsList []model.ContractCheckResultDetails[json.RawMessage]
- for _, report := range securityAnalysisReport.Context {
- var contractCheckResultDetails model.ContractCheckResultDetails[json.RawMessage]
- contractCheckResultDetails.Name = report.Name
- contractCheckResultDetails.Issue = report.Issue
- marshal, err := json.Marshal(report.Message)
- if err != nil {
- continue
- }
- contractCheckResultDetails.Message = marshal
- contractCheckResultDetailsList = append(contractCheckResultDetailsList, contractCheckResultDetails)
- }
- securityAnalysisReportRaw.Context = contractCheckResultDetailsList
- contractCheckResultList = append(contractCheckResultList, securityAnalysisReportRaw)
- }
- }
- a.path = path2.Join(destDir, consts.CheckAggregationResult)
- create, err := os.Create(a.path)
- if err != nil {
- return nil, err
- }
- marshal, err := json.Marshal(contractCheckResultList)
- if err != nil {
- return nil, err
- }
- _, err = create.WriteString(string(marshal))
- if err != nil {
- return nil, err
- }
- create.Close()
-
- id, err := strconv.Atoi(jobId)
- if err != nil {
- return nil, err
- }
- actionResult := model.ActionResult{
- Artifactorys: nil,
- Reports: []model.Report{
- {
- Id: id,
- Url: a.path,
- Type: 2,
- },
- },
- }
- return &actionResult, err
-}
-
-func (a *CheckAggregationAction) Post() error {
- return nil
-}
diff --git a/engine/action/action_git.go b/engine/action/action_git.go
deleted file mode 100644
index a1560fe4..00000000
--- a/engine/action/action_git.go
+++ /dev/null
@@ -1,268 +0,0 @@
-package action
-
-import (
- "bufio"
- "context"
- "fmt"
- "github.com/hamster-shared/a-line/engine/logger"
- model2 "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/output"
- "github.com/hamster-shared/a-line/engine/utils"
- "os"
- "os/exec"
- "strings"
-)
-
-// GitAction git clone
-type GitAction struct {
- repository string
- branch string
- workdir string
- output *output.Output
- ctx context.Context
-}
-
-func NewGitAction(step model2.Step, ctx context.Context, output *output.Output) *GitAction {
-
- stack := ctx.Value(STACK).(map[string]interface{})
- params := stack["parameter"].(map[string]string)
-
- return &GitAction{
- repository: utils.ReplaceWithParam(step.With["url"], params),
- branch: utils.ReplaceWithParam(step.With["branch"], params),
- ctx: ctx,
- output: output,
- }
-}
-
-func (a *GitAction) Pre() error {
- a.output.NewStep("git")
-
- stack := a.ctx.Value(STACK).(map[string]interface{})
- a.workdir = stack["workdir"].(string)
-
- _, err := os.Stat(a.workdir)
- if err != nil {
- err = os.MkdirAll(a.workdir, os.ModePerm)
- if err != nil {
- return err
- }
-
- command := "git init " + a.workdir
- _, err = a.ExecuteStringCommand(command)
- if err != nil {
- return err
- }
- }
-
- //TODO ... 检验 git 命令是否存在
- return nil
-}
-
-func (a *GitAction) Hook() (*model2.ActionResult, error) {
-
- stack := a.ctx.Value(STACK).(map[string]interface{})
-
- logger.Infof("git stack: %v", stack)
-
- // before
- //commands := []string{"git", "clone", "--progress", a.repository, "-b", a.branch, pipelineName}
- //err := a.ExecuteCommand(commands)
- //if err != nil {
- // return nil, err
- //}
-
- command := "git rev-parse --is-inside-work-tree"
- out, err := a.ExecuteStringCommand(command)
- if err != nil {
-
- command = "git init"
- _, err = a.ExecuteStringCommand(command)
- if err != nil {
- return nil, err
- }
-
- }
-
- command = "git config remote.origin.url " + a.repository
- out, err = a.ExecuteStringCommand(command)
- if err != nil {
- return nil, err
- }
-
- command = "git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*"
- out, err = a.ExecuteStringCommand(command)
- if err != nil {
- return nil, err
- }
-
- command = "git config remote.origin.url " + a.repository
- out, err = a.ExecuteStringCommand(command)
- if err != nil {
- return nil, err
- }
-
- command = "git fetch --tags --progress " + a.repository + " +refs/heads/*:refs/remotes/origin/*"
- out, err = a.ExecuteStringCommand(command)
- if err != nil {
- return nil, err
- }
-
- command = fmt.Sprintf("git rev-parse refs/remotes/origin/%s^{commit}", a.branch)
- commitId, err := a.ExecuteCommandDirect(strings.Fields(command))
- if err != nil {
- return nil, err
- }
-
- command = "git config core.sparsecheckout "
- out, _ = a.ExecuteStringCommand(command)
-
- command = fmt.Sprintf("git checkout -f %s", commitId)
- out, err = a.ExecuteStringCommand(command)
- if err != nil {
- return nil, err
- }
-
- command = "git branch -a -v --no-abbrev"
- out, err = a.ExecuteCommandDirect(strings.Fields(command))
- if err != nil {
- return nil, err
- }
-
- if containsBranch(out, a.branch) {
- command = fmt.Sprintf("git branch -D %s", a.branch)
- out, err = a.ExecuteStringCommand(command)
- logger.Debug(out)
- if err != nil {
- return nil, err
- }
- }
-
- command = fmt.Sprintf("git checkout -b %s %s", a.branch, commitId)
- out, err = a.ExecuteStringCommand(command)
- a.output.WriteLine(out)
- if err != nil {
- return nil, err
- }
-
- stack["workdir"] = a.workdir
- return &model2.ActionResult{
- CodeInfo: fmt.Sprintf("%s | %s", a.branch, commitId[0:6]),
- }, nil
-}
-
-func (a *GitAction) Post() error {
- //return os.Remove(a.workdir)
- return nil
-}
-
-func (a *GitAction) ExecuteStringCommand(command string) (string, error) {
- commands := strings.Fields(command)
- return a.ExecuteCommand(commands)
-}
-
-func (a *GitAction) ExecuteCommand(commands []string) (string, error) {
-
- c := exec.CommandContext(a.ctx, commands[0], commands[1:]...) // mac linux
- c.Dir = a.workdir
- logger.Debugf("execute git clone command: %s", strings.Join(commands, " "))
- a.output.WriteCommandLine(strings.Join(commands, " "))
-
- stdout, err := c.StdoutPipe()
- if err != nil {
- logger.Errorf("stdout error: %v", err)
- return "nil", err
- }
- stderr, err := c.StderrPipe()
- if err != nil {
- logger.Errorf("stderr error: %v", err)
- return "nil", err
- }
-
- go func() {
- for {
- // 检测到 ctx.Done() 之后停止读取
- <-a.ctx.Done()
- if a.ctx.Err() != nil {
- logger.Errorf("shell command error: %v", a.ctx.Err())
- return
- } else {
- p := c.Process
- if p == nil {
- return
- }
- // Kill by negative PID to kill the process group, which includes
- // the top-level process we spawned as well as any subprocesses
- // it spawned.
- //_ = syscall.Kill(-p.Pid, syscall.SIGKILL)
- logger.Info("shell command killed")
- return
- }
- }
- }()
-
- stdoutScanner := bufio.NewScanner(stdout)
- stderrScanner := bufio.NewScanner(stderr)
- go func() {
- for stdoutScanner.Scan() {
- fmt.Println(stdoutScanner.Text())
- a.output.WriteLine(stdoutScanner.Text())
- }
- }()
- go func() {
- for stderrScanner.Scan() {
- fmt.Println(stderrScanner.Text())
- a.output.WriteLine(stderrScanner.Text())
- }
- }()
-
- err = c.Start()
- if err != nil {
- logger.Errorf("shell command start error: %v", err)
- return "nil", err
- }
-
- err = c.Wait()
- if err != nil {
- logger.Errorf("shell command wait error: %v", err)
- return "nil", err
- }
- if err != nil {
- a.output.WriteLine(err.Error())
- }
-
- defer stdout.Close()
- defer stderr.Close()
- return "", err
-
-}
-
-func (a *GitAction) ExecuteCommandDirect(commands []string) (string, error) {
-
- c := exec.CommandContext(a.ctx, commands[0], commands[1:]...) // mac linux
- c.Dir = a.workdir
- logger.Debugf("execute git clone command: %s", strings.Join(commands, " "))
- a.output.WriteCommandLine(strings.Join(commands, " "))
-
- out, err := c.CombinedOutput()
- a.output.WriteCommandLine(string(out))
- if err != nil {
- a.output.WriteLine(err.Error())
- }
- return string(out), err
-
-}
-
-func containsBranch(branchOutput, branch string) bool {
- array := strings.Split(branchOutput, "\n")
-
- for _, s := range array {
- if len(strings.Fields(s)) == 0 {
- continue
- }
- if strings.EqualFold(strings.Fields(s)[0], branch) {
- return true
- }
- }
- return false
-}
diff --git a/engine/action/action_ink.go b/engine/action/action_ink.go
deleted file mode 100644
index e4a4a0fc..00000000
--- a/engine/action/action_ink.go
+++ /dev/null
@@ -1,111 +0,0 @@
-package action
-
-import (
- "context"
- "errors"
- "github.com/hamster-shared/a-line/pkg/consts"
- "github.com/hamster-shared/a-line/pkg/logger"
- "github.com/hamster-shared/a-line/pkg/model"
- "github.com/hamster-shared/a-line/pkg/output"
- "log"
- "os"
- "os/exec"
- "path/filepath"
- "strings"
-)
-
-type InkAction struct {
- network string // deploy network
- mnemonic string // deploy Private key
- output *output.Output
- ctx context.Context
-}
-
-func NewInkAction(step model.Step, ctx context.Context, output *output.Output) *InkAction {
- return &InkAction{
- network: step.With["network"],
- mnemonic: step.With["mnemonic"],
- ctx: ctx,
- output: output,
- }
-}
-
-func (a *InkAction) Pre() error {
- stack := a.ctx.Value(STACK).(map[string]interface{})
- logger.Infof("git stack: %v", stack)
- workdir, ok := stack["workdir"].(string)
- if !ok {
- return errors.New("get workdir error")
- }
- command := "npm install -g deploy-polkadot@1.0.3"
- out, err := a.ExecuteStringCommand(command, workdir)
- a.output.WriteLine(out)
- if err != nil {
- return err
- }
- return nil
-}
-
-func (a *InkAction) Hook() (*model.ActionResult, error) {
- stack := a.ctx.Value(STACK).(map[string]interface{})
- logger.Infof("git stack: %v", stack)
- workdir, ok := stack["workdir"].(string)
- if !ok {
- return nil, errors.New("get workdir error")
- }
- targetPath := filepath.Join(workdir, "target", "ink")
- _, err := os.Stat(targetPath)
- if os.IsNotExist(err) {
- log.Println("get target directory failed", err.Error())
- return nil, err
- }
- files, err := os.ReadDir(targetPath)
- if err != nil {
- log.Println("read target file failed: ", err.Error())
- return nil, err
- }
- var fileName string
- for _, file := range files {
- if strings.HasSuffix(file.Name(), ".contract") {
- fileName = file.Name()
- break
- }
- }
- //var command string
- if fileName != "" {
- contractPath := filepath.Join(targetPath, fileName)
- commands := []string{"deploy-polkadot", "--url", consts.InkUrlMap[a.network], "--mnemonic", a.mnemonic, "--metadata", contractPath}
- out, err := a.ExecuteCommand(commands, workdir)
- a.output.WriteLine(out)
- if err != nil {
- return nil, err
- }
- return nil, nil
- }
- return nil, errors.New("no contract structures found")
-}
-
-func (a *InkAction) Post() error {
- //return os.Remove(a.workdir)
- return nil
-}
-
-func (a *InkAction) ExecuteStringCommand(command, workdir string) (string, error) {
- commands := strings.Fields(command)
- return a.ExecuteCommand(commands, workdir)
-}
-
-func (a *InkAction) ExecuteCommand(commands []string, workdir string) (string, error) {
- c := exec.CommandContext(a.ctx, commands[0], commands[1:]...) // mac linux
- c.Dir = workdir
- logger.Debugf("execute truffle deploy command: %s", strings.Join(commands, " "))
- a.output.WriteCommandLine(strings.Join(commands, " "))
-
- out, err := c.CombinedOutput()
-
- a.output.WriteCommandLine(string(out))
- if err != nil {
- a.output.WriteLine(err.Error())
- }
- return string(out), err
-}
diff --git a/engine/action/action_ipfs.go b/engine/action/action_ipfs.go
deleted file mode 100644
index c3803912..00000000
--- a/engine/action/action_ipfs.go
+++ /dev/null
@@ -1,140 +0,0 @@
-package action
-
-import (
- "bytes"
- "context"
- "encoding/json"
- "errors"
- "fmt"
- "github.com/hamster-shared/a-line/engine/consts"
- model2 "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/output"
- "github.com/hamster-shared/a-line/engine/utils"
- "io"
- "mime/multipart"
- "net/http"
- "os"
- path2 "path"
-)
-
-// IpfsAction Upload files/directories to ipfs
-type IpfsAction struct {
- path string
- output *output.Output
- ctx context.Context
-}
-
-func NewIpfsAction(step model2.Step, ctx context.Context, output *output.Output) *IpfsAction {
- return &IpfsAction{
- path: step.With["path"],
- ctx: ctx,
- output: output,
- }
-}
-
-func (a *IpfsAction) Pre() error {
- return nil
-}
-
-func (a *IpfsAction) Hook() (*model2.ActionResult, error) {
-
- stack := a.ctx.Value(STACK).(map[string]interface{})
-
- workdir, ok := stack["workdir"].(string)
- if !ok {
- return nil, errors.New("get workdir error")
- }
-
- path := path2.Join(workdir, a.path)
- fmt.Println(path)
- fi, err := os.Stat(path)
- if err != nil {
- return nil, errors.New(fmt.Sprintf("get path fail, err is %s", err.Error()))
- }
- isDir := fi.IsDir()
- var dstPath string
- if isDir {
- dstPath = path + ".car"
- _, err := os.Stat(dstPath)
- if err == nil {
- os.Remove(dstPath)
- }
- car, err := utils.CreateCar(a.ctx, path, dstPath, consts.CarVersion)
- if err != nil {
- return nil, errors.New("dir to car fail")
- }
- fmt.Println(fmt.Sprintf("%s 的ipfs hash 是 %s", path, car))
- } else {
- dstPath = path
- }
-
- _, file := path2.Split(dstPath)
- body := new(bytes.Buffer)
- writer := multipart.NewWriter(body)
- formFile, err := writer.CreateFormFile("file", file)
- if err != nil {
- return nil, err
- }
- open, err := os.Open(dstPath)
- if err != nil {
- return nil, errors.New("dstPath open fail")
- }
- _, err = io.Copy(formFile, open)
- if err != nil {
- return nil, err
- }
- err = writer.Close()
- if err != nil {
- return nil, err
- }
- client := http.Client{}
- req, err := http.NewRequest("POST", consts.IpfsUploadUrl, body)
- if err != nil {
- return nil, err
- }
- req.Header.Add("Content-Type", writer.FormDataContentType())
- resp, err := client.Do(req)
- if err != nil {
- return nil, err
- }
- defer resp.Body.Close()
- bodyText, err := io.ReadAll(resp.Body)
- if err != nil {
- return nil, err
- }
- fmt.Printf("收到的req是 %s\n", bodyText)
- var ipfsGatewayCloudReq IpfsGatewayCloudReq
- err = json.Unmarshal(bodyText, &ipfsGatewayCloudReq)
- if err != nil {
- return nil, errors.New("req json unmarshal fail")
- }
- actionResult := model2.ActionResult{
- Artifactorys: []model2.Artifactory{
- {
- Name: a.path,
- Url: ipfsGatewayCloudReq.Url,
- },
- },
- Reports: nil,
- }
- fmt.Println(actionResult)
- return &actionResult, nil
-}
-
-func (a *IpfsAction) Post() error {
- return nil
-}
-
-type IpfsGatewayCloudReq struct {
- UploadID string `json:"uploadID"`
- UploadFileType string `json:"upload_file_type"`
- UploadType string `json:"upload_type"`
- Cid string `json:"cid"`
- Filename string `json:"filename"`
- ContentType string `json:"content_type"`
- Size int `json:"size"`
- Url string `json:"url"`
- Status string `json:"status"`
- Pin string `json:"pin"`
- Dht string `json:"dht"`
-}
diff --git a/engine/action/action_mythril.go b/engine/action/action_mythril.go
deleted file mode 100644
index ac53f6bf..00000000
--- a/engine/action/action_mythril.go
+++ /dev/null
@@ -1,267 +0,0 @@
-package action
-
-import (
- "bufio"
- "context"
- "encoding/json"
- "errors"
- "fmt"
- "github.com/hamster-shared/a-line/engine/consts"
- "github.com/hamster-shared/a-line/engine/logger"
- "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/output"
- "github.com/hamster-shared/a-line/pkg/utils"
- "io"
- "os"
- "os/exec"
- path2 "path"
- "strconv"
- "strings"
-)
-
-// MythRilAction mythRil合约检查
-type MythRilAction struct {
- path string
- solcVersion string
- ctx context.Context
- output *output.Output
-}
-
-func NewMythRilAction(step model.Step, ctx context.Context, output *output.Output) *MythRilAction {
- return &MythRilAction{
- path: step.With["path"],
- solcVersion: step.With["solc-version"],
- ctx: ctx,
- output: output,
- }
-}
-
-func (a *MythRilAction) Pre() error {
- stack := a.ctx.Value(STACK).(map[string]interface{})
- workdir, ok := stack["workdir"].(string)
- if !ok {
- return errors.New("workdir is empty")
- }
- nodeModules := path2.Join(workdir, "node_modules")
- files, err := os.ReadDir(nodeModules)
- fileContent := ""
- var fileNameList []string
- if err != nil {
- mythRilSolcJson := consts.MythRilSolcJson
- fileContent = strings.ReplaceAll(mythRilSolcJson, "%s", "")
- } else {
- for _, file := range files {
- if file.IsDir() {
- fileNameList = append(fileNameList, file.Name())
- }
- }
- if len(fileNameList) > 0 {
- var reMappings string
- for i, name := range fileNameList {
- mappings := consts.MythRilSolcJsonReMappings
- sprintf := fmt.Sprintf(mappings, name, name)
- if i == 0 {
- reMappings = reMappings + sprintf
- } else {
- reMappings = reMappings + "," + sprintf
- }
- }
- mythRilSolcJson := consts.MythRilSolcJson
- fileContent = fmt.Sprintf(mythRilSolcJson, reMappings)
- } else {
- mythRilSolcJson := consts.MythRilSolcJson
- fileContent = strings.ReplaceAll(mythRilSolcJson, "%s", "")
- }
- }
- create, err := os.Create(path2.Join(workdir, consts.MythRilSolcJsonName))
- if err != nil {
- return err
- }
- _, err = create.WriteString(fileContent)
- if err != nil {
- return err
- }
- create.Close()
- return nil
-}
-
-func (a *MythRilAction) Hook() (*model.ActionResult, error) {
-
- a.output.NewStep("mythril-check")
-
- stack := a.ctx.Value(STACK).(map[string]interface{})
-
- workdir, ok := stack["workdir"].(string)
- if !ok {
- return nil, errors.New("workdir is empty")
- }
- jobName, ok := stack["name"].(string)
- if !ok {
- return nil, errors.New("get job name error")
- }
- jobId, ok := stack["id"].(string)
- if !ok {
- return nil, errors.New("get job id error")
- }
- userHomeDir, err := os.UserHomeDir()
- if err != nil {
- logger.Errorf("Failed to get home directory, the file will be saved to the current directory, err is %s", err.Error())
- userHomeDir = "."
- }
-
- var absPathList []string
- basePath := path2.Join(workdir, a.path)
- absPathList = utils.GetSuffixFiles(basePath, consts.SolFileSuffix, absPathList)
- destDir := path2.Join(userHomeDir, consts.ArtifactoryDir, jobName, consts.CheckName, jobId, consts.MythRilCheckOutputDir)
- _, err = os.Stat(destDir)
- if os.IsNotExist(err) {
- err := os.MkdirAll(destDir, os.ModePerm)
- if err != nil {
- return nil, err
- }
- }
- for _, path := range absPathList {
- _, filenameOnly := utils.GetFilenameWithSuffixAndFilenameOnly(path)
- dest := path2.Join(destDir, filenameOnly+consts.SuffixType)
- err, redundantPath := utils.GetRedundantPath(basePath, path)
- if err != nil {
- return nil, err
- }
- commandTemplate := consts.MythRilCheck
- command := fmt.Sprintf(commandTemplate, workdir, path2.Join(a.path, redundantPath), consts.MythRilSolcJsonName)
- if a.solcVersion != "" {
- command = command + " --solv " + a.solcVersion
- }
- fields := strings.Fields(command)
- out, err := a.ExecuteCommand(fields, workdir)
- if err != nil {
- return nil, err
- }
- create, err := os.Create(dest)
- if err != nil {
- return nil, err
- }
- _, err = create.WriteString(out)
- if err != nil {
- return nil, err
- }
- create.Close()
- }
- a.path = destDir
- id, err := strconv.Atoi(jobId)
- if err != nil {
- return nil, err
- }
- actionResult := model.ActionResult{
- Artifactorys: nil,
- Reports: []model.Report{
- {
- Id: id,
- Url: "",
- Type: 2,
- },
- },
- }
- return &actionResult, err
-}
-
-func (a *MythRilAction) Post() error {
- open, err := os.Open(a.path)
- if err != nil {
- return err
- }
- fileInfo, err := open.Stat()
- if err != nil {
- return err
- }
- isDir := fileInfo.IsDir()
- if !isDir {
- return errors.New("check result path is err")
- }
- fileInfos, err := open.Readdir(-1)
- successFlag := true
- var checkResultDetailsList []model.ContractCheckResultDetails[[]model.ContractStyleGuideValidationsReportDetails]
- for _, info := range fileInfos {
- path := path2.Join(a.path, info.Name())
- var styleGuideValidationsReportDetailsList []model.ContractStyleGuideValidationsReportDetails
- file, err := os.Open(path)
- if err != nil {
- return errors.New("file open fail")
- }
- defer file.Close()
-
- line := bufio.NewReader(file)
- for {
- content, _, err := line.ReadLine()
- if err == io.EOF {
- break
- }
- s := string(content)
- if strings.Contains(s, "The analysis was completed successfully") {
- break
- }
- var styleGuideValidationsReportDetails model.ContractStyleGuideValidationsReportDetails
- styleGuideValidationsReportDetails.Tool = consts.MythRilCheckOutputDir
- if strings.Contains(s, "Error:") || strings.Contains(s, "Note:") {
- index := strings.Index(s, ":")
- styleGuideValidationsReportDetails.Note = s[index+2:]
- }
- if strings.Contains(s, "-->") {
- split := strings.Split(s, ":")
- if len(split) < 3 {
- continue
- }
- styleGuideValidationsReportDetails.Line = split[1]
- styleGuideValidationsReportDetails.Column = split[2]
- }
- if styleGuideValidationsReportDetails.Note == "" && styleGuideValidationsReportDetails.Line == "" {
- continue
- }
- if styleGuideValidationsReportDetails.Note == "" && len(styleGuideValidationsReportDetailsList) >= 1 {
- styleGuideValidationsReportDetailsList[len(styleGuideValidationsReportDetailsList)-1].Line = styleGuideValidationsReportDetails.Line
- styleGuideValidationsReportDetailsList[len(styleGuideValidationsReportDetailsList)-1].Column = styleGuideValidationsReportDetails.Column
- } else {
- styleGuideValidationsReportDetailsList = append(styleGuideValidationsReportDetailsList, styleGuideValidationsReportDetails)
- }
- successFlag = false
- }
- details := model.NewContractCheckResultDetails[[]model.ContractStyleGuideValidationsReportDetails](strings.Replace(info.Name(), consts.SuffixType, consts.SolFileSuffix, 1), len(styleGuideValidationsReportDetailsList), styleGuideValidationsReportDetailsList)
- checkResultDetailsList = append(checkResultDetailsList, details)
- }
- var result string
- if successFlag {
- result = consts.CheckSuccess.Result
- } else {
- result = consts.CheckFail.Result
- }
- checkResult := model.NewContractCheckResult(consts.ContractSecurityAnalysisReport.Name, result, consts.ContractSecurityAnalysisReport.Tool, checkResultDetailsList)
- create, err := os.Create(path2.Join(a.path, consts.CheckResult))
- fmt.Println(checkResult)
- if err != nil {
- return err
- }
- marshal, err := json.Marshal(checkResult)
- if err != nil {
- return err
- }
- _, err = create.WriteString(string(marshal))
- if err != nil {
- return err
- }
- create.Close()
- return nil
-}
-
-func (a *MythRilAction) ExecuteCommand(commands []string, workdir string) (string, error) {
- c := exec.CommandContext(a.ctx, commands[0], commands[1:]...) // mac linux
- c.Dir = workdir
- logger.Debugf("execute mythril check command: %s", strings.Join(commands, " "))
- a.output.WriteCommandLine(strings.Join(commands, " "))
- out, err := c.CombinedOutput()
- fmt.Println(string(out))
- a.output.WriteCommandLine(string(out))
- if err != nil {
- a.output.WriteLine(err.Error())
- }
- return string(out), err
-}
diff --git a/engine/action/action_pinata_ipfs.go b/engine/action/action_pinata_ipfs.go
deleted file mode 100644
index aabd1eab..00000000
--- a/engine/action/action_pinata_ipfs.go
+++ /dev/null
@@ -1,132 +0,0 @@
-package action
-
-import (
- "bytes"
- "context"
- "encoding/json"
- "errors"
- "fmt"
- "github.com/hamster-shared/a-line/engine/consts"
- "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/output"
- "io"
- "mime/multipart"
- "net/http"
- "os"
- path2 "path"
- "path/filepath"
-)
-
-// PinataIpfsAction Upload files/directories to ipfs
-type PinataIpfsAction struct {
- path string
- output *output.Output
- ctx context.Context
-}
-
-func NewPinataIpfsAction(step model.Step, ctx context.Context, output *output.Output) *PinataIpfsAction {
- return &PinataIpfsAction{
- path: step.With["path"],
- ctx: ctx,
- output: output,
- }
-}
-
-func (a *PinataIpfsAction) Pre() error {
- return nil
-}
-
-func (a *PinataIpfsAction) Hook() (*model.ActionResult, error) {
-
- stack := a.ctx.Value(STACK).(map[string]interface{})
-
- workdir, ok := stack["workdir"].(string)
- if !ok {
- return nil, errors.New("get workdir error")
- }
-
- path := path2.Join(workdir, a.path)
- fi, err := os.Stat(path)
- if err != nil {
- return nil, errors.New(fmt.Sprintf("get path fail, err is %s", err.Error()))
- }
- isDir := fi.IsDir()
- var dstPath string
- if isDir {
- dstPath = path
- } else {
- dstPath = path
- }
- _, fileName := path2.Split(dstPath)
- pinataMetadataFmt := consts.PinataMetadataFmt
- pinataMetadata := fmt.Sprintf(pinataMetadataFmt, fileName)
- payload := &bytes.Buffer{}
- writer := multipart.NewWriter(payload)
- file, err := os.Open(dstPath)
- if err != nil {
- return nil, errors.New("open path fail")
- }
- defer file.Close()
- part1, err := writer.CreateFormFile("file", filepath.Base(dstPath))
- if err != nil {
- return nil, errors.New("create FormFile fail")
- }
- _, err = io.Copy(part1, file)
- if err != nil {
- return nil, errors.New("file copy fail")
- }
-
- _ = writer.WriteField("pinataOptions", consts.PinataOptionsFmt)
- _ = writer.WriteField("pinataMetadata", pinataMetadata)
- err = writer.Close()
- if err != nil {
- return nil, errors.New("writer close fail")
- }
-
- client := &http.Client{}
- req, err := http.NewRequest("POST", consts.PinataIpfsPinUrl, payload)
- if err != nil {
- return nil, err
- }
- req.Header.Add("Authorization", "Bearer "+consts.PinataIpfsJWT)
-
- req.Header.Set("Content-Type", writer.FormDataContentType())
- res, err := client.Do(req)
- if err != nil {
- return nil, err
- }
- defer res.Body.Close()
-
- body, err := io.ReadAll(res.Body)
- if err != nil {
- return nil, err
- }
-
- var pinataIpfsPinReq PinataIpfsPinReq
- err = json.Unmarshal(body, &pinataIpfsPinReq)
- if err != nil {
- return nil, errors.New("req json unmarshal fail")
- }
-
- actionResult := model.ActionResult{
- Artifactorys: []model.Artifactory{
- {
- Name: a.path,
- Url: consts.PinataIpfsUrl + pinataIpfsPinReq.IpfsHash,
- },
- },
- Reports: nil,
- }
- fmt.Println(actionResult)
- return &actionResult, nil
-}
-
-func (a *PinataIpfsAction) Post() error {
- return nil
-}
-
-type PinataIpfsPinReq struct {
- IpfsHash string `json:"IpfsHash"` //This is the IPFS multi-hash provided back for your content
- PinSize string `json:"PinSize"` //This is how large (in bytes) the content you just pinned is
- Timestamp string `json:"timestamp"` //This is the timestamp for your content pinning (represented in ISO 8601 format)
-}
diff --git a/engine/action/action_remote.go b/engine/action/action_remote.go
deleted file mode 100644
index 8ab569bd..00000000
--- a/engine/action/action_remote.go
+++ /dev/null
@@ -1,106 +0,0 @@
-package action
-
-import (
- "context"
- "errors"
- "fmt"
- "github.com/hamster-shared/a-line/engine/logger"
- model2 "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/utils"
- "gopkg.in/yaml.v2"
- "io"
- "os"
- "os/exec"
- "path"
-)
-
-// RemoteAction 执行远程命令
-type RemoteAction struct {
- name string
- args map[string]string
- ctx context.Context
-
- actionRoot string
-}
-
-func NewRemoteAction(step model2.Step, ctx context.Context) *RemoteAction {
- return &RemoteAction{
- name: step.Uses,
- args: step.With,
- ctx: ctx,
- }
-}
-
-func (a *RemoteAction) Pre() error {
-
- stack := a.ctx.Value(STACK).(map[string]interface{})
-
- pipelineName := stack["name"].(string)
-
- logger.Infof("git stack: %v", stack)
-
- hamsterRoot := stack["hamsterRoot"].(string)
- cloneDir := utils.RandSeq(9)
- a.actionRoot = path.Join(hamsterRoot, cloneDir)
-
- _ = os.MkdirAll(hamsterRoot, os.ModePerm)
- _ = os.Remove(path.Join(hamsterRoot, pipelineName))
-
- githubUrl := fmt.Sprintf("https://github.com/%s", a.name)
-
- commands := []string{"git", "clone", "--progress", githubUrl, cloneDir}
- c := exec.CommandContext(a.ctx, commands[0], commands[1:]...) // mac linux
- c.Dir = hamsterRoot
-
- fmt.Println(a.name)
- fmt.Println(a.args)
-
- output, err := c.CombinedOutput()
- fmt.Println(string(output))
- return err
-}
-
-func (a *RemoteAction) Hook() (*model2.ActionResult, error) {
-
- stack := a.ctx.Value(STACK).(map[string]interface{})
- env, ok := stack["env"].([]string)
- if !ok {
- return nil, errors.New("env cannot be empty")
- }
-
- file, err := os.Open(path.Join(a.actionRoot, "action.yml"))
- if err != nil {
- return nil, err
- }
- yamlFile, err := io.ReadAll(file)
- var remoteAction model2.RemoteAction
- err = yaml.Unmarshal(yamlFile, &remoteAction)
-
- for envName, _ := range remoteAction.Inputs {
- env = append(env, fmt.Sprintf("%s=%s", envName, a.args[envName]))
- }
-
- for index, step := range remoteAction.Runs.Steps {
- args := make([]string, 0)
- if _, err := os.Stat(path.Join(a.actionRoot, step.Run)); err == nil {
- args = append(args, step.Run)
- } else {
- stepFile := path.Join(a.actionRoot, fmt.Sprintf("step-%d", index))
- err = os.WriteFile(stepFile, []byte(step.Run), os.ModePerm)
- args = append(args, "-c", stepFile)
- }
-
- cmd := utils.NewCommand(a.ctx, step.Shell, args...)
- cmd.Dir = a.actionRoot
- cmd.Env = env
- output, _ := cmd.CombinedOutput()
- fmt.Println(string(output))
- }
-
- return nil, err
-}
-
-func (a *RemoteAction) Post() error {
-
- return os.RemoveAll(a.actionRoot)
-}
diff --git a/engine/action/action_shell.go b/engine/action/action_shell.go
deleted file mode 100644
index afbeac52..00000000
--- a/engine/action/action_shell.go
+++ /dev/null
@@ -1,159 +0,0 @@
-package action
-
-import (
- "bufio"
- "context"
- "errors"
- "fmt"
- "github.com/hamster-shared/a-line/engine/logger"
- model2 "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/output"
- utils2 "github.com/hamster-shared/a-line/engine/utils"
- "os"
- "os/exec"
- "strings"
-)
-
-// ShellAction 命令工作
-type ShellAction struct {
- command string
- filename string
- ctx context.Context
- output *output.Output
-}
-
-func NewShellAction(step model2.Step, ctx context.Context, output *output.Output) *ShellAction {
-
- return &ShellAction{
- command: step.Run,
- ctx: ctx,
- output: output,
- }
-}
-
-func (a *ShellAction) Pre() error {
-
- stack := a.ctx.Value(STACK).(map[string]interface{})
-
- params := stack["parameter"].(map[string]string)
-
- data, ok := stack["workdir"]
-
- var workdir string
- if ok {
- workdir = data.(string)
- } else {
- return errors.New("workdir error")
- }
-
- workdirTmp := workdir + "_tmp"
-
- _ = os.MkdirAll(workdirTmp, os.ModePerm)
-
- a.filename = workdirTmp + "/" + utils2.RandSeq(10) + ".sh"
-
- command := utils2.ReplaceWithParam(a.command, params)
-
- content := []byte("#!/bin/sh\nset -ex\n" + command)
- err := os.WriteFile(a.filename, content, os.ModePerm)
-
- return err
-}
-
-func (a *ShellAction) Hook() (*model2.ActionResult, error) {
-
- a.output.NewStep("shell")
-
- stack := a.ctx.Value(STACK).(map[string]interface{})
-
- workdir, ok := stack["workdir"].(string)
- if !ok {
- return nil, errors.New("workdir is empty")
- }
- logger.Infof("shell stack: %v", stack)
- env, ok := stack["env"].([]string)
-
- commands := []string{"sh", "-c", a.filename}
- val, ok := stack["withEnv"]
- if ok {
- precommand := val.([]string)
- shellCommand := make([]string, len(commands))
- copy(shellCommand, commands)
- commands = append([]string{}, precommand...)
- commands = append(commands, shellCommand...)
- }
-
- c := exec.CommandContext(a.ctx, commands[0], commands[1:]...) // mac linux
- c.Dir = workdir
- c.Env = append(env, os.Environ()...)
-
- logger.Debugf("execute shell command: %s", strings.Join(commands, " "))
- a.output.WriteCommandLine(strings.Join(commands, " "))
-
- stdout, err := c.StdoutPipe()
- if err != nil {
- logger.Errorf("stdout error: %v", err)
- return nil, err
- }
- stderr, err := c.StderrPipe()
- if err != nil {
- logger.Errorf("stderr error: %v", err)
- return nil, err
- }
-
- go func() {
- for {
- // 检测到 ctx.Done() 之后停止读取
- <-a.ctx.Done()
- if a.ctx.Err() != nil {
- logger.Errorf("shell command error: %v", a.ctx.Err())
- return
- } else {
- p := c.Process
- if p == nil {
- return
- }
- // Kill by negative PID to kill the process group, which includes
- // the top-level process we spawned as well as any subprocesses
- // it spawned.
- //_ = syscall.Kill(-p.Pid, syscall.SIGKILL)
- logger.Info("shell command killed")
- return
- }
- }
- }()
-
- stdoutScanner := bufio.NewScanner(stdout)
- stderrScanner := bufio.NewScanner(stderr)
- go func() {
- for stdoutScanner.Scan() {
- fmt.Println(stdoutScanner.Text())
- a.output.WriteLine(stdoutScanner.Text())
- }
- }()
- go func() {
- for stderrScanner.Scan() {
- fmt.Println(stderrScanner.Text())
- a.output.WriteLine(stderrScanner.Text())
- }
- }()
-
- err = c.Start()
- if err != nil {
- logger.Errorf("shell command start error: %v", err)
- return nil, err
- }
-
- err = c.Wait()
- if err != nil {
- logger.Errorf("shell command wait error: %v", err)
- return nil, err
- }
-
- logger.Info("execute shell command success")
- return nil, err
-}
-
-func (a *ShellAction) Post() error {
- return os.Remove(a.filename)
-}
diff --git a/engine/action/action_slither.go b/engine/action/action_slither.go
deleted file mode 100644
index 360ee20a..00000000
--- a/engine/action/action_slither.go
+++ /dev/null
@@ -1,115 +0,0 @@
-package action
-
-import (
- "context"
- "errors"
- "fmt"
- "github.com/hamster-shared/a-line/engine/consts"
- "github.com/hamster-shared/a-line/engine/logger"
- "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/output"
- "github.com/hamster-shared/a-line/pkg/utils"
- "os"
- "os/exec"
- path2 "path"
- "strings"
-)
-
-// SlitherAction slither合约检查
-type SlitherAction struct {
- path string
- ctx context.Context
- output *output.Output
-}
-
-func NewSlitherAction(step model.Step, ctx context.Context, output *output.Output) *SlitherAction {
- return &SlitherAction{
- path: step.With["path"],
- ctx: ctx,
- output: output,
- }
-}
-
-func (a *SlitherAction) Pre() error {
- return nil
-}
-
-func (a *SlitherAction) Hook() (*model.ActionResult, error) {
-
- a.output.NewStep("slither-check")
-
- stack := a.ctx.Value(STACK).(map[string]interface{})
-
- workdir, ok := stack["workdir"].(string)
- if !ok {
- return nil, errors.New("workdir is empty")
- }
- jobName, ok := stack["name"].(string)
- if !ok {
- return nil, errors.New("get job name error")
- }
- jobId, ok := stack["id"].(string)
- if !ok {
- return nil, errors.New("get job id error")
- }
- userHomeDir, err := os.UserHomeDir()
- if err != nil {
- logger.Errorf("Failed to get home directory, the file will be saved to the current directory, err is %s", err.Error())
- userHomeDir = "."
- }
-
- var absPathList []string
- basePath := path2.Join(workdir, a.path)
- absPathList = utils.GetSuffixFiles(basePath, consts.SolFileSuffix, absPathList)
- destDir := path2.Join(userHomeDir, consts.ArtifactoryDir, jobName, consts.CheckName, jobId, consts.SlitherCheckOutputDir)
- _, err = os.Stat(destDir)
- if os.IsNotExist(err) {
- err := os.MkdirAll(destDir, os.ModePerm)
- if err != nil {
- return nil, err
- }
- }
- for _, path := range absPathList {
- _, filenameOnly := utils.GetFilenameWithSuffixAndFilenameOnly(path)
- dest := path2.Join(destDir, filenameOnly+consts.SuffixType)
- err, redundantPath := utils.GetRedundantPath(basePath, path)
- if err != nil {
- return nil, err
- }
- commandTemplate := consts.SlitherCheck
- command := fmt.Sprintf(commandTemplate, basePath, redundantPath)
- fields := strings.Fields(command)
- out, err := a.ExecuteCommand(fields, workdir)
- if err != nil {
- return nil, err
- }
- create, err := os.Create(dest)
- if err != nil {
- return nil, err
- }
- _, err = create.WriteString(out)
- if err != nil {
- return nil, err
- }
- create.Close()
- }
- return nil, err
-}
-
-func (a *SlitherAction) Post() error {
- return nil
-}
-
-func (a *SlitherAction) ExecuteCommand(commands []string, workdir string) (string, error) {
- c := exec.CommandContext(a.ctx, commands[0], commands[1:]...) // mac linux
- c.Dir = workdir
- logger.Debugf("execute slither check command: %s", strings.Join(commands, " "))
- a.output.WriteCommandLine(strings.Join(commands, " "))
- out, err := c.CombinedOutput()
- fmt.Println(string(out))
- a.output.WriteCommandLine(string(out))
- if err != nil {
- a.output.WriteLine(err.Error())
- }
- return string(out), err
-}
diff --git a/engine/action/action_sol_profiler.go b/engine/action/action_sol_profiler.go
deleted file mode 100644
index 7b904c67..00000000
--- a/engine/action/action_sol_profiler.go
+++ /dev/null
@@ -1,219 +0,0 @@
-package action
-
-import (
- "bufio"
- "context"
- "encoding/json"
- "errors"
- "fmt"
- "github.com/hamster-shared/a-line/engine/consts"
- "github.com/hamster-shared/a-line/engine/logger"
- "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/output"
- "github.com/hamster-shared/a-line/pkg/utils"
- "io"
- "os"
- "os/exec"
- path2 "path"
- "regexp"
- "strconv"
- "strings"
-)
-
-// SolProfilerAction SolProfiler合约检查
-type SolProfilerAction struct {
- path string
- ctx context.Context
- output *output.Output
-}
-
-func NewSolProfilerAction(step model.Step, ctx context.Context, output *output.Output) *SolProfilerAction {
- return &SolProfilerAction{
- path: step.With["path"],
- ctx: ctx,
- output: output,
- }
-}
-
-func (a *SolProfilerAction) Pre() error {
- return nil
-}
-
-func (a *SolProfilerAction) Hook() (*model.ActionResult, error) {
-
- a.output.NewStep("sol-profiler-check")
-
- stack := a.ctx.Value(STACK).(map[string]interface{})
-
- workdir, ok := stack["workdir"].(string)
- if !ok {
- return nil, errors.New("workdir is empty")
- }
- jobName, ok := stack["name"].(string)
- if !ok {
- return nil, errors.New("get job name error")
- }
- jobId, ok := stack["id"].(string)
- if !ok {
- return nil, errors.New("get job id error")
- }
- userHomeDir, err := os.UserHomeDir()
- if err != nil {
- logger.Errorf("Failed to get home directory, the file will be saved to the current directory, err is %s", err.Error())
- userHomeDir = "."
- }
-
- var absPathList []string
- absPathList = utils.GetSuffixFiles(path2.Join(workdir, a.path), consts.SolFileSuffix, absPathList)
- destDir := path2.Join(userHomeDir, consts.ArtifactoryDir, jobName, consts.CheckName, jobId, consts.SolProfilerCheckOutputDir)
- _, err = os.Stat(destDir)
- if os.IsNotExist(err) {
- err := os.MkdirAll(destDir, os.ModePerm)
- if err != nil {
- return nil, err
- }
- }
- for _, path := range absPathList {
- _, file := path2.Split(path)
- var filenameWithSuffix string
- filenameWithSuffix = path2.Base(file)
- var fileSuffix string
- fileSuffix = path2.Ext(filenameWithSuffix)
- var filenameOnly string
- filenameOnly = strings.TrimSuffix(filenameWithSuffix, fileSuffix)
-
- dest := path2.Join(destDir, filenameOnly+consts.SuffixType)
- command := consts.SolProfilerCheck + path
- fields := strings.Fields(command)
- out, err := a.ExecuteCommand(fields, workdir)
- if err != nil {
- return nil, err
- }
- create, err := os.Create(dest)
- if err != nil {
- return nil, err
- }
- _, err = create.WriteString(out)
- if err != nil {
- return nil, err
- }
- create.Close()
- }
- a.path = destDir
- id, err := strconv.Atoi(jobId)
- if err != nil {
- return nil, err
- }
- actionResult := model.ActionResult{
- Artifactorys: nil,
- Reports: []model.Report{
- {
- Id: id,
- Url: "",
- Type: 2,
- },
- },
- }
- return &actionResult, err
-}
-
-func (a *SolProfilerAction) Post() error {
- open, err := os.Open(a.path)
- if err != nil {
- return err
- }
- fileInfo, err := open.Stat()
- if err != nil {
- return err
- }
- isDir := fileInfo.IsDir()
- if !isDir {
- return errors.New("check result path is err")
- }
- fileInfos, err := open.Readdir(-1)
- var checkResultDetailsList []model.ContractCheckResultDetails[[]model.ContractMethodsPropertiesReportDetails]
- compile, err := regexp.Compile(`\[.{1,2}m`)
- if err != nil {
- logger.Errorf("regexp err %s", err)
- return err
- }
- for _, info := range fileInfos {
- path := path2.Join(a.path, info.Name())
- var methodsPropertiesReportDetailsList []model.ContractMethodsPropertiesReportDetails
- file, err := os.Open(path)
- if err != nil {
- return errors.New("file open fail")
- }
- defer file.Close()
-
- line := bufio.NewReader(file)
- for {
- content, _, err := line.ReadLine()
- if err == io.EOF {
- break
- }
- contentSting := string(content)
- s := compile.ReplaceAllString(contentSting, "")
- if strings.Contains(s, "┌─") || strings.Contains(s, "├─") || strings.Contains(s, "└─") || strings.Contains(s, "Contract/Library/Interface") {
- continue
- }
- if !strings.Contains(s, "│") {
- continue
- }
- split := strings.Split(s, "│")
- trimSpace := strings.TrimSpace(split[1])
- if trimSpace == "" {
- continue
- }
- var methodsPropertiesReportDetails model.ContractMethodsPropertiesReportDetails
- if strings.Contains(trimSpace, "(library)") {
- index := strings.Index(trimSpace, "(library)")
- methodsPropertiesReportDetails.Contract = strings.TrimSpace(trimSpace[:index])
- methodsPropertiesReportDetails.Category = "library"
- } else {
- methodsPropertiesReportDetails.Contract = trimSpace
- methodsPropertiesReportDetails.Category = "Contract"
- }
- methodsPropertiesReportDetails.Function = strings.TrimSpace(split[2])
- methodsPropertiesReportDetails.Visibility = strings.TrimSpace(split[3])
- methodsPropertiesReportDetails.Visibility = strings.TrimSpace(split[4])
- methodsPropertiesReportDetails.Returns = strings.TrimSpace(split[5])
- methodsPropertiesReportDetails.Modifiers = strings.TrimSpace(split[6])
- methodsPropertiesReportDetailsList = append(methodsPropertiesReportDetailsList, methodsPropertiesReportDetails)
- }
-
- details := model.NewContractCheckResultDetails[[]model.ContractMethodsPropertiesReportDetails](strings.Replace(info.Name(), consts.SuffixType, consts.SolFileSuffix, 1), 0, methodsPropertiesReportDetailsList)
- checkResultDetailsList = append(checkResultDetailsList, details)
- }
- checkResult := model.NewContractCheckResult(consts.ContractMethodsPropertiesReport.Name, consts.CheckSuccess.Result, consts.ContractMethodsPropertiesReport.Tool, checkResultDetailsList)
- fmt.Printf("%+v", checkResult)
- create, err := os.Create(path2.Join(a.path, consts.CheckResult))
- fmt.Println()
- if err != nil {
- return err
- }
- marshal, err := json.Marshal(checkResult)
- if err != nil {
- return err
- }
- _, err = create.WriteString(string(marshal))
- if err != nil {
- return err
- }
- create.Close()
- return nil
-}
-
-func (a *SolProfilerAction) ExecuteCommand(commands []string, workdir string) (string, error) {
- c := exec.CommandContext(a.ctx, commands[0], commands[1:]...) // mac linux
- c.Dir = workdir
- logger.Debugf("execute sol-profiler *.sol command: %s", strings.Join(commands, " "))
- a.output.WriteCommandLine(strings.Join(commands, " "))
- out, err := c.CombinedOutput()
- fmt.Println(string(out))
- a.output.WriteCommandLine(string(out))
- if err != nil {
- a.output.WriteLine(err.Error())
- }
- return string(out), err
-}
diff --git a/engine/action/action_solhint.go b/engine/action/action_solhint.go
deleted file mode 100644
index e54ca53e..00000000
--- a/engine/action/action_solhint.go
+++ /dev/null
@@ -1,207 +0,0 @@
-package action
-
-import (
- "bufio"
- "context"
- "encoding/json"
- "errors"
- "fmt"
- "github.com/hamster-shared/a-line/engine/consts"
- "github.com/hamster-shared/a-line/engine/logger"
- "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/output"
- "github.com/hamster-shared/a-line/pkg/utils"
- "io"
- "os"
- "os/exec"
- path2 "path"
- "strconv"
- "strings"
-)
-
-// SolHintAction SolHint合约检查
-type SolHintAction struct {
- path string
- ctx context.Context
- output *output.Output
-}
-
-func NewSolHintAction(step model.Step, ctx context.Context, output *output.Output) *SolHintAction {
- return &SolHintAction{
- path: step.With["path"],
- ctx: ctx,
- output: output,
- }
-}
-
-func (a *SolHintAction) Pre() error {
- stack := a.ctx.Value(STACK).(map[string]interface{})
-
- workdir, ok := stack["workdir"].(string)
- if !ok {
- return errors.New("workdir is empty")
- }
- create, err := os.Create(path2.Join(workdir, consts.SolHintCheckInitFileName))
- if err != nil {
- return err
- }
- _, err = create.WriteString(consts.SolHintCheckRule)
- if err != nil {
- return err
- }
- create.Close()
- return nil
-}
-
-func (a *SolHintAction) Hook() (*model.ActionResult, error) {
-
- a.output.NewStep("sol-profiler-check")
-
- stack := a.ctx.Value(STACK).(map[string]interface{})
-
- workdir, ok := stack["workdir"].(string)
- if !ok {
- return nil, errors.New("workdir is empty")
- }
- jobName, ok := stack["name"].(string)
- if !ok {
- return nil, errors.New("get job name error")
- }
- jobId, ok := stack["id"].(string)
- if !ok {
- return nil, errors.New("get job id error")
- }
- userHomeDir, err := os.UserHomeDir()
- if err != nil {
- logger.Errorf("Failed to get home directory, the file will be saved to the current directory, err is %s", err.Error())
- userHomeDir = "."
- }
-
- var absPathList []string
- absPathList = utils.GetSuffixFiles(path2.Join(workdir, a.path), consts.SolFileSuffix, absPathList)
- destDir := path2.Join(userHomeDir, consts.ArtifactoryDir, jobName, consts.CheckName, jobId, consts.SolHintCheckOutputDir)
- _, err = os.Stat(destDir)
- if os.IsNotExist(err) {
- err := os.MkdirAll(destDir, os.ModePerm)
- if err != nil {
- return nil, err
- }
- }
- for _, path := range absPathList {
- _, filenameOnly := utils.GetFilenameWithSuffixAndFilenameOnly(path)
- dest := path2.Join(destDir, filenameOnly+consts.SuffixType)
- command := consts.SolHintCheck + path
- fields := strings.Fields(command)
- out, err := a.ExecuteCommand(fields, workdir)
- if err != nil {
- return nil, err
- }
- create, err := os.Create(dest)
- if err != nil {
- return nil, err
- }
- _, err = create.WriteString(out)
- if err != nil {
- return nil, err
- }
- create.Close()
- }
- a.path = destDir
- id, err := strconv.Atoi(jobId)
- if err != nil {
- return nil, err
- }
- actionResult := model.ActionResult{
- Artifactorys: nil,
- Reports: []model.Report{
- {
- Id: id,
- Url: "",
- Type: 2,
- },
- },
- }
- return &actionResult, err
-}
-
-func (a *SolHintAction) Post() error {
- open, err := os.Open(a.path)
- if err != nil {
- return err
- }
- fileInfo, err := open.Stat()
- if err != nil {
- return err
- }
- isDir := fileInfo.IsDir()
- if !isDir {
- return errors.New("check result path is err")
- }
- fileInfos, err := open.Readdir(-1)
- var checkResultDetailsList []model.ContractCheckResultDetails[[]model.ContractStyleGuideValidationsReportDetails]
- successFlag := true
- for _, info := range fileInfos {
- path := path2.Join(a.path, info.Name())
- var styleGuideValidationsReportDetailsList []model.ContractStyleGuideValidationsReportDetails
- file, err := os.Open(path)
- if err != nil {
- return errors.New("file open fail")
- }
- defer file.Close()
-
- line := bufio.NewReader(file)
- for {
- content, _, err := line.ReadLine()
- if err == io.EOF {
- break
- }
- s := string(content)
- if strings.Contains(s, " ") {
- split := strings.Split(s, " ")
- lineAndCol := strings.Split(strings.TrimSpace(split[1]), ":")
- validationsReportDetails := model.NewContractStyleGuideValidationsReportDetails(lineAndCol[0], lineAndCol[1], split[2], "", strings.Join(split[3:len(split)-1], " "), consts.SolHintCheckOutputDir)
- styleGuideValidationsReportDetailsList = append(styleGuideValidationsReportDetailsList, validationsReportDetails)
- successFlag = false
- }
- }
-
- details := model.NewContractCheckResultDetails[[]model.ContractStyleGuideValidationsReportDetails](strings.Replace(info.Name(), consts.SuffixType, consts.SolFileSuffix, 1), len(styleGuideValidationsReportDetailsList), styleGuideValidationsReportDetailsList)
- checkResultDetailsList = append(checkResultDetailsList, details)
- }
- var result string
- if successFlag {
- result = consts.CheckSuccess.Result
- } else {
- result = consts.CheckFail.Result
- }
- checkResult := model.NewContractCheckResult(consts.ContractStyleGuideValidationsReport.Name, result, consts.ContractStyleGuideValidationsReport.Tool, checkResultDetailsList)
- fmt.Println(checkResult)
- create, err := os.Create(path2.Join(a.path, consts.CheckResult))
- if err != nil {
- return err
- }
- marshal, err := json.Marshal(checkResult)
- if err != nil {
- return err
- }
- _, err = create.WriteString(string(marshal))
- if err != nil {
- return err
- }
- create.Close()
- return nil
-}
-
-func (a *SolHintAction) ExecuteCommand(commands []string, workdir string) (string, error) {
- c := exec.CommandContext(a.ctx, commands[0], commands[1:]...) // mac linux
- c.Dir = workdir
- logger.Debugf("execute solhint -f table *.sol command: %s", strings.Join(commands, " "))
- a.output.WriteCommandLine(strings.Join(commands, " "))
- out, err := c.CombinedOutput()
- fmt.Println(string(out))
- a.output.WriteCommandLine(string(out))
- if err != nil {
- a.output.WriteLine(err.Error())
- }
- return string(out), err
-}
diff --git a/engine/action/action_truffle.go b/engine/action/action_truffle.go
deleted file mode 100644
index 466f8a3a..00000000
--- a/engine/action/action_truffle.go
+++ /dev/null
@@ -1,113 +0,0 @@
-package action
-
-import (
- "context"
- _ "embed"
- "errors"
- "fmt"
- "github.com/hamster-shared/a-line/engine/logger"
- model2 "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/output"
- "os"
- "os/exec"
- "path/filepath"
- "strings"
-)
-
-//go:embed deploy_config/truffle-config.js
-var TruffleConfigFile []byte
-
-//go:embed deploy_config/truffle-config-local.js
-var TruffleConfigLocal []byte
-
-// TruffleDeployAction truffle deploy action
-type TruffleDeployAction struct {
- network string // deploy network
- privateKey string // deploy Private key
- output *output.Output
- ctx context.Context
-}
-
-func NewTruffleDeployAction(step model2.Step, ctx context.Context, output *output.Output) *TruffleDeployAction {
- return &TruffleDeployAction{
- network: step.With["network"],
- privateKey: step.With["private-key"],
- ctx: ctx,
- output: output,
- }
-}
-
-func (a *TruffleDeployAction) Pre() error {
- stack := a.ctx.Value(STACK).(map[string]interface{})
- workdir := stack["workdir"].(string)
- _, err := os.Stat(workdir)
- if os.IsNotExist(err) {
- return errors.New("workdir not exist")
- }
- truffleConfigPath := filepath.Join(workdir, "truffle-config.js")
- if a.network != "default" {
- if a.privateKey == "" {
- return errors.New("private key is empty")
- }
- //private key path
- keyPath := filepath.Join(workdir, "key.secret")
- err = os.WriteFile(keyPath, []byte(a.privateKey), 0777)
- if err != nil {
- return errors.New("failed to write private key to file")
- }
- err = os.WriteFile(truffleConfigPath, TruffleConfigFile, 0777)
- if err != nil {
- return errors.New("failed to replace truffle-config. js")
- }
- } else {
- err = os.WriteFile(truffleConfigPath, TruffleConfigLocal, 0777)
- if err != nil {
- return errors.New("failed to replace truffle-config. js")
- }
- }
- return nil
-}
-
-func (a *TruffleDeployAction) Hook() (*model2.ActionResult, error) {
- stack := a.ctx.Value(STACK).(map[string]interface{})
- logger.Infof("git stack: %v", stack)
- workdir, ok := stack["workdir"].(string)
- if !ok {
- return nil, errors.New("get workdir error")
- }
- command := "truffle deploy"
- if a.network != "default" {
- command = fmt.Sprintf("truffle migrate --reset --network %s", a.network)
- }
- out, err := a.ExecuteStringCommand(command, workdir)
- a.output.WriteLine(out)
- if err != nil {
- return nil, err
- }
- return nil, nil
-}
-
-func (a *TruffleDeployAction) Post() error {
- //return os.Remove(a.workdir)
- return nil
-}
-
-func (a *TruffleDeployAction) ExecuteStringCommand(command, workdir string) (string, error) {
- commands := strings.Fields(command)
- return a.ExecuteCommand(commands, workdir)
-}
-
-func (a *TruffleDeployAction) ExecuteCommand(commands []string, workdir string) (string, error) {
- c := exec.CommandContext(a.ctx, commands[0], commands[1:]...) // mac linux
- c.Dir = workdir
- logger.Debugf("execute truffle deploy command: %s", strings.Join(commands, " "))
- a.output.WriteCommandLine(strings.Join(commands, " "))
-
- out, err := c.CombinedOutput()
-
- a.output.WriteCommandLine(string(out))
- if err != nil {
- a.output.WriteLine(err.Error())
- }
- return string(out), err
-}
diff --git a/engine/action/action_workdir.go b/engine/action/action_workdir.go
deleted file mode 100644
index 735b9222..00000000
--- a/engine/action/action_workdir.go
+++ /dev/null
@@ -1,75 +0,0 @@
-package action
-
-import (
- "context"
- "fmt"
- model2 "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/output"
- "os"
- "strings"
-)
-
-type WorkdirAction struct {
- workdir string
- output *output.Output
- ctx context.Context
-}
-
-func NewWorkdirAction(step model2.Step, ctx context.Context, output *output.Output) *WorkdirAction {
-
- stack := ctx.Value(STACK).(map[string]interface{})
- env, ok := stack["env"].([]string)
- workdir := step.With["workdir"]
- if ok {
- workdir = envRender(workdir, append(env, os.Environ()...))
- } else {
- workdir = envRender(workdir, append(os.Environ()))
- }
-
- return &WorkdirAction{
- ctx: ctx,
- output: output,
- workdir: workdir,
- }
-}
-
-func envRender(str string, envs []string) string {
- if str == "" {
- return str
- }
-
- for _, env := range envs {
- key := fmt.Sprintf("$%s", strings.Split(env, "=")[0])
- val := strings.Split(env, "=")[1]
- if strings.Contains(str, key) {
- str = strings.ReplaceAll(str, key, val)
- }
- }
- return str
-}
-
-func (a *WorkdirAction) Pre() error {
- return nil
-}
-
-// Hook 执行
-func (a *WorkdirAction) Hook() (*model2.ActionResult, error) {
- _, err := os.Stat(a.workdir)
- if err != nil {
- err = os.MkdirAll(a.workdir, os.ModePerm)
- if err != nil {
- return nil, err
- }
-
- }
-
- stack := a.ctx.Value(STACK).(map[string]interface{})
- stack["workdir"] = a.workdir
-
- return nil, nil
-}
-
-// Post 执行后清理 (无论执行是否成功,都应该有Post的清理)
-func (a *WorkdirAction) Post() error {
- return nil
-}
diff --git a/engine/action/deploy_config/truffle-config-local.js b/engine/action/deploy_config/truffle-config-local.js
deleted file mode 100644
index 4c5f4be4..00000000
--- a/engine/action/deploy_config/truffle-config-local.js
+++ /dev/null
@@ -1,35 +0,0 @@
-// const HDWalletProvider = require('@truffle/hdwallet-provider');
-
-// const fs = require('fs');
-// const mnemonic = fs.readFileSync(".secret").toString().trim();
-// const mnemonic = fs.readFileSync("key.secret").toString().trim();
-
-module.exports = {
- // Uncommenting the defaults below
- // provides for an easier quick-start with Ganache.
- // You can also follow this format for other networks.
- // See details at: https://trufflesuite.com/docs/truffle/reference/configuration
- // on how to specify configuration options!
- //
- networks: {
- development: {
- host: "127.0.0.1",
- port: 8545,
- network_id: "*"
- },
- },
- mocha: {
- // timeout: 100000
- },
- compilers: {
- solc: {
- version: '^0.8.0',
- settings: {
- optimizer: {
- enabled: true,
- runs: 200
- }
- }
- }
- }
-};
\ No newline at end of file
diff --git a/engine/action/deploy_config/truffle-config.js b/engine/action/deploy_config/truffle-config.js
deleted file mode 100644
index d08ebb9b..00000000
--- a/engine/action/deploy_config/truffle-config.js
+++ /dev/null
@@ -1,83 +0,0 @@
-const HDWalletProvider = require('@truffle/hdwallet-provider');
-
-const fs = require('fs');
-// const mnemonic = fs.readFileSync(".secret").toString().trim();
-const mnemonic = fs.readFileSync("key.secret").toString().trim();
-
-module.exports = {
- // Uncommenting the defaults below
- // provides for an easier quick-start with Ganache.
- // You can also follow this format for other networks.
- // See details at: https://trufflesuite.com/docs/truffle/reference/configuration
- // on how to specify configuration options!
- //
- networks: {
- development: {
- host: "127.0.0.1",
- port: 8545,
- network_id: "*"
- },
- rinkeby: {
- provider: () => new HDWalletProvider(mnemonic, `https://eth-rinkeby.nodereal.io/v1/e22027c44d0242ca8e0cbe791a0476a8`),
- network_id: 1214, // Ropsten's id
- gas: 5500000, // Ropsten has a lower block limit than mainnet
- confirmations: 2, // # of confs to wait between deployments. (default: 0)
- timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
- skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
- },
- goerli: {
- provider: () => new HDWalletProvider(mnemonic, `https://eth-goerli.nodereal.io/v1/3338535f903b481199dac92d3fe0b00c`),
- network_id: 5, // Ropsten's id
- gas: 5500000, // Ropsten has a lower block limit than mainnet
- confirmations: 2, // # of confs to wait between deployments. (default: 0)
- timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
- skipDryRun: true, // Skip dry run before migrations? (default: false for public nets )
- },
- moonbase: {
- provider: () => new HDWalletProvider(mnemonic, `https://rpc.api.moonbase.moonbeam.network`),
- network_id: 1287, // Ropsten's id
- gas: 5500000, // Ropsten has a lower block limit than mainnet
- confirmations: 2, // # of confs to wait between deployments. (default: 0)
- timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
- skipDryRun: true, // Skip dry run before migrations? (default: false for public nets )
- },
- moonbeam: {
- provider: () => new HDWalletProvider(mnemonic, `https://moonbeam-mainnet.gateway.pokt.network/v1/lb/629a2b5650ec8c0039bb30f0`),
- network_id: 1284, // Ropsten's id
- gas: 5500000, // Ropsten has a lower block limit than mainnet
- confirmations: 2, // # of confs to wait between deployments. (default: 0)
- timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
- skipDryRun: true, // Skip dry run before migrations? (default: false for public nets )
- },
- moonriver: {
- provider: () => new HDWalletProvider(mnemonic, `https://moonriver-mainnet.gateway.pokt.network/v1/lb/62a74fdb123e6f003963642f`),
- network_id: 1285, // Ropsten's id
- gas: 5500000, // Ropsten has a lower block limit than mainnet
- confirmations: 2, // # of confs to wait between deployments. (default: 0)
- timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
- skipDryRun: true, // Skip dry run before migrations? (default: false for public nets )
- },
- mainnet: {
- provider: () => new HDWalletProvider(mnemonic, `https://eth-mainnet.nodereal.io/v1/9f1a58fe4331425c971c9391a3d60c27`),
- network_id: 1, // Ropsten's id
- gas: 5500000, // Ropsten has a lower block limit than mainnet
- confirmations: 2, // # of confs to wait between deployments. (default: 0)
- timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
- skipDryRun: true, // Skip dry run before migrations? (default: false for public nets )
- },
- },
- mocha: {
- // timeout: 100000
- },
- compilers: {
- solc: {
- version: '^0.8.0',
- settings: {
- optimizer: {
- enabled: true,
- runs: 200
- }
- }
- }
- }
-};
\ No newline at end of file
diff --git a/engine/action/env_docker.go b/engine/action/env_docker.go
deleted file mode 100644
index 634b7880..00000000
--- a/engine/action/env_docker.go
+++ /dev/null
@@ -1,130 +0,0 @@
-package action
-
-import (
- "context"
- "errors"
- "fmt"
- "github.com/hamster-shared/a-line/engine/logger"
- model2 "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/output"
- "os"
- "os/exec"
- "strings"
- "time"
-)
-
-const STACK = "stack"
-
-type DockerEnv struct {
- ctx context.Context
- Image string
- containerID string
- output *output.Output
-}
-
-func NewDockerEnv(step model2.Step, ctx context.Context, output *output.Output) *DockerEnv {
- return &DockerEnv{
- ctx: ctx,
- Image: step.RunsOn,
- output: output,
- }
-}
-
-func (e *DockerEnv) Pre() error {
- //e.output.NewEnv("docker env")
-
- stack := e.ctx.Value(STACK).(map[string]interface{})
-
- jobName := stack["name"].(string)
- jobId := stack["id"].(string)
-
- data, ok := stack["workdir"]
-
- var workdir string
- if ok {
- workdir = data.(string)
- } else {
- return errors.New("workdir error")
- }
-
- workdirTmp := workdir + "_tmp"
-
- _ = os.MkdirAll(workdirTmp, os.ModePerm)
-
- //user := fmt.Sprintf("%d:%d", os.Getuid(), os.Getgid())
- // "-u", user,
-
- commands := []string{"docker", "run", "--name", fmt.Sprintf("%s_%s_%d", jobName, jobId, time.Now().Minute()), "-t", "-d", "-v", workdir + ":" + workdir, "-v", workdirTmp + ":" + workdirTmp, "-w", workdir, e.Image, "cat"}
- logger.Debugf("execute docker command: %s", strings.Join(commands, " "))
- e.output.WriteCommandLine(strings.Join(commands, " "))
- c := exec.Command(commands[0], commands[1:]...)
- c.Env = os.Environ()
- output, err := c.CombinedOutput()
- if err != nil {
- logger.Errorf("execute docker command error: %s", err.Error())
- return err
- }
- containerID := string(output)
- logger.Debugf("docker command output: %s", containerID)
- fmt.Printf("docker command output: %s \n", containerID)
- e.output.WriteLine(containerID)
-
- filelds := strings.Fields(containerID)
-
- fmt.Println(filelds)
- e.containerID = filelds[len(filelds)-1]
- return err
-}
-
-func (e *DockerEnv) Hook() (*model2.ActionResult, error) {
-
- c := exec.Command("docker", "top", e.containerID, "-eo", "pid,comm")
- c.Env = os.Environ()
- logger.Debugf("execute docker command: %s", strings.Join(c.Args, " "))
- e.output.WriteCommandLine(strings.Join(c.Args, " "))
-
- output, err := c.CombinedOutput()
- logger.Debugf("docker command output: %s", string(output))
- e.output.WriteLine(string(output))
-
- if err != nil {
- logger.Errorf("execute docker command error: %s", err.Error())
- return nil, err
- }
-
- stack := e.ctx.Value(STACK).(map[string]interface{})
- stack["withEnv"] = []string{"docker", "exec", e.containerID}
- return nil, nil
-}
-
-func (e *DockerEnv) Post() error {
-
- c := exec.Command("docker", "stop", "--time=1", e.containerID)
- logger.Debugf("execute docker command: %s", strings.Join(c.Args, " "))
- e.output.WriteCommandLine(strings.Join(c.Args, " "))
-
- output, err := c.CombinedOutput()
- e.output.WriteLine(string(output))
-
- if err != nil {
- logger.Errorf("execute docker command error: %s", err.Error())
- return err
- }
-
- c = exec.Command("docker", "rm", "-f", e.containerID)
- logger.Debugf("execute docker command: %s", strings.Join(c.Args, " "))
- e.output.WriteCommandLine(strings.Join(c.Args, " "))
-
- output, err = c.CombinedOutput()
- e.output.WriteLine(string(output))
-
- if err != nil {
- logger.Errorf("execute docker command error: %s", err.Error())
- return err
- }
-
- stack := e.ctx.Value(STACK).(map[string]interface{})
- stack["withEnv"] = []string{}
-
- return nil
-}
diff --git a/engine/action/hander.go b/engine/action/hander.go
deleted file mode 100644
index 5f9a86c2..00000000
--- a/engine/action/hander.go
+++ /dev/null
@@ -1,17 +0,0 @@
-package action
-
-import (
- "github.com/hamster-shared/a-line/engine/model"
-)
-
-// ActionHandler 执行动作钩子
-type ActionHandler interface {
- // Pre 执行前准备
- Pre() error
-
- // Hook 执行
- Hook() (*model.ActionResult, error)
-
- // Post 执行后清理 (无论执行是否成功,都应该有Post的清理)
- Post() error
-}
diff --git a/engine/consts/consts.go b/engine/consts/consts.go
deleted file mode 100644
index 7762a0c1..00000000
--- a/engine/consts/consts.go
+++ /dev/null
@@ -1,60 +0,0 @@
-package consts
-
-const (
- PIPELINE_DIR_NAME = "pipelines"
- JOB_DIR_NAME = "jobs"
- JOB_DETAIL_DIR_NAME = "job-details"
- JOB_DETAIL_LOG_DIR_NAME = "job-details-log"
-)
-
-const (
- LANG_EN = "en"
- LANG_ZH = "zh"
- WEB_PORT = 8080
-)
-
-const (
- TRIGGER_MODE = "Manual trigger"
-)
-
-const (
- ArtifactoryName = "/artifactory"
- ArtifactoryDir = PIPELINE_DIR_NAME + "/" + JOB_DIR_NAME
-)
-const (
- IpfsUploadUrl = "https://api.ipfs-gateway.cloud/upload"
- CarVersion = 1
- PinataIpfsUrl = "https://gateway.pinata.cloud/ipfs/"
- PinataIpfsPinUrl = "https://api.pinata.cloud/pinning/pinFileToIPFS"
- PinataIpfsJWT = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySW5mb3JtYXRpb24iOnsiaWQiOiI5YTY3ODQ5NC05MmY0LTQ5NTctYWMzYi1iNTY2ZmRjMWM5ZjkiLCJlbWFpbCI6ImFiaW5nNDEwMTc0ODMzQGdtYWlsLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJwaW5fcG9saWN5Ijp7InJlZ2lvbnMiOlt7ImlkIjoiRlJBMSIsImRlc2lyZWRSZXBsaWNhdGlvbkNvdW50IjoxfSx7ImlkIjoiTllDMSIsImRlc2lyZWRSZXBsaWNhdGlvbkNvdW50IjoxfV0sInZlcnNpb24iOjF9LCJtZmFfZW5hYmxlZCI6ZmFsc2UsInN0YXR1cyI6IkFDVElWRSJ9LCJhdXRoZW50aWNhdGlvblR5cGUiOiJzY29wZWRLZXkiLCJzY29wZWRLZXlLZXkiOiI2MDZlZWE4NTg1YTk3ZjQzMGM3ZiIsInNjb3BlZEtleVNlY3JldCI6ImE4ODZkYjNiNDE1ZmM5ODdkYmZkMmFlYzBkODA0NjliMjQwYWFhNGY5NzdjZWQ5NmE4OWY3MzUxZWJlYzYzYzciLCJpYXQiOjE2NzAzMTY3ODB9.WCw_yg3txR8fnFUUmbTFXC3z3pXVmW0OZ0cnWJdtQHI"
- PinataOptionsFmt = "{\"cidVersion\": 1}"
- PinataMetadataFmt = "{\"name\": \"%s\", \"keyvalues\": {\"company\": \"Hamster\"}}"
-)
-
-const (
- SolFileSuffix = ".sol"
- CheckName = "/check"
- CheckResult = "total_result.txt"
- CheckAggregationResult = "check_aggregation_result.txt"
- SuffixType = ".txt"
- SolProfilerCheck = "sol-profiler "
- SolProfilerCheckOutputDir = "sol_profiler"
- SolHintCheckOutputDir = "solhint"
- SolHintCheck = "solhint -f stylish "
- SolHintCheckInitFileName = ".solhint.json"
- SolHintCheckRule = "{\n \"extends\": \"solhint:recommended\",\n \"rules\": {\n \"code-complexity\": [\"warn\",7],\n \"function-max-lines\": [\"warn\",50],\n \"max-states-count\": [\"warn\",15],\n \"no-empty-blocks\": \"off\",\n \"no-unused-vars\": \"warn\",\n \"payable-fallback\": \"warn\",\n \"reason-string\": [\"warn\",{\"maxLength\":64}],\n \"constructor-syntax\": \"warn\",\n \"avoid-call-value\": \"warn\",\n \"avoid-low-level-calls\": \"warn\",\n \"avoid-throw\": \"warn\",\n \"compiler-version\": [\"off\",\"^0.8.13\"],\n \"avoid-tx-origin\": \"warn\",\n \"multiple-sends\": \"warn\",\n \"reentrancy\": \"warn\",\n \"not-rely-on-block-hash\": \"warn\",\n \"not-rely-on-time\": \"warn\",\n \"state-visibility\": \"warn\",\n \"quotes\": [\"warn\",\"double\"],\n \"visibility-modifier-order\": \"warn\"\n }\n}\n"
- MythRilCheckOutputDir = "mythril"
- MythRilSolcJsonName = ".myhril.json"
- MythRilSolcJson = "{\n \"remappings\": [%s]\n}"
- MythRilSolcJsonReMappings = "\"%s/=node_modules/%s/\""
- MythRilCheck = "docker run --rm -v %s:/tmp -w /tmp mythril/myth analyze /tmp/%s --solc-json %s --execution-timeout 15"
- SlitherCheckOutputDir = "slither"
- SlitherCheck = "docker run --rm -v %s:/tmp bingjian/solidity_check:slither_091_1_0816 slither /tmp/%s"
-)
-
-var InkUrlMap = map[string]string{
- "Local": "ws://127.0.0.1:9944",
- "Rococo": "wss://rococo-contracts-rpc.polkadot.io",
- "Shibuya": "wss://rpc.shibuya.astar.network",
- "Shiden": "wss://rpc.shiden.astar.network",
-}
diff --git a/engine/consts/contract_check_enum.go b/engine/consts/contract_check_enum.go
deleted file mode 100644
index 15f371b4..00000000
--- a/engine/consts/contract_check_enum.go
+++ /dev/null
@@ -1,37 +0,0 @@
-package consts
-
-type ContractCheckEnum struct {
- Name string
- Result string
- Tool string
-}
-
-func contractCheckResult(name string, tool string) ContractCheckEnum {
- return ContractCheckEnum{
- Name: name,
- Tool: tool,
- }
-}
-
-var (
- ContractMethodsPropertiesReport = contractCheckResult("Contract Methods Properties Report", "sol-profiler")
- ContractStyleGuideValidationsReport = contractCheckResult("Contract Style Guide validations Report", "Solhint")
- ContractSecurityAnalysisReport = contractCheckResult("Contract Security Analysis Report", "mythril")
-)
-
-type ContractCheckResultDetails struct {
- Result string
- message string
-}
-
-func contractCheckResultDetails(result string, message string) ContractCheckResultDetails {
- return ContractCheckResultDetails{
- Result: result,
- message: message,
- }
-}
-
-var (
- CheckSuccess = contractCheckResultDetails("Success", "检查成功")
- CheckFail = contractCheckResultDetails("Fail", "检查失败")
-)
diff --git a/engine/dispatcher/dispatcher.go b/engine/dispatcher/dispatcher.go
deleted file mode 100644
index 28292243..00000000
--- a/engine/dispatcher/dispatcher.go
+++ /dev/null
@@ -1,138 +0,0 @@
-package dispatcher
-
-import (
- "github.com/hamster-shared/a-line/engine/executor"
- model2 "github.com/hamster-shared/a-line/engine/model"
- "math/rand"
-)
-
-type IDispatcher interface {
- // DispatchNode 选择节点
- DispatchNode(job *model2.Job) *model2.Node
- // Register 节点注册
- Register(node *model2.Node)
- // UnRegister 节点注销
- UnRegister(node *model2.Node)
-
- // HealthcheckNode 节点心跳
- HealthcheckNode(node *model2.Node)
-
- // SendJob 发送任务
- SendJob(job *model2.JobDetail, node *model2.Node)
-
- // CancelJob 取消任务
- CancelJob(job *model2.JobDetail, node *model2.Node)
-
- // GetExecutor 根据节点获取执行器
- // TODO ... 这个方法设计的不好,分布式机构后应当用api代替
- GetExecutor(node *model2.Node) executor.IExecutor
-}
-
-type Dispatcher struct {
- Channel chan model2.QueueMessage
- CallbackChannel chan model2.StatusChangeMessage
- nodes []*model2.Node
-}
-
-func NewDispatcher(channel chan model2.QueueMessage, callbackChannel chan model2.StatusChangeMessage) *Dispatcher {
- return &Dispatcher{
- Channel: channel,
- CallbackChannel: callbackChannel,
- nodes: make([]*model2.Node, 0),
- }
-}
-
-// DispatchNode 选择节点
-func (d *Dispatcher) DispatchNode(job *model2.Job) *model2.Node {
-
- //TODO ... 单机情况直接返回 本地
- if len(d.nodes) > 0 {
- return d.nodes[0]
- }
- return nil
-}
-
-// Register 节点注册
-func (d *Dispatcher) Register(node *model2.Node) {
- d.nodes = append(d.nodes, node)
- return
-}
-
-// UnRegister 节点注销
-func (d *Dispatcher) UnRegister(node *model2.Node) {
- return
-}
-
-// HealthcheckNode 节点心跳
-func (d *Dispatcher) HealthcheckNode(*model2.Node) {
- // TODO ... 检查注册的心跳信息,超过3分钟没有更新的节点,踢掉
- return
-}
-
-// SendJob 发送任务
-func (d *Dispatcher) SendJob(job *model2.JobDetail, node *model2.Node) {
-
- // TODO ... 单机情况下 不考虑节点,直接发送本地
- // TODO ... 集群情况下 通过注册的ip 地址进行api接口调用
-
- d.Channel <- model2.NewStartQueueMsg(job.Name, job.Id)
-
- return
-}
-
-// CancelJob 取消任务
-func (d *Dispatcher) CancelJob(job *model2.JobDetail, node *model2.Node) {
-
- d.Channel <- model2.NewStopQueueMsg(job.Name, job.Id)
- return
-}
-
-// GetExecutor 根据节点获取执行器
-// TODO ... 这个方法设计的不好,分布式机构后应当用api代替
-func (d *Dispatcher) GetExecutor(node *model2.Node) executor.IExecutor {
- return nil
-}
-
-type HttpDispatcher struct {
- Channel chan model2.QueueMessage
- nodes []*model2.Node
-}
-
-// DispatchNode 选择节点
-func (d *HttpDispatcher) DispatchNode(job *model2.Job) *model2.Node {
-
- data := rand.Intn(len(d.nodes))
- return d.nodes[data]
-}
-
-// Register 节点注册
-func (d *HttpDispatcher) Register(node *model2.Node) {
-
-}
-
-// UnRegister 节点注销
-func (d *HttpDispatcher) UnRegister(node *model2.Node) {
-
-}
-
-// HealthcheckNode 节点心跳
-func (d *HttpDispatcher) HealthcheckNode(node *model2.Node) {
-
-}
-
-// SendJob 发送任务
-func (d *HttpDispatcher) SendJob(job *model2.JobDetail, node *model2.Node) {
-
-}
-
-// CancelJob 取消任务
-func (d *HttpDispatcher) CancelJob(job *model2.JobDetail, node *model2.Node) {
-
-}
-
-// GetExecutor 根据节点获取执行器
-// TODO ... 这个方法设计的不好,分布式机构后应当用api代替
-func (d *HttpDispatcher) GetExecutor(node *model2.Node) executor.IExecutor {
-
- return nil
-}
diff --git a/engine/engin_test.go b/engine/engin_test.go
deleted file mode 100644
index ee18f433..00000000
--- a/engine/engin_test.go
+++ /dev/null
@@ -1,9 +0,0 @@
-package engine
-
-import (
- "testing"
-)
-
-func TestEngine(t *testing.T) {
-
-}
diff --git a/engine/engine.go b/engine/engine.go
deleted file mode 100644
index 62bab765..00000000
--- a/engine/engine.go
+++ /dev/null
@@ -1,150 +0,0 @@
-package engine
-
-import (
- "fmt"
- "github.com/hamster-shared/a-line/engine/dispatcher"
- "github.com/hamster-shared/a-line/engine/executor"
- "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/service"
- "os"
-)
-
-type Engine struct {
- channel chan model.QueueMessage
- callbackChannel chan model.StatusChangeMessage
- jobService service.IJobService
- dispatch dispatcher.IDispatcher
- executeClient *executor.ExecutorClient
-}
-
-func NewEngine() *Engine {
-
- channel := make(chan model.QueueMessage)
- callbackChannel := make(chan model.StatusChangeMessage)
- jobService := service.NewJobService()
- dispatch := dispatcher.NewDispatcher(channel, callbackChannel)
- executeClient := executor.NewExecutorClient(channel, callbackChannel, jobService)
-
- hostname, _ := os.Hostname()
-
- dispatch.Register(&model.Node{
- Name: hostname,
- Address: "127.0.0.1",
- })
-
- return &Engine{
- channel: channel,
- callbackChannel: callbackChannel,
- jobService: jobService,
- dispatch: dispatch,
- executeClient: executeClient,
- }
-}
-
-func (e *Engine) Start() {
- e.executeClient.Main()
-}
-
-func (e *Engine) CreateJob(name string, yaml string) error {
-
- return e.jobService.SaveJob(name, yaml)
-}
-
-func (e *Engine) DeleteJob(name string) error {
- return e.jobService.DeleteJob(name)
-}
-
-func (e *Engine) UpdateJob(name, newName, jobYaml string) error {
-
- return e.jobService.UpdateJob(name, newName, jobYaml)
-}
-
-func (e *Engine) GetJob(name string) *model.Job {
- return e.jobService.GetJobObject(name)
-}
-
-func (e *Engine) GetJobs(keyword string, page int, size int) *model.JobPage {
- return e.jobService.JobList(keyword, page, size)
-}
-
-func (e *Engine) ExecuteJob(name string) (*model.JobDetail, error) {
-
- job := e.jobService.GetJobObject(name)
- jobDetail, err := e.jobService.ExecuteJob(name)
- if err != nil {
- return nil, err
- }
- node := e.dispatch.DispatchNode(job)
- e.dispatch.SendJob(jobDetail, node)
- return jobDetail, nil
-}
-
-func (e *Engine) ReExecuteJob(name string, historyId int) error {
-
- err := e.jobService.ReExecuteJob(name, historyId)
- job := e.jobService.GetJobObject(name)
- jobDetail := e.jobService.GetJobDetail(name, historyId)
- node := e.dispatch.DispatchNode(job)
- e.dispatch.SendJob(jobDetail, node)
- return err
-}
-
-func (e *Engine) TerminalJob(name string, historyId int) error {
-
- err := e.jobService.StopJobDetail(name, historyId)
- if err != nil {
- return err
- }
- job := e.jobService.GetJobObject(name)
- jobDetail := e.jobService.GetJobDetail(name, historyId)
- node := e.dispatch.DispatchNode(job)
- e.dispatch.CancelJob(jobDetail, node)
- return nil
-}
-
-func (e *Engine) GetJobHistory(name string, historyId int) *model.JobDetail {
- return e.jobService.GetJobDetail(name, historyId)
-}
-
-func (e *Engine) GetJobHistorys(name string, page, size int) *model.JobDetailPage {
- return e.jobService.JobDetailList(name, page, size)
-}
-
-func (e *Engine) DeleteJobHistory(name string, historyId int) error {
- return e.jobService.DeleteJobDetail(name, historyId)
-}
-
-func (e *Engine) GetJobHistoryLog(name string, historyId int) *model.JobLog {
- return e.jobService.GetJobLog(name, historyId)
-}
-
-func (e *Engine) GetJobHistoryStageLog(name string, historyId int, stageName string, start int) *model.JobStageLog {
- return e.jobService.GetJobStageLog(name, historyId, stageName, start)
-}
-
-func (e *Engine) GetCodeInfo(name string, historyId int) string {
- jobDetail := e.jobService.GetJobDetail(name, historyId)
- if jobDetail != nil {
- return jobDetail.CodeInfo
- }
- return ""
-}
-
-func (e *Engine) RegisterStatusChangeHook(hookResult func(message model.StatusChangeMessage)) {
- for { //
-
- //3. 监听队列
- statusMsg, ok := <-e.callbackChannel
- if !ok {
- return
- }
-
- fmt.Println("=======[status callback]=========")
- fmt.Println(statusMsg)
- fmt.Println("=======[status callback]=========")
-
- if hookResult != nil {
- hookResult(statusMsg)
- }
- }
-}
diff --git a/engine/executor/client.go b/engine/executor/client.go
deleted file mode 100644
index ab59ee9d..00000000
--- a/engine/executor/client.go
+++ /dev/null
@@ -1,76 +0,0 @@
-package executor
-
-import (
- "github.com/hamster-shared/a-line/engine/logger"
- model2 "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/pipeline"
- "github.com/hamster-shared/a-line/engine/service"
-)
-
-func NewExecutorClient(channel chan model2.QueueMessage, callbackChannel chan model2.StatusChangeMessage, jobService service.IJobService) *ExecutorClient {
- return &ExecutorClient{
- executor: &Executor{
- cancelMap: make(map[string]func()),
- jobService: jobService,
- callbackChannel: callbackChannel,
- },
- channel: channel,
- callbackChannel: callbackChannel,
- }
-}
-
-type ExecutorClient struct {
- executor IExecutor
- channel chan model2.QueueMessage
- callbackChannel chan model2.StatusChangeMessage
-}
-
-func (c *ExecutorClient) Main() {
- //1. TODO... 注册节点
-
- //2. TODO... gorouting 发送定时心跳
-
- for { //
-
- //3. 监听队列
- queueMessage, ok := <-c.channel
- if !ok {
- return
- }
-
- //4.TODO...,获取job信息
-
- // TODO ... 计算jobId
- jobName := queueMessage.JobName
- jobId := queueMessage.JobId
-
- pipelineReader, err := c.executor.FetchJob(jobName)
-
- if err != nil {
- logger.Error(err)
- continue
- }
-
- //5. 解析pipeline
- job, err := pipeline.GetJobFromReader(pipelineReader)
-
- //6. 异步执行pipeline
- go func() {
- var err error
- if queueMessage.Command == model2.Command_Start {
- err = c.executor.Execute(jobId, job)
- } else if queueMessage.Command == model2.Command_Stop {
- err = c.executor.Cancel(jobId, job)
- }
-
- if err != nil {
-
- }
- }()
-
- }
-}
-
-func (c *ExecutorClient) Execute(jobId int, job *model2.Job) error {
- return c.executor.Execute(jobId, job)
-}
diff --git a/engine/executor/executor.go b/engine/executor/executor.go
deleted file mode 100644
index b1fdf6a4..00000000
--- a/engine/executor/executor.go
+++ /dev/null
@@ -1,259 +0,0 @@
-package executor
-
-import (
- "context"
- "fmt"
- "github.com/hamster-shared/a-line/engine/action"
- "github.com/hamster-shared/a-line/engine/logger"
- model2 "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/output"
- "github.com/hamster-shared/a-line/engine/service"
- "github.com/hamster-shared/a-line/engine/utils"
- "io"
- "os"
- "path"
- "strconv"
- "strings"
- "time"
-)
-
-type IExecutor interface {
-
- // FetchJob 获取任务
- FetchJob(name string) (io.Reader, error)
-
- // Execute 执行任务
- Execute(id int, job *model2.Job) error
-
- // HandlerLog 处理日志
- HandlerLog(jobId int)
-
- //SendResultToQueue 发送结果到队列
- SendResultToQueue(channel chan model2.StatusChangeMessage, jobWrapper *model2.JobDetail)
-
- Cancel(id int, job *model2.Job) error
-}
-
-type Executor struct {
- cancelMap map[string]func()
- jobService service.IJobService
- callbackChannel chan model2.StatusChangeMessage
-}
-
-// FetchJob 获取任务
-func (e *Executor) FetchJob(name string) (io.Reader, error) {
-
- //TODO... 根据 name 从 rpc 或 直接内部调用获取 job 的 pipeline 文件
- job := e.jobService.GetJob(name)
- return strings.NewReader(job), nil
-}
-
-// Execute 执行任务
-func (e *Executor) Execute(id int, job *model2.Job) error {
-
- // 1. 解析对 pipeline 进行任务排序
- stages, err := job.StageSort()
- jobWrapper := &model2.JobDetail{
- Id: id,
- Job: *job,
- Status: model2.STATUS_NOTRUN,
- Stages: stages,
- ActionResult: model2.ActionResult{
- Artifactorys: make([]model2.Artifactory, 0),
- Reports: make([]model2.Report, 0),
- },
- }
-
- if err != nil {
- return err
- }
-
- // 2. 初始化 执行器的上下文
-
- env := make([]string, 0)
- env = append(env, "NAME="+job.Name)
-
- homeDir, _ := os.UserHomeDir()
-
- engineContext := make(map[string]interface{})
- engineContext["hamsterRoot"] = path.Join(homeDir, "workdir")
- workdir := path.Join(engineContext["hamsterRoot"].(string), job.Name)
- engineContext["workdir"] = workdir
-
- err = os.MkdirAll(workdir, os.ModePerm)
-
- engineContext["name"] = job.Name
- engineContext["id"] = fmt.Sprintf("%d", id)
- engineContext["env"] = env
-
- if job.Parameter == nil {
- job.Parameter = make(map[string]string)
- }
-
- engineContext["parameter"] = job.Parameter
-
- ctx, cancel := context.WithCancel(context.WithValue(context.Background(), "stack", engineContext))
-
- // 将取消 hook 记录到内存中,用于中断程序
- e.cancelMap[strings.Join([]string{job.Name, strconv.Itoa(id)}, "/")] = cancel
-
- // 队列堆栈
- var stack utils.Stack[action.ActionHandler]
-
- jobWrapper.Status = model2.STATUS_RUNNING
- jobWrapper.StartTime = time.Now()
-
- executeAction := func(ah action.ActionHandler, job *model2.JobDetail) error {
- if jobWrapper.Status != model2.STATUS_RUNNING {
- return nil
- }
- err := ah.Pre()
- if err != nil {
- job.Status = model2.STATUS_FAIL
- fmt.Println(err)
- return err
- }
- stack.Push(ah)
- actionResult, err := ah.Hook()
- if actionResult != nil && len(actionResult.Artifactorys) > 0 {
- jobWrapper.Artifactorys = append(jobWrapper.Artifactorys, actionResult.Artifactorys...)
- }
- if actionResult != nil && len(actionResult.Reports) > 0 {
- jobWrapper.Reports = append(jobWrapper.Reports, actionResult.Reports...)
- }
- if actionResult != nil && actionResult.CodeInfo != "" {
- jobWrapper.CodeInfo = actionResult.CodeInfo
- }
- if err != nil {
- job.Status = model2.STATUS_FAIL
- return err
- }
- return nil
- }
-
- jobWrapper.Output = output.New(job.Name, jobWrapper.Id)
-
- for index, stageWapper := range jobWrapper.Stages {
- //TODO ... stage 的输出也需要换成堆栈方式
- logger.Info("stage: {")
- logger.Infof(" // %s", stageWapper.Name)
- stageWapper.Status = model2.STATUS_RUNNING
- stageWapper.StartTime = time.Now()
- jobWrapper.Stages[index] = stageWapper
- jobWrapper.Output.NewStage(stageWapper.Name)
- e.jobService.SaveJobDetail(jobWrapper.Name, jobWrapper)
-
- for index, step := range stageWapper.Stage.Steps {
- var ah action.ActionHandler
- if step.RunsOn != "" {
- ah = action.NewDockerEnv(step, ctx, jobWrapper.Output)
- err = executeAction(ah, jobWrapper)
- if err != nil {
- break
- }
- }
- stageWapper.Stage.Steps[index].StartTime = time.Now()
- stageWapper.Stage.Steps[index].Status = model2.STATUS_RUNNING
- if step.Uses == "" || step.Uses == "shell" {
- ah = action.NewShellAction(step, ctx, jobWrapper.Output)
- } else if step.Uses == "git-checkout" {
- ah = action.NewGitAction(step, ctx, jobWrapper.Output)
- } else if step.Uses == "hamster-ipfs" {
- ah = action.NewIpfsAction(step, ctx, jobWrapper.Output)
- } else if step.Uses == "hamster-pinata-ipfs" {
- ah = action.NewPinataIpfsAction(step, ctx, jobWrapper.Output)
- } else if step.Uses == "hamster-artifactory" {
- ah = action.NewArtifactoryAction(step, ctx, jobWrapper.Output)
- } else if step.Uses == "deploy-contract" {
- ah = action.NewTruffleDeployAction(step, ctx, jobWrapper.Output)
- } else if step.Uses == "sol-profiler-check" {
- ah = action.NewSolProfilerAction(step, ctx, jobWrapper.Output)
- } else if step.Uses == "solhint-check" {
- ah = action.NewSolHintAction(step, ctx, jobWrapper.Output)
- } else if step.Uses == "mythril-check" {
- ah = action.NewMythRilAction(step, ctx, jobWrapper.Output)
- } else if step.Uses == "slither-check" {
- ah = action.NewSlitherAction(step, ctx, jobWrapper.Output)
- } else if step.Uses == "check-aggregation" {
- ah = action.NewCheckAggregationAction(step, ctx, jobWrapper.Output)
- } else if step.Uses == "deploy-ink-contract" {
- ah = action.NewInkAction(step, ctx, jobWrapper.Output)
- } else if step.Uses == "workdir" {
- ah = action.NewWorkdirAction(step, ctx, jobWrapper.Output)
- } else if strings.Contains(step.Uses, "/") {
- ah = action.NewRemoteAction(step, ctx)
- }
- err = executeAction(ah, jobWrapper)
- dataTime := time.Now().Sub(stageWapper.Stage.Steps[index].StartTime)
- stageWapper.Stage.Steps[index].Duration = dataTime.Milliseconds()
- if err != nil {
- stageWapper.Stage.Steps[index].Status = model2.STATUS_FAIL
- break
- }
- stageWapper.Stage.Steps[index].Status = model2.STATUS_SUCCESS
- }
-
- for !stack.IsEmpty() {
- ah, _ := stack.Pop()
- _ = ah.Post()
- }
-
- if err != nil {
- stageWapper.Status = model2.STATUS_FAIL
- } else {
- stageWapper.Status = model2.STATUS_SUCCESS
- }
- dataTime := time.Now().Sub(stageWapper.StartTime)
- stageWapper.Duration = dataTime.Milliseconds()
- jobWrapper.Stages[index] = stageWapper
- e.jobService.SaveJobDetail(jobWrapper.Name, jobWrapper)
- logger.Info("}")
- if err != nil {
- cancel()
- break
- }
-
- }
- jobWrapper.Output.Done()
-
- delete(e.cancelMap, job.Name)
- if err == nil {
- jobWrapper.Status = model2.STATUS_SUCCESS
- } else {
- jobWrapper.Status = model2.STATUS_FAIL
- jobWrapper.Error = err.Error()
- }
-
- dataTime := time.Now().Sub(jobWrapper.StartTime)
- jobWrapper.Duration = dataTime.Milliseconds()
- e.jobService.SaveJobDetail(jobWrapper.Name, jobWrapper)
-
- //TODO ... 发送结果到队列
- e.SendResultToQueue(e.callbackChannel, jobWrapper)
- //_ = os.RemoveAll(path.Join(engineContext["hamsterRoot"].(string), job.Name))
-
- return err
-
-}
-
-// HandlerLog 处理日志
-func (e *Executor) HandlerLog(jobId int) {
-
- //TODO ...
-}
-
-// SendResultToQueue 发送结果到队列
-func (e *Executor) SendResultToQueue(channel chan model2.StatusChangeMessage, job *model2.JobDetail) {
- //TODO ...
- channel <- model2.NewStatusChangeMsg(job.Name, job.Id, job.Status)
-}
-
-// Cancel 取消
-func (e *Executor) Cancel(id int, job *model2.Job) error {
-
- cancel, ok := e.cancelMap[strings.Join([]string{job.Name, strconv.Itoa(id)}, "/")]
- if ok {
- cancel()
- }
- return nil
-}
diff --git a/engine/grpc/api/aline.pb.go b/engine/grpc/api/aline.pb.go
deleted file mode 100644
index 1ca27b7f..00000000
--- a/engine/grpc/api/aline.pb.go
+++ /dev/null
@@ -1,438 +0,0 @@
-// Code generated by protoc-gen-go. DO NOT EDIT.
-// versions:
-// protoc-gen-go v1.28.1
-// protoc v3.21.4
-// source: pkg/grpc/api/aline.proto
-
-package api
-
-import (
- protoreflect "google.golang.org/protobuf/reflect/protoreflect"
- protoimpl "google.golang.org/protobuf/runtime/protoimpl"
- reflect "reflect"
- sync "sync"
-)
-
-const (
- // Verify that this generated code is sufficiently up-to-date.
- _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
- // Verify that runtime/protoimpl is sufficiently up-to-date.
- _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
-)
-
-type AlineMessage struct {
- state protoimpl.MessageState
- sizeCache protoimpl.SizeCache
- unknownFields protoimpl.UnknownFields
-
- // 1: register 2: offline 3: heartbeat 4: execute 5: cancel 6: executeResultNotify 7: getLog
- Type int64 `protobuf:"varint,1,opt,name=type,proto3" json:"type,omitempty"`
- // registry
- Address string `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"`
- ExecReq *ExecuteReq `protobuf:"bytes,3,opt,name=execReq,proto3" json:"execReq,omitempty"`
- // execute result
- Result string `protobuf:"bytes,4,opt,name=result,proto3" json:"result,omitempty"`
- // log
- Log *Log `protobuf:"bytes,5,opt,name=log,proto3" json:"log,omitempty"`
-}
-
-func (x *AlineMessage) Reset() {
- *x = AlineMessage{}
- if protoimpl.UnsafeEnabled {
- mi := &file_pkg_grpc_api_aline_proto_msgTypes[0]
- ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
- ms.StoreMessageInfo(mi)
- }
-}
-
-func (x *AlineMessage) String() string {
- return protoimpl.X.MessageStringOf(x)
-}
-
-func (*AlineMessage) ProtoMessage() {}
-
-func (x *AlineMessage) ProtoReflect() protoreflect.Message {
- mi := &file_pkg_grpc_api_aline_proto_msgTypes[0]
- if protoimpl.UnsafeEnabled && x != nil {
- ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
- if ms.LoadMessageInfo() == nil {
- ms.StoreMessageInfo(mi)
- }
- return ms
- }
- return mi.MessageOf(x)
-}
-
-// Deprecated: Use AlineMessage.ProtoReflect.Descriptor instead.
-func (*AlineMessage) Descriptor() ([]byte, []int) {
- return file_pkg_grpc_api_aline_proto_rawDescGZIP(), []int{0}
-}
-
-func (x *AlineMessage) GetType() int64 {
- if x != nil {
- return x.Type
- }
- return 0
-}
-
-func (x *AlineMessage) GetAddress() string {
- if x != nil {
- return x.Address
- }
- return ""
-}
-
-func (x *AlineMessage) GetExecReq() *ExecuteReq {
- if x != nil {
- return x.ExecReq
- }
- return nil
-}
-
-func (x *AlineMessage) GetResult() string {
- if x != nil {
- return x.Result
- }
- return ""
-}
-
-func (x *AlineMessage) GetLog() *Log {
- if x != nil {
- return x.Log
- }
- return nil
-}
-
-type ExecuteReq struct {
- state protoimpl.MessageState
- sizeCache protoimpl.SizeCache
- unknownFields protoimpl.UnknownFields
-
- // pipeline file
- PipelineFile string `protobuf:"bytes,1,opt,name=pipelineFile,proto3" json:"pipelineFile,omitempty"`
- // job exec id
- JobDetailId int64 `protobuf:"varint,2,opt,name=jobDetailId,proto3" json:"jobDetailId,omitempty"`
-}
-
-func (x *ExecuteReq) Reset() {
- *x = ExecuteReq{}
- if protoimpl.UnsafeEnabled {
- mi := &file_pkg_grpc_api_aline_proto_msgTypes[1]
- ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
- ms.StoreMessageInfo(mi)
- }
-}
-
-func (x *ExecuteReq) String() string {
- return protoimpl.X.MessageStringOf(x)
-}
-
-func (*ExecuteReq) ProtoMessage() {}
-
-func (x *ExecuteReq) ProtoReflect() protoreflect.Message {
- mi := &file_pkg_grpc_api_aline_proto_msgTypes[1]
- if protoimpl.UnsafeEnabled && x != nil {
- ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
- if ms.LoadMessageInfo() == nil {
- ms.StoreMessageInfo(mi)
- }
- return ms
- }
- return mi.MessageOf(x)
-}
-
-// Deprecated: Use ExecuteReq.ProtoReflect.Descriptor instead.
-func (*ExecuteReq) Descriptor() ([]byte, []int) {
- return file_pkg_grpc_api_aline_proto_rawDescGZIP(), []int{1}
-}
-
-func (x *ExecuteReq) GetPipelineFile() string {
- if x != nil {
- return x.PipelineFile
- }
- return ""
-}
-
-func (x *ExecuteReq) GetJobDetailId() int64 {
- if x != nil {
- return x.JobDetailId
- }
- return 0
-}
-
-type ExecuteResult struct {
- state protoimpl.MessageState
- sizeCache protoimpl.SizeCache
- unknownFields protoimpl.UnknownFields
-
- JobDetail string `protobuf:"bytes,1,opt,name=jobDetail,proto3" json:"jobDetail,omitempty"`
- StartTime string `protobuf:"bytes,2,opt,name=startTime,proto3" json:"startTime,omitempty"`
- Duration int64 `protobuf:"varint,3,opt,name=duration,proto3" json:"duration,omitempty"`
-}
-
-func (x *ExecuteResult) Reset() {
- *x = ExecuteResult{}
- if protoimpl.UnsafeEnabled {
- mi := &file_pkg_grpc_api_aline_proto_msgTypes[2]
- ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
- ms.StoreMessageInfo(mi)
- }
-}
-
-func (x *ExecuteResult) String() string {
- return protoimpl.X.MessageStringOf(x)
-}
-
-func (*ExecuteResult) ProtoMessage() {}
-
-func (x *ExecuteResult) ProtoReflect() protoreflect.Message {
- mi := &file_pkg_grpc_api_aline_proto_msgTypes[2]
- if protoimpl.UnsafeEnabled && x != nil {
- ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
- if ms.LoadMessageInfo() == nil {
- ms.StoreMessageInfo(mi)
- }
- return ms
- }
- return mi.MessageOf(x)
-}
-
-// Deprecated: Use ExecuteResult.ProtoReflect.Descriptor instead.
-func (*ExecuteResult) Descriptor() ([]byte, []int) {
- return file_pkg_grpc_api_aline_proto_rawDescGZIP(), []int{2}
-}
-
-func (x *ExecuteResult) GetJobDetail() string {
- if x != nil {
- return x.JobDetail
- }
- return ""
-}
-
-func (x *ExecuteResult) GetStartTime() string {
- if x != nil {
- return x.StartTime
- }
- return ""
-}
-
-func (x *ExecuteResult) GetDuration() int64 {
- if x != nil {
- return x.Duration
- }
- return 0
-}
-
-type Log struct {
- state protoimpl.MessageState
- sizeCache protoimpl.SizeCache
- unknownFields protoimpl.UnknownFields
-
- Stage string `protobuf:"bytes,1,opt,name=stage,proto3" json:"stage,omitempty"`
- Content string `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"`
- More bool `protobuf:"varint,3,opt,name=more,proto3" json:"more,omitempty"`
-}
-
-func (x *Log) Reset() {
- *x = Log{}
- if protoimpl.UnsafeEnabled {
- mi := &file_pkg_grpc_api_aline_proto_msgTypes[3]
- ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
- ms.StoreMessageInfo(mi)
- }
-}
-
-func (x *Log) String() string {
- return protoimpl.X.MessageStringOf(x)
-}
-
-func (*Log) ProtoMessage() {}
-
-func (x *Log) ProtoReflect() protoreflect.Message {
- mi := &file_pkg_grpc_api_aline_proto_msgTypes[3]
- if protoimpl.UnsafeEnabled && x != nil {
- ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
- if ms.LoadMessageInfo() == nil {
- ms.StoreMessageInfo(mi)
- }
- return ms
- }
- return mi.MessageOf(x)
-}
-
-// Deprecated: Use Log.ProtoReflect.Descriptor instead.
-func (*Log) Descriptor() ([]byte, []int) {
- return file_pkg_grpc_api_aline_proto_rawDescGZIP(), []int{3}
-}
-
-func (x *Log) GetStage() string {
- if x != nil {
- return x.Stage
- }
- return ""
-}
-
-func (x *Log) GetContent() string {
- if x != nil {
- return x.Content
- }
- return ""
-}
-
-func (x *Log) GetMore() bool {
- if x != nil {
- return x.More
- }
- return false
-}
-
-var File_pkg_grpc_api_aline_proto protoreflect.FileDescriptor
-
-var file_pkg_grpc_api_aline_proto_rawDesc = []byte{
- 0x0a, 0x18, 0x70, 0x6b, 0x67, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61,
- 0x6c, 0x69, 0x6e, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x03, 0x61, 0x70, 0x69, 0x22,
- 0x9b, 0x01, 0x0a, 0x0c, 0x41, 0x6c, 0x69, 0x6e, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
- 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04,
- 0x74, 0x79, 0x70, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18,
- 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x29,
- 0x0a, 0x07, 0x65, 0x78, 0x65, 0x63, 0x52, 0x65, 0x71, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32,
- 0x0f, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x52, 0x65, 0x71,
- 0x52, 0x07, 0x65, 0x78, 0x65, 0x63, 0x52, 0x65, 0x71, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73,
- 0x75, 0x6c, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c,
- 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6c, 0x6f, 0x67, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08,
- 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4c, 0x6f, 0x67, 0x52, 0x03, 0x6c, 0x6f, 0x67, 0x22, 0x52, 0x0a,
- 0x0a, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x52, 0x65, 0x71, 0x12, 0x22, 0x0a, 0x0c, 0x70,
- 0x69, 0x70, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28,
- 0x09, 0x52, 0x0c, 0x70, 0x69, 0x70, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x12,
- 0x20, 0x0a, 0x0b, 0x6a, 0x6f, 0x62, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x49, 0x64, 0x18, 0x02,
- 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x6a, 0x6f, 0x62, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x49,
- 0x64, 0x22, 0x67, 0x0a, 0x0d, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x52, 0x65, 0x73, 0x75,
- 0x6c, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x6a, 0x6f, 0x62, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x18,
- 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6a, 0x6f, 0x62, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c,
- 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20,
- 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x61, 0x72, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1a,
- 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03,
- 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x49, 0x0a, 0x03, 0x4c, 0x6f,
- 0x67, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
- 0x52, 0x05, 0x73, 0x74, 0x61, 0x67, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65,
- 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e,
- 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6d, 0x6f, 0x72, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52,
- 0x04, 0x6d, 0x6f, 0x72, 0x65, 0x32, 0x43, 0x0a, 0x08, 0x41, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x50,
- 0x43, 0x12, 0x37, 0x0a, 0x09, 0x41, 0x6c, 0x69, 0x6e, 0x65, 0x43, 0x68, 0x61, 0x74, 0x12, 0x11,
- 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x41, 0x6c, 0x69, 0x6e, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67,
- 0x65, 0x1a, 0x11, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x41, 0x6c, 0x69, 0x6e, 0x65, 0x4d, 0x65, 0x73,
- 0x73, 0x61, 0x67, 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x42, 0x5e, 0x0a, 0x1f, 0x63, 0x6f,
- 0x6d, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x68, 0x61, 0x6d, 0x73, 0x74, 0x65, 0x72,
- 0x2d, 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2e, 0x61, 0x6c, 0x69, 0x6e, 0x65, 0x42, 0x0a, 0x41,
- 0x6c, 0x69, 0x6e, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x2d, 0x67, 0x69, 0x74,
- 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x68, 0x61, 0x6d, 0x73, 0x74, 0x65, 0x72, 0x2d,
- 0x73, 0x68, 0x61, 0x72, 0x65, 0x64, 0x2f, 0x61, 0x2d, 0x6c, 0x69, 0x6e, 0x65, 0x2f, 0x70, 0x6b,
- 0x67, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
- 0x6f, 0x33,
-}
-
-var (
- file_pkg_grpc_api_aline_proto_rawDescOnce sync.Once
- file_pkg_grpc_api_aline_proto_rawDescData = file_pkg_grpc_api_aline_proto_rawDesc
-)
-
-func file_pkg_grpc_api_aline_proto_rawDescGZIP() []byte {
- file_pkg_grpc_api_aline_proto_rawDescOnce.Do(func() {
- file_pkg_grpc_api_aline_proto_rawDescData = protoimpl.X.CompressGZIP(file_pkg_grpc_api_aline_proto_rawDescData)
- })
- return file_pkg_grpc_api_aline_proto_rawDescData
-}
-
-var file_pkg_grpc_api_aline_proto_msgTypes = make([]protoimpl.MessageInfo, 4)
-var file_pkg_grpc_api_aline_proto_goTypes = []interface{}{
- (*AlineMessage)(nil), // 0: api.AlineMessage
- (*ExecuteReq)(nil), // 1: api.ExecuteReq
- (*ExecuteResult)(nil), // 2: api.ExecuteResult
- (*Log)(nil), // 3: api.Log
-}
-var file_pkg_grpc_api_aline_proto_depIdxs = []int32{
- 1, // 0: api.AlineMessage.execReq:type_name -> api.ExecuteReq
- 3, // 1: api.AlineMessage.log:type_name -> api.Log
- 0, // 2: api.AlineRPC.AlineChat:input_type -> api.AlineMessage
- 0, // 3: api.AlineRPC.AlineChat:output_type -> api.AlineMessage
- 3, // [3:4] is the sub-list for method output_type
- 2, // [2:3] is the sub-list for method input_type
- 2, // [2:2] is the sub-list for extension type_name
- 2, // [2:2] is the sub-list for extension extendee
- 0, // [0:2] is the sub-list for field type_name
-}
-
-func init() { file_pkg_grpc_api_aline_proto_init() }
-func file_pkg_grpc_api_aline_proto_init() {
- if File_pkg_grpc_api_aline_proto != nil {
- return
- }
- if !protoimpl.UnsafeEnabled {
- file_pkg_grpc_api_aline_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
- switch v := v.(*AlineMessage); i {
- case 0:
- return &v.state
- case 1:
- return &v.sizeCache
- case 2:
- return &v.unknownFields
- default:
- return nil
- }
- }
- file_pkg_grpc_api_aline_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
- switch v := v.(*ExecuteReq); i {
- case 0:
- return &v.state
- case 1:
- return &v.sizeCache
- case 2:
- return &v.unknownFields
- default:
- return nil
- }
- }
- file_pkg_grpc_api_aline_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
- switch v := v.(*ExecuteResult); i {
- case 0:
- return &v.state
- case 1:
- return &v.sizeCache
- case 2:
- return &v.unknownFields
- default:
- return nil
- }
- }
- file_pkg_grpc_api_aline_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
- switch v := v.(*Log); i {
- case 0:
- return &v.state
- case 1:
- return &v.sizeCache
- case 2:
- return &v.unknownFields
- default:
- return nil
- }
- }
- }
- type x struct{}
- out := protoimpl.TypeBuilder{
- File: protoimpl.DescBuilder{
- GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
- RawDescriptor: file_pkg_grpc_api_aline_proto_rawDesc,
- NumEnums: 0,
- NumMessages: 4,
- NumExtensions: 0,
- NumServices: 1,
- },
- GoTypes: file_pkg_grpc_api_aline_proto_goTypes,
- DependencyIndexes: file_pkg_grpc_api_aline_proto_depIdxs,
- MessageInfos: file_pkg_grpc_api_aline_proto_msgTypes,
- }.Build()
- File_pkg_grpc_api_aline_proto = out.File
- file_pkg_grpc_api_aline_proto_rawDesc = nil
- file_pkg_grpc_api_aline_proto_goTypes = nil
- file_pkg_grpc_api_aline_proto_depIdxs = nil
-}
diff --git a/engine/grpc/api/aline.proto b/engine/grpc/api/aline.proto
deleted file mode 100644
index 53c21e79..00000000
--- a/engine/grpc/api/aline.proto
+++ /dev/null
@@ -1,50 +0,0 @@
-syntax = "proto3";
-
-option go_package = "github.com/hamster-shared/a-line/pkg/grpc/api";
-option java_multiple_files = true;
-option java_package = "com.github.hamster-shared.aline";
-option java_outer_classname = "AlineProto";
-
-package api;
-
-service AlineRPC {
-
- rpc AlineChat(stream AlineMessage) returns (stream AlineMessage){}
-}
-
-
-message AlineMessage {
- // 1: register 2: offline 3: heartbeat 4: execute 5: cancel 6: executeResultNotify 7: getLog
- int64 type = 1 ;
-
- // registry
- string address = 2;
-
- ExecuteReq execReq = 3;
-
- // execute result
- string result = 4;
-
- // log
- Log log = 5;
-}
-
-message ExecuteReq {
- // pipeline file
- string pipelineFile = 1;
-
- // job exec id
- int64 jobDetailId = 2;
-}
-
-message ExecuteResult {
- string jobDetail = 1;
- string startTime = 2;
- int64 duration = 3;
-}
-
-message Log {
- string stage = 1;
- string content = 2;
- bool more = 3;
-}
diff --git a/engine/grpc/api/aline_grpc.pb.go b/engine/grpc/api/aline_grpc.pb.go
deleted file mode 100644
index bacd1342..00000000
--- a/engine/grpc/api/aline_grpc.pb.go
+++ /dev/null
@@ -1,137 +0,0 @@
-// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
-// versions:
-// - protoc-gen-go-grpc v1.2.0
-// - protoc v3.21.4
-// source: pkg/grpc/api/aline.proto
-
-package api
-
-import (
- context "context"
- grpc "google.golang.org/grpc"
- codes "google.golang.org/grpc/codes"
- status "google.golang.org/grpc/status"
-)
-
-// This is a compile-time assertion to ensure that this generated file
-// is compatible with the grpc package it is being compiled against.
-// Requires gRPC-Go v1.32.0 or later.
-const _ = grpc.SupportPackageIsVersion7
-
-// AlineRPCClient is the client API for AlineRPC service.
-//
-// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
-type AlineRPCClient interface {
- AlineChat(ctx context.Context, opts ...grpc.CallOption) (AlineRPC_AlineChatClient, error)
-}
-
-type alineRPCClient struct {
- cc grpc.ClientConnInterface
-}
-
-func NewAlineRPCClient(cc grpc.ClientConnInterface) AlineRPCClient {
- return &alineRPCClient{cc}
-}
-
-func (c *alineRPCClient) AlineChat(ctx context.Context, opts ...grpc.CallOption) (AlineRPC_AlineChatClient, error) {
- stream, err := c.cc.NewStream(ctx, &AlineRPC_ServiceDesc.Streams[0], "/api.AlineRPC/AlineChat", opts...)
- if err != nil {
- return nil, err
- }
- x := &alineRPCAlineChatClient{stream}
- return x, nil
-}
-
-type AlineRPC_AlineChatClient interface {
- Send(*AlineMessage) error
- Recv() (*AlineMessage, error)
- grpc.ClientStream
-}
-
-type alineRPCAlineChatClient struct {
- grpc.ClientStream
-}
-
-func (x *alineRPCAlineChatClient) Send(m *AlineMessage) error {
- return x.ClientStream.SendMsg(m)
-}
-
-func (x *alineRPCAlineChatClient) Recv() (*AlineMessage, error) {
- m := new(AlineMessage)
- if err := x.ClientStream.RecvMsg(m); err != nil {
- return nil, err
- }
- return m, nil
-}
-
-// AlineRPCServer is the server API for AlineRPC service.
-// All implementations must embed UnimplementedAlineRPCServer
-// for forward compatibility
-type AlineRPCServer interface {
- AlineChat(AlineRPC_AlineChatServer) error
- mustEmbedUnimplementedAlineRPCServer()
-}
-
-// UnimplementedAlineRPCServer must be embedded to have forward compatible implementations.
-type UnimplementedAlineRPCServer struct {
-}
-
-func (UnimplementedAlineRPCServer) AlineChat(AlineRPC_AlineChatServer) error {
- return status.Errorf(codes.Unimplemented, "method AlineChat not implemented")
-}
-func (UnimplementedAlineRPCServer) mustEmbedUnimplementedAlineRPCServer() {}
-
-// UnsafeAlineRPCServer may be embedded to opt out of forward compatibility for this service.
-// Use of this interface is not recommended, as added methods to AlineRPCServer will
-// result in compilation errors.
-type UnsafeAlineRPCServer interface {
- mustEmbedUnimplementedAlineRPCServer()
-}
-
-func RegisterAlineRPCServer(s grpc.ServiceRegistrar, srv AlineRPCServer) {
- s.RegisterService(&AlineRPC_ServiceDesc, srv)
-}
-
-func _AlineRPC_AlineChat_Handler(srv interface{}, stream grpc.ServerStream) error {
- return srv.(AlineRPCServer).AlineChat(&alineRPCAlineChatServer{stream})
-}
-
-type AlineRPC_AlineChatServer interface {
- Send(*AlineMessage) error
- Recv() (*AlineMessage, error)
- grpc.ServerStream
-}
-
-type alineRPCAlineChatServer struct {
- grpc.ServerStream
-}
-
-func (x *alineRPCAlineChatServer) Send(m *AlineMessage) error {
- return x.ServerStream.SendMsg(m)
-}
-
-func (x *alineRPCAlineChatServer) Recv() (*AlineMessage, error) {
- m := new(AlineMessage)
- if err := x.ServerStream.RecvMsg(m); err != nil {
- return nil, err
- }
- return m, nil
-}
-
-// AlineRPC_ServiceDesc is the grpc.ServiceDesc for AlineRPC service.
-// It's only intended for direct use with grpc.RegisterService,
-// and not to be introspected or modified (even as a copy)
-var AlineRPC_ServiceDesc = grpc.ServiceDesc{
- ServiceName: "api.AlineRPC",
- HandlerType: (*AlineRPCServer)(nil),
- Methods: []grpc.MethodDesc{},
- Streams: []grpc.StreamDesc{
- {
- StreamName: "AlineChat",
- Handler: _AlineRPC_AlineChat_Handler,
- ServerStreams: true,
- ClientStreams: true,
- },
- },
- Metadata: "pkg/grpc/api/aline.proto",
-}
diff --git a/engine/grpc/client/aline_grpc_client.go b/engine/grpc/client/aline_grpc_client.go
deleted file mode 100644
index a31cf571..00000000
--- a/engine/grpc/client/aline_grpc_client.go
+++ /dev/null
@@ -1,47 +0,0 @@
-package client
-
-import (
- "context"
- "github.com/hamster-shared/a-line/engine/grpc/api"
- "io"
- "log"
- "time"
-)
-
-func runChat(client api.AlineRPCClient) {
- ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
- defer cancel()
- stream, err := client.AlineChat(ctx)
- if err != nil {
- log.Fatalf("client.RouteChat failed: %v", err)
- }
- waitc := make(chan struct{})
- go func() {
- for {
- in, err := stream.Recv()
- if err == io.EOF {
- // read done.
- close(waitc)
- return
- }
- if err != nil {
- log.Fatalf("client.RouteChat failed: %v", err)
- }
- log.Printf("Got message %s at point(%d, %d)", in.String(), in.Type, in.GetType())
- }
- }()
-
- notes := []api.AlineMessage{
- api.AlineMessage{
- Type: 1,
- },
- }
-
- for _, note := range notes {
- if err := stream.Send(¬e); err != nil {
- log.Fatalf("client.RouteChat: stream.Send(%v) failed: %v", note, err)
- }
- }
- stream.CloseSend()
- <-waitc
-}
diff --git a/engine/grpc/client/aline_grpc_client_test.go b/engine/grpc/client/aline_grpc_client_test.go
deleted file mode 100644
index ed246839..00000000
--- a/engine/grpc/client/aline_grpc_client_test.go
+++ /dev/null
@@ -1,19 +0,0 @@
-package client
-
-import (
- pb "github.com/hamster-shared/a-line/engine/grpc/api"
- "github.com/stretchr/testify/assert"
- "google.golang.org/grpc"
- "google.golang.org/grpc/credentials/insecure"
- "testing"
-)
-
-func TestClient(t *testing.T) {
- var opts []grpc.DialOption
- opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
- conn, err := grpc.Dial("127.0.0.1:50051", opts...)
- assert.NoError(t, err)
- client := pb.NewAlineRPCClient(conn)
-
- runChat(client)
-}
diff --git a/engine/grpc/server/aline_grpc_server.go b/engine/grpc/server/aline_grpc_server.go
deleted file mode 100644
index 8cc58d9b..00000000
--- a/engine/grpc/server/aline_grpc_server.go
+++ /dev/null
@@ -1,50 +0,0 @@
-package server
-
-import (
- "fmt"
- "github.com/hamster-shared/a-line/engine/grpc/api"
- "io"
- "sync"
-)
-
-type AlineGRPCServer struct {
- api.UnimplementedAlineRPCServer
-
- mu sync.Mutex // protects routeNotes
-}
-
-func (s *AlineGRPCServer) AlineChat(stream api.AlineRPC_AlineChatServer) error {
- for {
- in, err := stream.Recv()
- if err == io.EOF {
- return nil
- }
- if err != nil {
- return err
- }
- t := in.Type
- fmt.Println(t)
-
- s.mu.Lock()
- //s.routeNotes[key] = append(s.routeNotes[key], in)
- // Note: this copy prevents blocking other clients while serving this one.
- // We don't need to do a deep copy, because elements in the slice are
- // insert-only and never modified.
- //rn := make([]*pb.RouteNote, len(s.routeNotes[key]))
- //copy(rn, s.routeNotes[key])
- s.mu.Unlock()
-
- execMsg := &api.AlineMessage{
- Type: 1,
- }
-
- if err := stream.Send(execMsg); err != nil {
- fmt.Println("send execMsg success")
- }
- //for _, note := range rn {
- // if err := stream.Send(note); err != nil {
- // return err
- // }
- //}
- }
-}
diff --git a/engine/grpc/server/aline_grpc_server_test.go b/engine/grpc/server/aline_grpc_server_test.go
deleted file mode 100644
index 6b1f1262..00000000
--- a/engine/grpc/server/aline_grpc_server_test.go
+++ /dev/null
@@ -1,27 +0,0 @@
-package server
-
-import (
- "fmt"
- pb "github.com/hamster-shared/a-line/engine/grpc/api"
- "github.com/stretchr/testify/assert"
- "google.golang.org/grpc"
- "net"
- "testing"
-)
-
-func newServer() *AlineGRPCServer {
- return &AlineGRPCServer{}
-}
-
-func TestStartServer(t *testing.T) {
- var opts []grpc.ServerOption
- grpcServer := grpc.NewServer(opts...)
- pb.RegisterAlineRPCServer(grpcServer, newServer())
- lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", 50051))
- if err != nil {
- assert.NoError(t, err)
- return
- }
- grpcServer.Serve(lis)
-
-}
diff --git a/engine/logger/logger.go b/engine/logger/logger.go
deleted file mode 100644
index 291ff606..00000000
--- a/engine/logger/logger.go
+++ /dev/null
@@ -1,263 +0,0 @@
-// logger 提供封装好的 logrus 日志库
-// 日志等级从底到高分别为:trace, debug, info, warn, error, fatal, panic
-// trace 用于跟踪程序运行过程中的一些细节
-// debug 用于调试程序
-// info 用于重要信息
-// warn 用于警告信息
-// error 用于错误信息
-// fatal 用于致命错误,程序将退出
-// panic 用于致命错误,程序将崩溃退出,并展开堆栈调用信息
-package logger
-
-import (
- "bytes"
- "fmt"
- "io"
- "os"
- "path/filepath"
- "runtime"
- "strings"
- "sync"
- "time"
-
- nested "github.com/antonfisher/nested-logrus-formatter"
- "github.com/sirupsen/logrus"
-)
-
-var l *Logger
-
-type Logger struct {
- mu sync.Mutex
- l *logrus.Logger
- f *os.File
- mem *bytes.Buffer
-}
-
-func Init() *Logger {
- l = &Logger{
- l: logrus.New(),
- }
- return l
-}
-
-func (l *Logger) SetLevel(level logrus.Level) *Logger {
- l.l.SetLevel(level)
- return l
-}
-
-func (l *Logger) ToStdout() *Logger {
- l.l.SetOutput(os.Stdout)
- l.l.SetFormatter(formatter(true))
- return l
-}
-
-func (l *Logger) ToFile() *Logger {
- l.makeLogDir()
- if l.logFile() == nil {
- return l.ToStdout()
- }
- l.l.SetOutput(l.logFile())
- l.l.SetFormatter(formatter(false))
- return l
-}
-
-func (l *Logger) ToMemory() *Logger {
- l.mem = new(bytes.Buffer)
- l.l.SetOutput(l.mem)
- l.l.SetFormatter(formatter(false))
- return l
-}
-
-func (l *Logger) ToStdoutAndFile() *Logger {
- l.makeLogDir()
- if l.logFile() == nil {
- return l.ToStdout()
- }
- multi := io.MultiWriter(os.Stdout, l.logFile())
- l.l.SetOutput(multi)
- l.l.SetFormatter(formatter(false))
- return l
-}
-
-func (l *Logger) ToStdoutAndMemory() *Logger {
- l.mem = new(bytes.Buffer)
- multi := io.MultiWriter(os.Stdout, l.mem)
- l.l.SetOutput(multi)
- l.l.SetFormatter(formatter(false))
- return l
-}
-
-func (l *Logger) ToStdoutAndFileAndMemory() *Logger {
- l.makeLogDir()
- if l.logFile() == nil {
- return l.ToStdoutAndMemory()
- }
- l.mem = new(bytes.Buffer)
- multi := io.MultiWriter(os.Stdout, l.logFile(), l.mem)
- l.l.SetOutput(multi)
- l.l.SetFormatter(formatter(false))
- return l
-}
-
-func Buffer() *bytes.Buffer {
- return l.mem
-}
-
-func ClearBuffer() {
- if l.mem == nil {
- return
- }
- l.mem.Reset()
-}
-
-func AutoClearBuffer(len int) {
- if l.mem == nil {
- return
- }
- go func(len int) {
- for {
- time.Sleep(time.Second * 1)
- if l.mem.Len() > len {
- ClearBuffer()
- }
- }
- }(len)
-}
-
-func (l *Logger) makeLogDir() {
- err := os.MkdirAll("log", os.ModePerm)
- if err != nil {
- fmt.Printf("Failed to create log dir, err: %s\n", err)
- }
-}
-
-func (l *Logger) logFile() *os.File {
- l.mu.Lock()
- if l.f != nil {
- l.mu.Unlock()
- return l.f
- }
-
- filename := time.Now().Local().Format("2006-01-02-15:04:05") + ".log"
- filename = filepath.Join("log", filename)
- f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
- if err != nil {
- fmt.Printf("Failed to create logfile %s, err: %s\n", filename, err)
- l.mu.Unlock()
- return nil
- }
- l.f = f
- l.mu.Unlock()
- return l.f
-}
-
-func Trace(args ...interface{}) {
- entry := l.l.WithFields(logrus.Fields{})
- entry.Data["file"] = fileInfo(2)
- entry.Trace(args...)
-}
-
-func Tracef(format string, args ...interface{}) {
- entry := l.l.WithFields(logrus.Fields{})
- entry.Data["file"] = fileInfo(2)
- entry.Tracef(format, args...)
-}
-
-func Debug(args ...interface{}) {
- entry := l.l.WithFields(logrus.Fields{})
- entry.Data["file"] = fileInfo(2)
- entry.Debug(args...)
-}
-
-func Debugf(format string, args ...interface{}) {
- entry := l.l.WithFields(logrus.Fields{})
- entry.Data["file"] = fileInfo(2)
- entry.Debugf(format, args...)
-}
-
-func Info(args ...interface{}) {
- entry := l.l.WithFields(logrus.Fields{})
- entry.Data["file"] = fileInfo(2)
- entry.Info(args...)
-}
-
-func Infof(format string, args ...interface{}) {
- entry := l.l.WithFields(logrus.Fields{})
- entry.Data["file"] = fileInfo(2)
- entry.Infof(format, args...)
-}
-
-func Warn(args ...interface{}) {
- entry := l.l.WithFields(logrus.Fields{})
- entry.Data["file"] = fileInfo(2)
- entry.Warn(args...)
-}
-
-func Warnf(format string, args ...interface{}) {
- entry := l.l.WithFields(logrus.Fields{})
- entry.Data["file"] = fileInfo(2)
- entry.Warnf(format, args...)
-}
-
-func Error(args ...interface{}) {
- entry := l.l.WithFields(logrus.Fields{})
- entry.Data["file"] = fileInfo(2)
- entry.Error(args...)
-}
-
-func Errorf(format string, args ...interface{}) {
- entry := l.l.WithFields(logrus.Fields{})
- entry.Data["file"] = fileInfo(2)
- entry.Errorf(format, args...)
-}
-
-func Fatal(args ...interface{}) {
- entry := l.l.WithFields(logrus.Fields{})
- entry.Data["file"] = fileInfo(2)
- entry.Fatal(args...)
-}
-
-func Fatalf(format string, args ...interface{}) {
- entry := l.l.WithFields(logrus.Fields{})
- entry.Data["file"] = fileInfo(2)
- entry.Fatalf(format, args...)
-}
-
-func Panic(args ...interface{}) {
- entry := l.l.WithFields(logrus.Fields{})
- entry.Data["file"] = fileInfo(2)
- entry.Panic(args...)
-}
-
-func Panicf(format string, args ...interface{}) {
- entry := l.l.WithFields(logrus.Fields{})
- entry.Data["file"] = fileInfo(2)
- entry.Panicf(format, args...)
-}
-
-func formatter(isConsole bool) *nested.Formatter {
- fmtter := &nested.Formatter{
- HideKeys: true,
- TimestampFormat: "2006-01-02 15:04:05",
- }
- if isConsole {
- fmtter.NoColors = false
- } else {
- fmtter.NoColors = true
- }
- return fmtter
-}
-
-func fileInfo(skip int) string {
- _, file, line, ok := runtime.Caller(skip)
- if !ok {
- file = "??>"
- line = 1
- } else {
- slash := strings.LastIndex(file, "/")
- if slash >= 0 {
- file = file[slash+1:]
- }
- }
- return fmt.Sprintf("%s:%d", file, line)
-}
diff --git a/engine/logger/logger_test.go b/engine/logger/logger_test.go
deleted file mode 100644
index dd9a01d4..00000000
--- a/engine/logger/logger_test.go
+++ /dev/null
@@ -1,39 +0,0 @@
-// logger 提供封装好的 logrus 日志库
-// 日志等级从底到高分别为:trace, debug, info, warn, error, fatal, panic
-// trace 用于跟踪程序运行过程中的一些细节
-// debug 用于调试程序
-// info 用于重要信息
-// warn 用于警告信息
-// error 用于错误信息
-// fatal 用于致命错误,程序将退出
-// panic 用于致命错误,程序将崩溃退出,并展开堆栈调用信息
-package logger
-
-import (
- "testing"
-
- "github.com/sirupsen/logrus"
-)
-
-func TestLogger(t *testing.T) {
- Init().ToStdoutAndFile().SetLevel(logrus.TraceLevel)
- Trace("info")
- Tracef("info %s", "hello")
- Debug("info")
- Debugf("info %s", "hello")
- Info("info")
- Infof("info %s", "hello")
- Warn("info")
- Warnf("info %s", "hello")
- Error("info")
- Errorf("info %s", "hello")
-}
-
-func TestToMemory(t *testing.T) {
- Init().ToMemory().SetLevel(logrus.TraceLevel)
- Trace("hello")
- mem := Buffer()
- if mem.Len() == 0 {
- t.Fatal("error")
- }
-}
diff --git a/engine/model/artifictory.go b/engine/model/artifictory.go
deleted file mode 100644
index 99747a52..00000000
--- a/engine/model/artifictory.go
+++ /dev/null
@@ -1,24 +0,0 @@
-package model
-
-/*
-Artifactory 构建物
-*/
-type Artifactory struct {
- Name string `json:"name"`
- Url string `json:"url"`
-}
-
-/*
-Report 构建物报告
-*/
-type Report struct {
- Id int `json:"id"`
- Url string `json:"url"`
- Type int `json:"type"`
-}
-
-type ActionResult struct {
- CodeInfo string
- Artifactorys []Artifactory `json:"artifactorys"`
- Reports []Report `json:"reports"`
-}
diff --git a/engine/model/contract_check.go b/engine/model/contract_check.go
deleted file mode 100644
index 053a758b..00000000
--- a/engine/model/contract_check.go
+++ /dev/null
@@ -1,79 +0,0 @@
-package model
-
-import "encoding/json"
-
-type ContractCheckResult[T ResultDetailType] struct {
- Name string `json:"name"`
- Result string `json:"result"`
- Tool string `json:"tool"`
- Context []ContractCheckResultDetails[T] `json:"context"`
-}
-
-func NewContractCheckResult[T ResultDetailType](name string, result string, tool string, context []ContractCheckResultDetails[T]) ContractCheckResult[T] {
- return ContractCheckResult[T]{
- Name: name,
- Result: result,
- Tool: tool,
- Context: context,
- }
-}
-
-type ResultDetailType interface {
- string | []ContractStyleGuideValidationsReportDetails | []ContractMethodsPropertiesReportDetails | json.RawMessage
-}
-
-type ContractCheckResultDetails[T ResultDetailType] struct {
- Name string `json:"name"`
- Issue int `json:"issue"`
- Message T `json:"message"`
-}
-
-func NewContractCheckResultDetails[T ResultDetailType](name string, issue int, message T) ContractCheckResultDetails[T] {
- return ContractCheckResultDetails[T]{
- Name: name,
- Issue: issue,
- Message: message,
- }
-}
-
-type ContractStyleGuideValidationsReportDetails struct {
- Line string `json:"line"`
- Column string `json:"column"`
- Level string `json:"level"`
- OriginalText string `json:"originalText"`
- Note string `json:"note"`
- Tool string `json:"tool"`
-}
-
-func NewContractStyleGuideValidationsReportDetails(line, column, level, originalText, note, tool string) ContractStyleGuideValidationsReportDetails {
- return ContractStyleGuideValidationsReportDetails{
- Line: line,
- Column: column,
- Level: level,
- OriginalText: originalText,
- Note: note,
- Tool: tool,
- }
-}
-
-type ContractMethodsPropertiesReportDetails struct {
- Contract string `json:"contract"`
- Category string `json:"category"`
- Function string `json:"function"`
- Visibility string `json:"visibility"`
- ViewPure string `json:"view_pure"`
- Returns string `json:"returns"`
- Modifiers string `json:"modifiers"`
-}
-
-func NewContractMethodsPropertiesReportDetails(contract, category, function, visibility, viewPure, returns, modifiers string) ContractMethodsPropertiesReportDetails {
- return ContractMethodsPropertiesReportDetails{
- Contract: contract,
- Category: category,
- Function: function,
- Visibility: visibility,
- ViewPure: viewPure,
- Returns: returns,
- Modifiers: modifiers,
- }
-}
diff --git a/engine/model/job.go b/engine/model/job.go
deleted file mode 100644
index fad2f827..00000000
--- a/engine/model/job.go
+++ /dev/null
@@ -1,187 +0,0 @@
-package model
-
-import (
- "fmt"
- "github.com/hamster-shared/a-line/engine/output"
- "github.com/hamster-shared/a-line/engine/utils"
- "io"
- "os"
- "path"
- "strconv"
- "time"
-)
-
-type Status int
-
-const (
- STATUS_NOTRUN Status = 0
- STATUS_RUNNING Status = 1
- STATUS_FAIL Status = 2
- STATUS_SUCCESS Status = 3
- STATUS_STOP Status = 4
-)
-
-type Job struct {
- Version string `yaml:"version,omitempty" json:"version"`
- Name string `yaml:"name,omitempty" json:"name"`
- Stages map[string]Stage `yaml:"stages,omitempty" json:"stages"`
- Parameter map[string]string `yaml:"parameter" json:"parameter"`
-}
-
-type JobVo struct {
- Version string `yaml:"version" json:"version"`
- Name string `yaml:"name" json:"name"`
- Stages map[string]Stage `yaml:"stages" json:"stages"`
- Status Status `json:"status"`
- StartTime time.Time `yaml:"startTime" json:"startTime"`
- Duration int64 `json:"duration"`
- TriggerMode string `yaml:"triggerMode" json:"triggerMode"`
- PipelineDetailId int `json:"pipelineDetailId"`
- Error string `json:"error"`
- CreateTime time.Time `json:"createTime"`
-}
-
-type JobDetail struct {
- Id int `json:"id"`
- Job
- Status Status `json:"status"`
- TriggerMode string `yaml:"triggerMode" json:"triggerMode"`
- Stages []StageDetail `json:"stages"`
- StartTime time.Time `yaml:"startTime" json:"startTime"`
- Duration int64 `json:"duration"`
- ActionResult `yaml:"actionResult" json:"actionResult"`
- Output *output.Output `json:"output"`
- Error string `yaml:"error,omitempty"json:"error"`
-}
-
-func (jd *JobDetail) ToString() string {
- str := ""
- for _, s := range jd.Stages {
- str += s.ToString() + "\n"
- }
- return fmt.Sprintf("job: %s, Status: %d, StartTime: %s , Duration: %d, stages: [\n%s]", jd.Name, jd.Status, jd.StartTime, jd.Duration, str)
-}
-
-// StageSort job 排序
-func (job *Job) StageSort() ([]StageDetail, error) {
- stages := make(map[string]Stage)
- for key, stage := range job.Stages {
- stages[key] = stage
- }
-
- sortedMap := make(map[string]any)
-
- stageList := make([]StageDetail, 0)
- for len(stages) > 0 {
- last := len(stages)
- for key, stage := range stages {
- allContains := true
- for _, needs := range stage.Needs {
- _, ok := sortedMap[needs]
- if !ok {
- allContains = false
- }
- }
- if allContains {
- sortedMap[key] = ""
- delete(stages, key)
- stageList = append(stageList, NewStageDetail(key, stage))
- }
- }
-
- if len(stages) == last {
- return nil, fmt.Errorf("cannot resolve dependency, %v", stages)
- }
-
- }
-
- return stageList, nil
-}
-
-func (jd *JobDetail) AddArtifactory(file *os.File) error {
- arti := Artifactory{
- Name: file.Name(),
- Url: fmt.Sprintf("/artifactory/%s/%d/%s", jd.Name, jd.Id, file.Name()),
- }
- dir := path.Join(utils.DefaultConfigDir(), "artifactory", jd.Name, strconv.Itoa(jd.Id))
- _ = os.MkdirAll(dir, os.ModePerm)
-
- fullPath := path.Join(dir, file.Name())
-
- destination, err := os.Create(fullPath)
- if err != nil {
- return err
- }
-
- _, err = io.Copy(destination, file)
- if err != nil {
- return err
- }
-
- if len(jd.Artifactorys) > 0 {
- jd.Artifactorys = append(jd.Artifactorys, arti)
- } else {
- jd.Artifactorys = make([]Artifactory, 0)
- jd.Artifactorys = append(jd.Artifactorys, arti)
- }
- return nil
-}
-
-type JobLog struct {
- // 开始时间
- StartTime time.Time `json:"startTime"`
- // 持续时间
- Duration time.Duration `json:"duration"`
-
- //日志内容
- Content string `json:"content"`
-
- //最后一行 行号
- LastLine int `json:"lastLine"`
-}
-
-type JobStageLog struct {
- // 开始时间
- StartTime time.Time `json:"startTime"`
- // 持续时间
- Duration time.Duration `json:"duration"`
-
- //日志内容
- Content string `json:"content"`
-
- //最后一行 行号
- LastLine int `json:"lastLine"`
-
- //是否结束
- End bool `yaml:"end" json:"end"`
-}
-
-type JobPage struct {
- Data []JobVo `json:"data"`
- Total int `json:"total"`
- Page int `json:"page"`
- PageSize int `json:"pageSize"`
-}
-
-type JobDetailPage struct {
- Data []JobDetail `json:"data"`
- Total int `json:"total"`
- Page int `json:"page"`
- PageSize int `json:"pageSize"`
-}
-
-type JobDetailDecrement []JobDetail
-
-func (s JobDetailDecrement) Len() int { return len(s) }
-
-func (s JobDetailDecrement) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
-
-func (s JobDetailDecrement) Less(i, j int) bool { return s[i].Id > s[j].Id }
-
-type JobVoTimeDecrement []JobVo
-
-func (s JobVoTimeDecrement) Len() int { return len(s) }
-
-func (s JobVoTimeDecrement) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
-
-func (s JobVoTimeDecrement) Less(i, j int) bool { return s[i].CreateTime.After(s[j].CreateTime) }
diff --git a/engine/model/message.go b/engine/model/message.go
deleted file mode 100644
index 7ee94d94..00000000
--- a/engine/model/message.go
+++ /dev/null
@@ -1,46 +0,0 @@
-package model
-
-type Command int
-
-const (
- Command_Start Command = iota
- Command_Stop
-)
-
-type QueueMessage struct {
- JobName string
- JobId int
- Command Command
-}
-
-func NewStartQueueMsg(name string, id int) QueueMessage {
- return QueueMessage{
- JobName: name,
- JobId: id,
- Command: Command_Start,
- }
-
-}
-
-func NewStopQueueMsg(name string, id int) QueueMessage {
- return QueueMessage{
- JobName: name,
- JobId: id,
- Command: Command_Stop,
- }
-
-}
-
-type StatusChangeMessage struct {
- JobName string
- JobId int
- Status Status
-}
-
-func NewStatusChangeMsg(name string, id int, status Status) StatusChangeMessage {
- return StatusChangeMessage{
- name,
- id,
- status,
- }
-}
diff --git a/engine/model/node.go b/engine/model/node.go
deleted file mode 100644
index 9035bd3e..00000000
--- a/engine/model/node.go
+++ /dev/null
@@ -1,7 +0,0 @@
-package model
-
-type Node struct {
- // ip 地址
- Name string
- Address string
-}
diff --git a/engine/model/remote_action.go b/engine/model/remote_action.go
deleted file mode 100644
index d7343bc0..00000000
--- a/engine/model/remote_action.go
+++ /dev/null
@@ -1,25 +0,0 @@
-package model
-
-type RemoteAction struct {
- Name string `yaml:"name"`
- Description string `yaml:"description"`
- Author string `yaml:"author"`
- Inputs map[string]ActionInputArg `yaml:"inputs"`
- Runs ActionRun `yaml:"runs"`
-}
-
-type ActionInputArg struct {
- Description string `yaml:"description"`
- Default string `yaml:"default"`
- Required bool `yaml:"required"`
-}
-
-type ActionRun struct {
- Using string `yaml:"using"`
- Steps []ActionStep `yaml:"steps"`
-}
-
-type ActionStep struct {
- Run string `yaml:"run"`
- Shell string `yaml:"shell"`
-}
diff --git a/engine/model/stage.go b/engine/model/stage.go
deleted file mode 100644
index a6bdcdbf..00000000
--- a/engine/model/stage.go
+++ /dev/null
@@ -1,31 +0,0 @@
-package model
-
-import (
- "fmt"
- "time"
-)
-
-type Stage struct {
- Steps []Step `yaml:"steps,omitempty" json:"steps"`
- Needs []string `yaml:"needs,omitempty" json:"needs"`
-}
-
-type StageDetail struct {
- Name string `json:"name"`
- Stage Stage `json:"stage"`
- Status Status `json:"status"`
- StartTime time.Time `json:"startTime"`
- Duration int64 `json:"duration"`
-}
-
-func NewStageDetail(name string, stage Stage) StageDetail {
- return StageDetail{
- Name: name,
- Stage: stage,
- Status: STATUS_NOTRUN,
- }
-}
-
-func (s *StageDetail) ToString() string {
- return fmt.Sprintf("StageName: %s, status: %d, StartTime: %s, Duration: %d ", s.Name, s.Status, s.StartTime, s.Duration)
-}
diff --git a/engine/model/step.go b/engine/model/step.go
deleted file mode 100644
index 9b8114a0..00000000
--- a/engine/model/step.go
+++ /dev/null
@@ -1,15 +0,0 @@
-package model
-
-import "time"
-
-type Step struct {
- Name string `yaml:"name,omitempty" json:"name"`
- Id string `yaml:"id,omitempty" json:"id"`
- Uses string `yaml:"uses,omitempty" json:"uses"`
- With map[string]string `yaml:"with,omitempty" json:"with"`
- RunsOn string `yaml:"runs-on,omitempty" json:"runsOn"`
- Run string `yaml:"run,omitempty" json:"run"`
- Status Status `yaml:"status,omitempty" json:"status"`
- StartTime time.Time `yaml:"startTime,omitempty" json:"startTime"`
- Duration int64 `yaml:"duration,omitempty" json:"duration"`
-}
diff --git a/engine/model/template.go b/engine/model/template.go
deleted file mode 100644
index 852140a2..00000000
--- a/engine/model/template.go
+++ /dev/null
@@ -1,41 +0,0 @@
-package model
-
-type Template struct {
- Id int `yaml:"id,omitempty" json:"id"`
- Name string `yaml:"name,omitempty" json:"name"`
- Description string `yaml:"description,omitempty" json:"description"`
- Tag string `yaml:"tag,omitempty" json:"tag"`
- ImageName string `yaml:"imageName,omitempty" json:"imageName"`
-}
-
-type TemplateEnglish struct {
- Id int `yaml:"id,omitempty" json:"id"`
- Name string `yaml:"name,omitempty" json:"name"`
- DescriptionEnglish string `yaml:"descriptionEnglish,omitempty" json:"description"`
- Tag string `yaml:"tag,omitempty" json:"tag"`
- ImageName string `yaml:"imageName,omitempty" json:"imageName"`
-}
-
-type TemplateChinese struct {
- Id int `yaml:"id,omitempty" json:"id"`
- Name string `yaml:"name,omitempty" json:"name"`
- DescriptionChinese string `yaml:"descriptionChinese,omitempty" json:"description"`
- Tag string `yaml:"tag,omitempty" json:"tag"`
- ImageName string `yaml:"imageName,omitempty" json:"imageName"`
-}
-
-type TemplateVo struct {
- Id int `yaml:"id" json:"id"`
- Name string `yaml:"name" json:"name"`
- Description string `yaml:"description" json:"description"`
- Tag string `yaml:"tag" json:"tag"`
- ImageName string `yaml:"imageName" json:"imageName"`
- Template string `yaml:"template" json:"template"`
-}
-
-type TemplateDetail struct {
- Id int `json:"id"`
- Name string `json:"name"`
- Description string `json:"description"`
- Yaml string `json:"yaml"`
-}
diff --git a/engine/output/output.go b/engine/output/output.go
deleted file mode 100644
index 7ec3b0ba..00000000
--- a/engine/output/output.go
+++ /dev/null
@@ -1,405 +0,0 @@
-package output
-
-import (
- "bufio"
- "fmt"
- "github.com/hamster-shared/a-line/engine/consts"
- "github.com/hamster-shared/a-line/engine/logger"
- "github.com/hamster-shared/a-line/engine/utils"
- "os"
- "path/filepath"
- "strings"
- "sync"
- "time"
-)
-
-type Output struct {
- Name string
- ID int
- buffer []string
- f *os.File
- mu sync.Mutex
- filename string
- fileCursor int
- bufferCursor int
- stageTimeConsuming map[string]TimeConsuming
- stepTimeConsuming map[string]TimeConsuming
- timeConsuming TimeConsuming
-}
-
-type Log struct {
- StartTime time.Time
- EndTime time.Time
- Duration time.Duration
- Stages []StageOutput
- Lines []string
-}
-
-type StageOutput struct {
- StartTime time.Time
- EndTime time.Time
- Duration time.Duration
- Name string
- Lines []string
-}
-
-type TimeConsuming struct {
- Done bool
- StartTime time.Time
- EndTime time.Time
- Duration time.Duration
-}
-
-// New 新建一个 Output 对象,会自动初始化文件,以及定时将内容写入文件
-func New(name string, id int) *Output {
- o := &Output{
- Name: name,
- ID: id,
- buffer: make([]string, 0, 16),
- timeConsuming: TimeConsuming{
- StartTime: time.Now().Local(),
- },
- stageTimeConsuming: make(map[string]TimeConsuming),
- stepTimeConsuming: make(map[string]TimeConsuming),
- }
-
- err := o.initFile()
- if err != nil {
- logger.Errorf("Failed to init output file, err: %s", err)
- return o
- }
-
- o.timedWriteFile()
-
- o.WriteLine("[Job] Started on " + o.timeConsuming.StartTime.Format("2006-01-02 15:04:05"))
-
- return o
-}
-
-// Duration 返回持续时间
-func (o *Output) Duration() time.Duration {
- if o.timeConsuming.Done {
- return o.timeConsuming.Duration
- }
- return time.Since(o.timeConsuming.StartTime)
-}
-
-// TimeConsuming 返回耗时信息
-func (o *Output) TimeConsuming() TimeConsuming {
- return o.timeConsuming
-}
-
-// StageDuration 返回某个 Stage 的持续时间
-func (o *Output) StageDuration(name string) time.Duration {
- stageTimeConsuming, ok := o.stageTimeConsuming[name]
- if !ok {
- return 0
- }
- if stageTimeConsuming.Done {
- return stageTimeConsuming.Duration
- }
- if stageTimeConsuming.StartTime.IsZero() {
- return 0
- }
- return time.Since(stageTimeConsuming.StartTime)
-}
-
-// StageTimeConsuming 将阶段的时间信息暴露出去,便于外部查看详情
-func (o *Output) StageTimeConsuming(name string) (TimeConsuming, error) {
- timeConsuming, ok := o.stageTimeConsuming[name]
- if !ok {
- return TimeConsuming{}, fmt.Errorf("stage %s not found", name)
- }
- return timeConsuming, nil
-}
-
-// Done 标记输出已完成,会将缓存中的内容刷入文件,然后关闭文件
-func (o *Output) Done() {
- logger.Trace("output done, flush all, close file")
- now := time.Now().Local()
-
- // 将之前的 Stage 标记为完成
- for k, v := range o.stageTimeConsuming {
- if !v.Done {
- v.EndTime = now
- v.Duration = v.EndTime.Sub(v.StartTime)
- v.Done = true
- o.stageTimeConsuming[k] = v
- o.WriteLine(fmt.Sprintf("[TimeConsuming] EndTime: %s, Duration: %s", v.EndTime.Format("2006-01-02 15:04:05"), v.Duration))
- }
- }
-
- o.mu.Lock()
- o.timeConsuming.Done = true
- o.timeConsuming.EndTime = now
- o.timeConsuming.Duration = now.Sub(o.timeConsuming.StartTime)
- o.flush(o.buffer[o.fileCursor:])
- o.flush([]string{fmt.Sprintf("\n\n\n[Job] Finished on %s, Duration: %s", now.Format("2006-01-02 15:04:05"), o.timeConsuming.Duration)})
- o.f.Close()
- o.mu.Unlock()
-}
-
-// WriteLine 将一行普通内容写入输出
-func (o *Output) WriteLine(line string) {
- // 如果不是以换行符结尾,自动添加
- if !strings.HasSuffix(line, "\n") {
- line += "\n"
- }
- o.buffer = append(o.buffer, line)
-}
-
-// WriteCommandLine 将一行命令行内容写入输出,其实就是在前面加上了一个 "> "
-func (o *Output) WriteCommandLine(line string) {
- o.WriteLine("> " + line)
-}
-
-// Content 总是返回从起始到现在的所有内容
-func (o *Output) Content() string {
- o.bufferCursor = len(o.buffer)
- return strings.Join(o.buffer[:o.bufferCursor], "")
-}
-
-// NewContent 总是返回自上次读取后新出现的内容
-func (o *Output) NewContent() string {
- if o.bufferCursor >= len(o.buffer) {
- return ""
- }
- endIndex := len(o.buffer)
- result := strings.Join(o.buffer[o.bufferCursor:endIndex], "")
- o.bufferCursor = endIndex
- return result
-}
-
-// NewStage 会写入以 [Pipeline] Stage: 开头的一行,表示一个新的 Stage 开始
-func (o *Output) NewStage(name string) {
-
- // 将之前的 Stage 标记为完成
- for k, v := range o.stageTimeConsuming {
- if !v.Done {
- v.EndTime = time.Now().Local()
- v.Duration = v.EndTime.Sub(v.StartTime)
- v.Done = true
- o.stageTimeConsuming[k] = v
- o.WriteLine(fmt.Sprintf("[TimeConsuming] EndTime: %s, Duration: %s", v.EndTime.Format("2006-01-02 15:04:05"), v.Duration))
- o.WriteLine("} ")
- }
- }
-
- o.WriteLine("\n")
- o.WriteLine("[Pipeline] Stage: " + name)
- o.WriteLine("{ ")
-
- startTime := time.Now().Local()
- o.WriteLine("[TimeConsuming] StartTime: " + startTime.Format("2006-01-02 15:04:05"))
- o.stageTimeConsuming[name] = TimeConsuming{
- StartTime: startTime,
- }
-}
-
-// NewStage 会写入以 [Pipeline] Stage: 开头的一行,表示一个新的 Stage 开始
-func (o *Output) NewStep(name string) {
-
- // 将之前的 Stage 标记为完成
- for k, v := range o.stepTimeConsuming {
- if !v.Done {
- v.EndTime = time.Now().Local()
- v.Duration = v.EndTime.Sub(v.StartTime)
- v.Done = true
- o.stepTimeConsuming[k] = v
- o.WriteLine(fmt.Sprintf("[TimeConsuming] EndTime: %s, Duration: %s", v.EndTime.Format("2006-01-02 15:04:05"), v.Duration))
- }
- }
-
- o.WriteLine("\n")
- o.WriteLine("\n")
- o.WriteLine("\n")
- o.WriteLine("[Pipeline] Step: " + name)
- startTime := time.Now().Local()
- o.WriteLine("[TimeConsuming] StartTime: " + startTime.Format("2006-01-02 15:04:05"))
- o.stepTimeConsuming[name] = TimeConsuming{
- StartTime: startTime,
- }
-}
-
-// 在一个协程中定时刷入文件
-func (o *Output) timedWriteFile() {
- endIndex := 0
- go func(endIndex int) {
- for {
- o.mu.Lock()
- if o.timeConsuming.Done {
- o.mu.Unlock()
- break
- }
- o.mu.Unlock()
-
- if len(o.buffer) <= endIndex {
- time.Sleep(1 * time.Second)
- continue
- }
-
- endIndex = len(o.buffer)
- err := o.flush(o.buffer[o.fileCursor:endIndex])
- if err != nil {
- logger.Error(err)
- }
- o.fileCursor = endIndex
- time.Sleep(1 * time.Second)
- }
- }(endIndex)
-}
-
-// 刷入文件
-func (o *Output) flush(arr []string) error {
- if o.f == nil {
- return nil
- }
- for _, line := range arr {
- if _, err := o.f.WriteString(line); err != nil {
- logger.Error(err)
- return err
- }
- }
- return nil
-}
-
-// 初始化文件
-func (o *Output) initFile() error {
- o.mu.Lock()
- if o.f != nil {
- o.mu.Unlock()
- return nil
- }
-
- if o.filename == "" {
- o.filename = filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, o.Name, consts.JOB_DETAIL_LOG_DIR_NAME, fmt.Sprintf("%d.log", o.ID))
- }
-
- basepath := filepath.Dir(o.filename)
- if err := os.MkdirAll(basepath, 0755); err != nil {
- o.mu.Unlock()
- return err
- }
-
- f, err := os.OpenFile(o.filename, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
- if err != nil {
- logger.Errorf("Failed to create output log file %s, err: %s\n", o.filename, err)
- o.mu.Unlock()
- return err
- }
- o.f = f
- o.mu.Unlock()
- return nil
-}
-
-// Filename 返回文件名
-func (o *Output) Filename() string {
- return o.filename
-}
-
-// StageOutputList 返回存储了 Stage 输出的列表
-func (o *Output) StageOutputList() []StageOutput {
- return parseLogLines(o.buffer[:]).Stages
-}
-
-// ParseLogFile 解析日志文件,返回存储了 Stage 输出的列表
-func ParseLogFile(filename string) (Log, error) {
- lines, err := ReadFileLines(filename)
- if err != nil {
- return Log{}, err
- }
- result := parseLogLines(lines)
- return result, nil
-}
-
-// ReadFileLines 读取文件中的行
-func ReadFileLines(filename string) ([]string, error) {
- f, err := os.Open(filename)
- if err != nil {
- return nil, err
- }
- defer f.Close()
- fileScanner := bufio.NewScanner(f)
- fileScanner.Split(bufio.ScanLines)
- var lines []string
- for fileScanner.Scan() {
- lines = append(lines, fileScanner.Text())
- }
- return lines, nil
-}
-
-func parseLogLines(lines []string) Log {
- var log Log
- log.Lines = lines
-
- var stageName = "unknown"
- var stageNameList []string
-
- // 先遍历到 map 里,由于 map 是无序的,所以需要一个数组来记录顺序
- var stageOutputMap = make(map[string][]string)
- for _, line := range lines {
- if strings.HasPrefix(line, "[Job]") || line == "\n" || line == "" {
- if strings.HasPrefix(line, "[Job] Started on ") {
- startTime := strings.TrimPrefix(line, "[Job] Started on ")
- log.StartTime, _ = time.Parse("2006-01-02 15:04:05", startTime)
- }
- if strings.HasPrefix(line, "[Job] Finished on ") {
- endTimeAndDuration := strings.TrimPrefix(line, "[Job] Finished on ")
- endTimeAndDurationSlice := strings.Split(endTimeAndDuration, ",")
- endTime := endTimeAndDurationSlice[0]
- log.EndTime, _ = time.Parse("2006-01-02 15:04:05", endTime)
-
- if len(endTimeAndDurationSlice) > 1 {
- duration := endTimeAndDurationSlice[1]
- duration = strings.TrimPrefix(duration, " Duration: ")
- log.Duration, _ = time.ParseDuration(duration)
- }
- }
-
- continue
- }
- if strings.HasPrefix(line, "[Pipeline] Stage: ") {
- stageName = strings.TrimPrefix(line, "[Pipeline] Stage: ")
- stageOutputMap[stageName] = make([]string, 0)
- stageNameList = append(stageNameList, stageName)
- }
- stageOutputMap[stageName] = append(stageOutputMap[stageName], line)
- }
-
- for k, v := range stageOutputMap {
- for i := range stageNameList {
- if stageNameList[i] == k {
- var startTime, endTime time.Time
- var duration time.Duration
- for _, line := range v {
- if strings.HasPrefix(line, "[TimeConsuming] StartTime: ") {
- startTimeString := strings.TrimPrefix(line, "[TimeConsuming] StartTime: ")
- startTime, _ = time.Parse("2006-01-02 15:04:05", startTimeString)
- }
- if strings.HasPrefix(line, "[TimeConsuming] EndTime: ") {
- endTimeString := strings.TrimPrefix(line, "[TimeConsuming] EndTime: ")
- endTimeAndDurationSlice := strings.Split(endTimeString, ",")
- endTime, _ = time.Parse("2006-01-02 15:04:05", endTimeAndDurationSlice[0])
-
- if len(endTimeAndDurationSlice) > 1 {
- durationString := endTimeAndDurationSlice[1]
- durationString = strings.TrimPrefix(durationString, " Duration: ")
- duration, _ = time.ParseDuration(durationString)
- }
- }
- }
-
- stageOutput := StageOutput{
- Name: k,
- Lines: v,
- StartTime: startTime,
- EndTime: endTime,
- Duration: duration,
- }
- log.Stages = append(log.Stages, stageOutput)
- }
- }
- }
-
- return log
-}
diff --git a/engine/output/output_test.go b/engine/output/output_test.go
deleted file mode 100644
index 300923ce..00000000
--- a/engine/output/output_test.go
+++ /dev/null
@@ -1,150 +0,0 @@
-package output
-
-import (
- "fmt"
- "github.com/hamster-shared/a-line/engine/logger"
- "testing"
- "time"
-
- "github.com/davecgh/go-spew/spew"
- "github.com/sirupsen/logrus"
-)
-
-func TestNew(t *testing.T) {
- logger.Init().ToStdoutAndFile().SetLevel(logrus.TraceLevel)
- testOutput := New("test", 10001)
-
- testOutput.NewStage("第一阶段")
- testOutput.WriteLine("第一行")
- testOutput.WriteLine("第二行")
- testOutput.WriteLine("第三行")
- testOutput.WriteLine("第四行")
- testOutput.WriteLine("第五行")
-
- testOutput.NewStage("第二阶段")
- testOutput.WriteLine("第一行")
- testOutput.WriteLine("第二行")
- testOutput.WriteLine("第三行")
- testOutput.WriteLine("第四行")
- testOutput.WriteLine("第五行")
-
- testOutput.Done()
-
- fmt.Println("文件写入到", testOutput.Filename())
-}
-
-func TestParseLogFile(t *testing.T) {
- result, err := ParseLogFile("/home/vihv/pipelines/jobs/test/job-details-log/10001.log")
- if err != nil {
- t.Error(err)
- }
- spew.Dump(result)
-}
-
-func TestContent(t *testing.T) {
- logger.Init().ToStdoutAndFile().SetLevel(logrus.TraceLevel)
- testOutput := New("test", 10085)
-
- testOutput.NewStage("第一阶段")
- testOutput.WriteLine("第一行")
- testOutput.WriteLine("第二行")
- testOutput.WriteLine("第三行")
- testOutput.WriteLine("第四行")
- testOutput.WriteLine("第五行")
-
- fmt.Println("读取所有内容:", testOutput.Content())
-
- testOutput.NewStage("第二阶段")
- testOutput.WriteLine("第一行")
- testOutput.WriteLine("第二行")
- testOutput.WriteLine("第三行")
- testOutput.WriteLine("第四行")
- testOutput.WriteLine("第五行")
-
- fmt.Println("读取新出现的内容:", testOutput.NewContent())
-
- if len(testOutput.NewContent()) != 0 {
- t.Error("new content length error")
- }
-
- testOutput.Done()
-}
-
-func TestStageOutputList(t *testing.T) {
- logger.Init().ToStdoutAndFile().SetLevel(logrus.TraceLevel)
- testOutput := New("test", 10000)
-
- testOutput.NewStage("第一阶段")
- testOutput.WriteLine("第一行")
- testOutput.WriteLine("第二行")
- testOutput.WriteLine("第三行")
- testOutput.WriteLine("第四行")
- testOutput.WriteLine("第五行")
-
- testOutput.NewStage("第二阶段")
- testOutput.WriteLine("第一行")
- testOutput.WriteLine("第二行")
- testOutput.WriteLine("第三行")
- testOutput.WriteLine("第四行")
- testOutput.WriteLine("第五行")
-
- if len(testOutput.StageOutputList()) != 2 {
- t.Error("stage output list length error")
- }
-
- testOutput.Done()
-}
-func TestTimeInfo(t *testing.T) {
- logger.Init().ToStdoutAndFile().SetLevel(logrus.TraceLevel)
- testOutput := New("test", 10085)
-
- testOutput.NewStage("第一阶段")
- testOutput.WriteLine("第一行")
- testOutput.WriteLine("第二行")
- testOutput.WriteLine("第三行")
- testOutput.WriteLine("第四行")
- testOutput.WriteLine("第五行")
-
- fmt.Println("第一阶段的时间信息:", testOutput.stageTimeConsuming["第一阶段"])
-
- time.Sleep(1 * time.Second)
- testOutput.NewStage("第二阶段")
-
- fmt.Println("当有了新阶段后,第一阶段的时间信息:", testOutput.stageTimeConsuming["第一阶段"])
-
- testOutput.WriteLine("第一行")
- testOutput.WriteLine("第二行")
- testOutput.WriteLine("第三行")
- testOutput.WriteLine("第四行")
- testOutput.WriteLine("第五行")
-
- fmt.Println("第二阶段的时间信息:", testOutput.stageTimeConsuming["第二阶段"])
-
- testOutput.Done()
-
- fmt.Println("整个的时间信息:", testOutput.timeConsuming)
- fmt.Println("整个结束后,第二阶段的时间信息:", testOutput.stageTimeConsuming["第二阶段"])
-
- fmt.Println("不存在的阶段的时间信息:", testOutput.stageTimeConsuming["不存在的阶段"])
-
- // 单独查看耗时
- fmt.Println("第一阶段的耗时:", testOutput.StageDuration("第一阶段"))
- fmt.Println("第二阶段的耗时:", testOutput.StageDuration("第二阶段"))
- fmt.Println("不存在的阶段的耗时:", testOutput.StageDuration("不存在的阶段"))
-
- if testOutput.StageDuration("不存在的阶段") != 0 {
- t.Error("stage duration error")
- }
-
- if testOutput.StageDuration("第一阶段") == 0 {
- t.Error("stage duration error")
- }
-
- if testOutput.StageDuration("第二阶段") == 0 {
- t.Error("stage duration error")
- }
-
- if !testOutput.stageTimeConsuming["第一阶段"].Done {
- t.Error("stage time info done error")
- }
-}
diff --git a/engine/pipeline/resolver.go b/engine/pipeline/resolver.go
deleted file mode 100644
index cf8cf4a4..00000000
--- a/engine/pipeline/resolver.go
+++ /dev/null
@@ -1,38 +0,0 @@
-package pipeline
-
-import (
- "github.com/hamster-shared/a-line/engine/model"
- "gopkg.in/yaml.v2"
- "io"
- "os"
-)
-
-// GetJob 根据文件获取job信息
-func GetJob(path string) (*model.Job, error) {
- file, err := os.Open(path)
- if err != nil {
- return nil, err
- }
- return GetJobFromReader(file)
-}
-
-// GetJobFromReader 根据流获取Job 信息
-func GetJobFromReader(reader io.Reader) (*model.Job, error) {
- yamlFile, err := io.ReadAll(reader)
- if err != nil {
- return nil, err
- }
- var job model.Job
-
- err = yaml.Unmarshal(yamlFile, &job)
-
- return &job, err
-}
-
-func GetJobFromYaml(yamlStr string) (*model.Job, error) {
- var job model.Job
-
- err := yaml.Unmarshal([]byte(yamlStr), &job)
-
- return &job, err
-}
diff --git a/engine/pipeline/state.go b/engine/pipeline/state.go
deleted file mode 100644
index 5e90c30b..00000000
--- a/engine/pipeline/state.go
+++ /dev/null
@@ -1,77 +0,0 @@
-package pipeline
-
-type State string
-
-const (
- StateNotRun = State("NotRun")
- StateRunning = State("Running")
- StateDone = State("Done")
- StateFail = State("Fail")
-)
-
-var (
- NotRunInstance = &NotRunStep{}
- RunningInstance = &RunningStep{}
- DoneInstance = &DoneStep{}
- FailInstance = &FailStep{}
-)
-
-type IStepState interface {
- getState() State
- execute(machine *StepMachine)
-}
-
-// NotRunStep 未开始状态
-type NotRunStep struct {
-}
-
-func (step *NotRunStep) getState() State {
- return StateNotRun
-}
-
-func (step *NotRunStep) execute(sm *StepMachine) {
-
- sm.stepState = RunningInstance
-}
-
-// RunningStep 运行中状态
-type RunningStep struct {
-}
-
-func NewRunningStep() *RunningStep {
- return &RunningStep{}
-}
-
-func (step *RunningStep) getState() State {
- return StateRunning
-}
-
-func (step *RunningStep) execute(sm *StepMachine) {
- // will not happen
- sm.stepState = DoneInstance
-
-}
-
-// DoneStep 完成状态
-type DoneStep struct {
-}
-
-func (step *DoneStep) getState() State {
- return StateDone
-}
-
-func (step *DoneStep) execute(sm *StepMachine) {
- // will not happen
-}
-
-// FailStep 失败状态
-type FailStep struct {
-}
-
-func (step *FailStep) getState() State {
- return StateFail
-}
-
-func (step *FailStep) execute(sm *StepMachine) {
- // will not happen
-}
diff --git a/engine/pipeline/state_machine.go b/engine/pipeline/state_machine.go
deleted file mode 100644
index 1e82d4ca..00000000
--- a/engine/pipeline/state_machine.go
+++ /dev/null
@@ -1,19 +0,0 @@
-package pipeline
-
-type StepMachine struct {
- stepState IStepState
-}
-
-func InitialStepStateMachine() *StepMachine {
- return &StepMachine{
- stepState: NotRunInstance,
- }
-}
-
-func (s *StepMachine) Run() {
- s.stepState.execute(s)
-}
-
-func (s *StepMachine) State() State {
- return s.stepState.getState()
-}
diff --git a/engine/queue/queue.go b/engine/queue/queue.go
deleted file mode 100644
index e6e9ffee..00000000
--- a/engine/queue/queue.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package queue
-
-import (
- "github.com/hamster-shared/a-line/engine/model"
-)
-
-type IQueue interface {
- Push(job *model.Job, node *model.Node)
- Listener() chan *model.Job
-}
-
-type Queue struct {
-}
diff --git a/engine/service/job.go b/engine/service/job.go
deleted file mode 100644
index 530f8b56..00000000
--- a/engine/service/job.go
+++ /dev/null
@@ -1,685 +0,0 @@
-package service
-
-import (
- "github.com/hamster-shared/a-line/engine/consts"
- "github.com/hamster-shared/a-line/engine/logger"
- model2 "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/output"
- "github.com/hamster-shared/a-line/engine/utils"
- "github.com/hamster-shared/a-line/engine/utils/platform"
- "github.com/jinzhu/copier"
- "gopkg.in/yaml.v3"
- "io"
- "log"
- "os"
- "path"
- "path/filepath"
- "sort"
- "strconv"
- "strings"
- "time"
-)
-
-type IJobService interface {
- //SaveJob 保存 Job
- SaveJob(name string, yaml string) error
-
- // GetJob 获取 Job
- GetJob(name string) string
-
- // GetJobObject get job object
- GetJobObject(name string) *model2.Job
-
- JobList(keyword string, page, size int) *model2.JobPage
-
- //UpdateJob update job
- UpdateJob(oldName string, newName string, yaml string) error
-
- //DeleteJob delete job
- DeleteJob(name string) error
-
- // SaveJobDetail 保存 Job 详情
- SaveJobDetail(name string, job *model2.JobDetail) error
-
- UpdateJobDetail(name string, job *model2.JobDetail) error
-
- // GetJobDetail 获取 Job 详情
- GetJobDetail(name string, id int) *model2.JobDetail
-
- //JobDetailList get job detail list
- JobDetailList(name string, page, size int) *model2.JobDetailPage
-
- //DeleteJobDetail delete job detail
- DeleteJobDetail(name string, pipelineDetailId int) error
-
- //ExecuteJob exec pipeline job
- ExecuteJob(name string) (*model2.JobDetail, error)
-
- // ReExecuteJob re exec pipeline job
- ReExecuteJob(name string, pipelineDetailId int) error
-
- // StopJobDetail stop pipeline job
- StopJobDetail(name string, pipelineDetailId int) error
-
- // GetJobLog 获取 job 日志
- GetJobLog(name string, pipelineDetailId int) *model2.JobLog
- // GetJobStageLog 获取 job 的 stage 日志
- GetJobStageLog(name string, pipelineDetailId int, stageName string, start int) *model2.JobStageLog
-
- // OpenArtifactoryDir open artifactory folder
- OpenArtifactoryDir(name string, detailId string) error
- //SaveJobWithFile save pipeline job with template file
- SaveJobWithFile(file, name string)
-}
-
-type JobService struct {
-}
-
-func NewJobService() *JobService {
- return &JobService{}
-}
-
-// SaveJob save pipeline job
-func (svc *JobService) SaveJob(name string, yaml string) error {
- //file directory path
- dir := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name)
- src := filepath.Join(dir, name+".yml")
- //determine whether the folder exists, and create it if it does not exist
- _, err := os.Stat(dir)
- if err != nil && os.IsNotExist(err) {
- err := os.MkdirAll(dir, os.ModePerm)
- if err != nil {
- log.Println("create jobs dir failed", err.Error())
- return err
- }
- }
-
- //write data to yaml file
- err = os.WriteFile(src, []byte(yaml), 0777)
- if err != nil {
- log.Println("write data to yaml file failed", err)
- return err
- }
- return nil
-}
-
-// GetJob get job
-func (svc *JobService) GetJob(name string) string {
- //job file path
- src := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, name+".yml")
- //judge whether the job file exists
- _, err := os.Stat(src)
- //not exist
- if os.IsNotExist(err) {
- log.Println("get job failed,job file not exist", err.Error())
- return ""
- }
- //exist
- fileContent, err := os.ReadFile(src)
- if err != nil {
- log.Println("get job read file failed", err.Error())
- return ""
- }
- return string(fileContent)
-}
-
-// UpdateJob update job
-func (svc *JobService) UpdateJob(oldName string, newName string, yaml string) error {
- name := oldName
- oldDir := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name)
- _, err := os.Stat(oldDir)
- //not exist
- if os.IsNotExist(err) {
- log.Println("update job failed,job file not exist", err.Error())
- return err
- }
- // job file path
- src := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, name+".yml")
- //judge whether the job detail file exists
- _, err = os.Stat(src)
- //not exist
- if os.IsNotExist(err) {
- log.Println("update job failed,job file not exist", err.Error())
- return err
- }
- if newName != "" {
- newDir := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, newName)
- err = os.Rename(oldDir, newDir)
- if err != nil {
- log.Println("reName failed", err.Error())
- return err
- }
- oldSrc := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, newName, name+".yml")
- newSrc := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, newName, newName+".yml")
- err = os.Rename(oldSrc, newSrc)
- if err != nil {
- log.Println("reName failed", err.Error())
- return err
- }
- src = newSrc
- svc.updateJobDetailName(newName)
- }
- //write data to yaml file
- err = os.WriteFile(src, []byte(yaml), 0777)
- if err != nil {
- log.Println("write data to yaml file failed", err)
- return err
- }
- return nil
-}
-
-// DeleteJob delete job
-func (svc *JobService) DeleteJob(name string) error {
- // job file path
- src := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name)
- //judge whether the job file exists
- _, err := os.Stat(src)
- //not exist
- if os.IsNotExist(err) {
- log.Println("delete job failed,job file not exist", err.Error())
- return err
- }
- err = os.RemoveAll(src)
- if err != nil {
- log.Println("delete job failed", err.Error())
- return err
- }
- return nil
-}
-
-// SaveJobDetail save job detail
-func (svc *JobService) SaveJobDetail(name string, job *model2.JobDetail) error {
- job.TriggerMode = consts.TRIGGER_MODE
- // serializes yaml struct
- data, err := yaml.Marshal(job)
- if err != nil {
- log.Println("serializes yaml failed", err)
- return err
- }
- //file directory path
- dir := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, consts.JOB_DETAIL_DIR_NAME)
- //determine whether the folder exists, and create it if it does not exist
- _, err = os.Stat(dir)
- if os.IsNotExist(err) {
- err = os.MkdirAll(dir, os.ModePerm)
- if err != nil {
- log.Println("create job details failed", err.Error())
- return err
- }
- }
- src := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, consts.JOB_DETAIL_DIR_NAME, strconv.Itoa(job.Id)+".yml")
- //write data to yaml file
- err = os.WriteFile(src, data, 0777)
- if err != nil {
- log.Println("write data to yaml file failed", err)
- return err
- }
- return nil
-}
-
-// UpdateJobDetail update job detail
-func (svc *JobService) UpdateJobDetail(name string, job *model2.JobDetail) error {
- // serializes yaml struct
- data, err := yaml.Marshal(job)
- if err != nil {
- log.Println("serializes yaml failed", err)
- return err
- }
- //file directory path
- dir := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, consts.JOB_DETAIL_DIR_NAME)
- //determine whether the folder exists, and create it if it does not exist
- _, err = os.Stat(dir)
- if os.IsNotExist(err) {
- log.Println("update job detail failed", err.Error())
- return err
- }
- src := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, consts.JOB_DETAIL_DIR_NAME, strconv.Itoa(job.Id)+".yml")
- //write data to yaml file
- err = os.WriteFile(src, data, 0777)
- if err != nil {
- log.Println("update job detail file failed", err)
- return err
- }
- return nil
-}
-
-// GetJobDetail get job detail
-func (svc *JobService) GetJobDetail(name string, id int) *model2.JobDetail {
- var jobDetailData model2.JobDetail
- //job file path
- src := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, consts.JOB_DETAIL_DIR_NAME, strconv.Itoa(id)+".yml")
- //judge whether the job detail file exists
- _, err := os.Stat(src)
- //not exist
- if os.IsNotExist(err) {
- log.Println("get job detail failed,job detail file not exist", err.Error())
- return &jobDetailData
- }
- //exist
- fileContent, err := os.ReadFile(src)
- if err != nil {
- log.Println("get job read detail file failed", err.Error())
- return &jobDetailData
- }
- //deserialization job detail yml file
- err = yaml.Unmarshal(fileContent, &jobDetailData)
- if err != nil {
- log.Println("get job,deserialization job detail file failed", err.Error())
- return &jobDetailData
- }
-
- runningStage := -1
- for index, stage := range jobDetailData.Stages {
- if stage.Status == model2.STATUS_RUNNING {
- runningStage = index
-
- }
- }
-
- if runningStage >= 0 && runningStage < len(jobDetailData.Stages) {
- jobDetailData.Stages[runningStage].Duration = time.Now().Sub(jobDetailData.Stages[runningStage].StartTime).Milliseconds()
- }
- return &jobDetailData
-}
-
-// JobList job list
-func (svc *JobService) JobList(keyword string, page, pageSize int) *model2.JobPage {
- var jobPage model2.JobPage
- var jobs []model2.JobVo
- //jobs folder path
- src := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME)
- _, err := os.Stat(src)
- if os.IsNotExist(err) {
- log.Println("jobs folder does not exist", err.Error())
- return &jobPage
- }
- files, err := os.ReadDir(src)
- if err != nil {
- log.Println("failed to read jobs folder", err.Error())
- return &jobPage
- }
- for _, file := range files {
- var ymlPath string
- if keyword != "" {
- if strings.Contains(file.Name(), keyword) {
- //job yml file path
- ymlPath = filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, file.Name(), file.Name()+".yml")
- } else {
- continue
- }
- } else {
- ymlPath = filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, file.Name(), file.Name()+".yml")
- }
- //judge whether the job file exists
- _, err := os.Stat(ymlPath)
- //not exist
- if os.IsNotExist(err) {
- log.Println("job file not exist", err.Error())
- continue
- }
- fileContent, err := os.ReadFile(ymlPath)
- if err != nil {
- log.Println("get job read file failed", err.Error())
- continue
- }
- var jobData model2.Job
- var jobVo model2.JobVo
- //deserialization job yml file
- err = yaml.Unmarshal(fileContent, &jobData)
- if err != nil {
- log.Println("get job,deserialization job file failed", err.Error())
- continue
- }
- copier.Copy(&jobVo, &jobData)
- svc.getJobInfo(&jobVo)
- createTime := platform.GetFileCreateTime(ymlPath)
- jobVo.CreateTime = *createTime
- jobs = append(jobs, jobVo)
- }
- sort.Sort(model2.JobVoTimeDecrement(jobs))
- pageNum, size, start, end := utils.SlicePage(page, pageSize, len(jobs))
- jobPage.Page = pageNum
- jobPage.PageSize = size
- jobPage.Total = len(jobs)
- jobPage.Data = jobs[start:end]
- return &jobPage
-}
-
-// JobDetailList job detail list
-func (svc *JobService) JobDetailList(name string, page, pageSize int) *model2.JobDetailPage {
- var jobDetailPage model2.JobDetailPage
- var jobDetails []model2.JobDetail
- //get the folder path of job details
- src := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, consts.JOB_DETAIL_DIR_NAME)
- _, err := os.Stat(src)
- if os.IsNotExist(err) {
- log.Println("job-details folder does not exist", err.Error())
- return &jobDetailPage
- }
- files, err := os.ReadDir(src)
- if err != nil {
- log.Println("failed to read jobs folder", err.Error())
- return &jobDetailPage
- }
- for _, file := range files {
- ymlPath := filepath.Join(src, file.Name())
- //judge whether the job detail file exists
- _, err := os.Stat(ymlPath)
- //not exist
- if os.IsNotExist(err) {
- log.Println("job detail file not exist", err.Error())
- continue
- }
- fileContent, err := os.ReadFile(ymlPath)
- if err != nil {
- log.Println("get job detail read file failed", err.Error())
- continue
- }
- var jobDetailData model2.JobDetail
- //deserialization job yml file
- err = yaml.Unmarshal(fileContent, &jobDetailData)
- if err != nil {
- log.Println("get job detail,deserialization job file failed", err.Error())
- continue
- }
- jobDetails = append(jobDetails, jobDetailData)
- }
- sort.Sort(model2.JobDetailDecrement(jobDetails))
- pageNum, size, start, end := utils.SlicePage(page, pageSize, len(jobDetails))
- jobDetailPage.Page = pageNum
- jobDetailPage.PageSize = size
- jobDetailPage.Total = len(jobDetails)
- jobDetailPage.Data = jobDetails[start:end]
- return &jobDetailPage
-}
-
-// DeleteJobDetail delete job detail
-func (svc *JobService) DeleteJobDetail(name string, pipelineDetailId int) error {
- // job detail file path
- src := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, consts.JOB_DETAIL_DIR_NAME, strconv.Itoa(pipelineDetailId)+".yml")
- //judge whether the job detail file exists
- _, err := os.Stat(src)
- //not exist
- if os.IsNotExist(err) {
- log.Println("delete job detail failed,job detail file not exist", err.Error())
- return err
- }
- err = os.Remove(src)
- if err != nil {
- log.Println("delete job detail failed", err.Error())
- return err
- }
- return nil
-}
-
-// ExecuteJob exec pipeline job
-func (svc *JobService) ExecuteJob(name string) (*model2.JobDetail, error) {
- //get job data
- jobData := svc.GetJobObject(name)
- //create job detail
- var jobDetail model2.JobDetail
- var ids []int
- //job-details file path
- src := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, consts.JOB_DETAIL_DIR_NAME)
- //judge whether the job detail file exists
- _, err := os.Stat(src)
- if os.IsNotExist(err) {
- log.Println("job detail file not exist", err.Error())
- err = os.MkdirAll(src, os.ModePerm)
- if err != nil {
- return nil, err
- }
- }
- // read file
- files, err := os.ReadDir(src)
- if err != nil {
- log.Println("read file failed", err.Error())
- return nil, err
- }
- for _, file := range files {
- index := strings.Index(file.Name(), ".")
- id, err := strconv.Atoi(file.Name()[0:index])
- if err != nil {
- log.Println("string to int failed", err.Error())
- continue
- }
- ids = append(ids, id)
- }
- if len(ids) > 0 {
- sort.Sort(sort.Reverse(sort.IntSlice(ids)))
- jobDetail.Id = ids[0] + 1
- } else {
- jobDetail.Id = 1
- }
- stageDetail, err := jobData.StageSort()
- if err != nil {
- return &jobDetail, err
- }
- jobDetail.Job = *jobData
- jobDetail.Status = model2.STATUS_NOTRUN
- jobDetail.StartTime = time.Now()
- jobDetail.Stages = stageDetail
- jobDetail.TriggerMode = consts.TRIGGER_MODE
- //TODO... 执行 pipeline job
-
- //create and save job detail
- return &jobDetail, svc.SaveJobDetail(name, &jobDetail)
-}
-
-// ReExecuteJob re exec pipeline job
-func (svc *JobService) ReExecuteJob(name string, pipelineDetailId int) error {
- //get job detail data
- jobDetailData := svc.GetJobDetail(name, pipelineDetailId)
- println(jobDetailData)
- //todo 重新执行 pipeline job
- return nil
-}
-
-// StopJobDetail stop pipeline job detail
-func (svc *JobService) StopJobDetail(name string, pipelineDetailId int) error {
- //get job detail data
- jobDetailData := svc.GetJobDetail(name, pipelineDetailId)
- println(jobDetailData)
- //todo stop pipeline job detail
- return nil
-}
-
-// GetJobLog 获取 job 日志
-func (svc *JobService) GetJobLog(name string, pipelineDetailId int) *model2.JobLog {
- src := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, consts.JOB_DETAIL_LOG_DIR_NAME, strconv.Itoa(pipelineDetailId)+".log")
-
- fileLog, err := output.ParseLogFile(src)
- if err != nil {
- logger.Errorf("parse log file failed, %v", err)
- return nil
- }
-
- jobLog := &model2.JobLog{
- StartTime: fileLog.StartTime,
- Duration: fileLog.Duration,
- Content: strings.Join(fileLog.Lines, "\r"),
- LastLine: len(fileLog.Lines),
- }
-
- return jobLog
-}
-
-// GetJobStageLog 获取 job 的 stage 日志
-func (svc *JobService) GetJobStageLog(name string, execId int, stageName string, start int) *model2.JobStageLog {
- src := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, consts.JOB_DETAIL_LOG_DIR_NAME, strconv.Itoa(execId)+".log")
-
- fileLog, err := output.ParseLogFile(src)
- if err != nil {
- logger.Errorf("parse log file failed, %v", err)
- return nil
- }
-
- detail := svc.GetJobDetail(name, execId)
-
- var stageDetail model2.StageDetail
-
- for _, stage := range detail.Stages {
- if stage.Name == stageName {
- stageDetail = stage
- }
- }
-
- if &stageDetail == nil {
- return &model2.JobStageLog{}
- }
-
- for _, stage := range fileLog.Stages {
- if stage.Name == stageName {
- var content string
- if start >= 0 && start <= len(stage.Lines) {
- content = strings.Join(stage.Lines[start:], "\r")
- }
-
- return &model2.JobStageLog{
- StartTime: stage.StartTime,
- Duration: stage.Duration,
- Content: content,
- LastLine: len(stage.Lines),
- End: stageDetail.Status == model2.STATUS_SUCCESS || stageDetail.Status == model2.STATUS_FAIL,
- }
- }
- }
- return nil
-}
-
-func (svc *JobService) getJobInfo(jobData *model2.JobVo) {
- //get the folder path of job details
- src := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, jobData.Name, consts.JOB_DETAIL_DIR_NAME)
- _, err := os.Stat(src)
- if os.IsNotExist(err) {
- log.Println("job-details folder does not exist", err.Error())
- }
- files, err := os.ReadDir(src)
- if err != nil {
- log.Println("failed to read jobs folder", err.Error())
- }
- var ids []int
- for _, file := range files {
- index := strings.Index(file.Name(), ".")
- id, err := strconv.Atoi(file.Name()[0:index])
- if err != nil {
- log.Println("string to int failed", err.Error())
- continue
- }
- ids = append(ids, id)
- }
- if len(ids) > 0 {
- sort.Sort(sort.Reverse(sort.IntSlice(ids)))
- jobDetail := svc.GetJobDetail(jobData.Name, ids[0])
- jobData.Duration = jobDetail.Duration
- jobData.Status = jobDetail.Status
- jobData.TriggerMode = jobDetail.TriggerMode
- jobData.StartTime = jobDetail.StartTime
- jobData.TriggerMode = jobDetail.TriggerMode
- jobData.PipelineDetailId = jobDetail.Id
- jobData.Error = jobDetail.Error
- }
-}
-
-// GetJob get job
-func (svc *JobService) GetJobObject(name string) *model2.Job {
- var jobData model2.Job
- //job file path
- src := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, name+".yml")
- //judge whether the job file exists
- _, err := os.Stat(src)
- //not exist
- if os.IsNotExist(err) {
- log.Println("get job failed,job file not exist", err.Error())
- return nil
- }
- //exist
- fileContent, err := os.ReadFile(src)
- if err != nil {
- log.Println("get job read file failed", err.Error())
- return &jobData
- }
- //deserialization job yml file
- err = yaml.Unmarshal(fileContent, &jobData)
- if err != nil {
- log.Println("get job,deserialization job file failed", err.Error())
- return &jobData
- }
- return &jobData
-}
-
-// OpenArtifactoryDir open artifactory folder
-func (svc *JobService) OpenArtifactoryDir(name string, detailId string) error {
- artifactoryDir := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, consts.ArtifactoryDir, detailId)
- return platform.OpenDir(artifactoryDir)
-}
-
-// updateJobDetailName update job detail name
-func (svc *JobService) updateJobDetailName(name string) {
- //file directory path
- dir := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, consts.JOB_DETAIL_DIR_NAME)
- //determine whether the folder exists, and create it if it does not exist
- _, err := os.Stat(dir)
- if os.IsNotExist(err) {
- logger.Errorf("update job detail name failed:%s", err.Error())
- }
- // read file
- files, err := os.ReadDir(dir)
- if err != nil {
- logger.Errorf("read file failed:%s", err.Error())
- }
- if len(files) > 0 {
- for _, file := range files {
- ymlPath := filepath.Join(dir, file.Name())
- //judge whether the job detail file exists
- _, err := os.Stat(ymlPath)
- //not exist
- if os.IsNotExist(err) {
- log.Println("job detail file not exist", err.Error())
- continue
- }
- fileContent, err := os.ReadFile(ymlPath)
- if err != nil {
- log.Println("get job detail read file failed", err.Error())
- continue
- }
- var jobDetailData model2.JobDetail
- //deserialization job yml file
- err = yaml.Unmarshal(fileContent, &jobDetailData)
- if err != nil {
- log.Println("get job detail,deserialization job file failed", err.Error())
- continue
- }
- jobDetailData.Name = name
- svc.UpdateJobDetail(name, &jobDetailData)
- }
- }
-}
-
-// SaveJobWithFile save pipeline job with template file
-func (svc *JobService) SaveJobWithFile(file, name string) {
- //file directory path
- dir := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name)
- src := filepath.Join(utils.DefaultConfigDir(), consts.JOB_DIR_NAME, name, name+".yml")
- //determine whether the folder exists, and create it if it does not exist
- _, err := os.Stat(dir)
- if err != nil && os.IsNotExist(err) {
- err := os.MkdirAll(dir, os.ModePerm)
- if err != nil {
- log.Println("create jobs dir failed", err.Error())
- }
- } else {
- log.Println("the pipeline job name already exists")
- return
- }
- cicdFile, err := os.Open(path.Join(file))
- defer func() {
- cicdFile.Close()
- }()
- yamlFile, err := io.ReadAll(cicdFile)
- //write data to yaml file
- err = os.WriteFile(src, yamlFile, 0777)
- if err != nil {
- log.Println("write data to yaml file failed", err)
- }
-}
diff --git a/engine/service/job_test.go b/engine/service/job_test.go
deleted file mode 100644
index 77a07922..00000000
--- a/engine/service/job_test.go
+++ /dev/null
@@ -1,188 +0,0 @@
-package service
-
-import (
- model2 "github.com/hamster-shared/a-line/engine/model"
- "gopkg.in/yaml.v2"
- "log"
- "os/exec"
- "testing"
-
- "github.com/davecgh/go-spew/spew"
- "github.com/stretchr/testify/assert"
- ass "gotest.tools/v3/assert"
-)
-
-func Test_SaveJob(t *testing.T) {
- step1 := model2.Step{
- Name: "sun",
- Uses: "",
- With: map[string]string{
- "pipelie": "string",
- "data": "data",
- },
- RunsOn: "open",
- Run: "stage",
- }
- var steps []model2.Step
- var strs []string
- strs = append(strs, "strings")
- steps = append(steps, step1)
- job := model2.Job{
- Version: "1",
- Name: "mysql",
- Stages: map[string]model2.Stage{
- "node": {
- Steps: steps,
- Needs: strs,
- },
- },
- }
- jobService := NewJobService()
- data, _ := yaml.Marshal(job)
- err := jobService.SaveJob("qiao", string(data))
- ass.NilError(t, err)
-}
-
-func Test_SaveJobDetail(t *testing.T) {
- step1 := model2.Step{
- Name: "sun",
- Uses: "",
- With: map[string]string{
- "pipelie": "string",
- "data": "data",
- },
- RunsOn: "open",
- Run: "stage",
- }
- var steps []model2.Step
- var strs []string
- strs = append(strs, "strings")
- steps = append(steps, step1)
- stageDetail := model2.StageDetail{
- Name: "string",
- Stage: model2.Stage{
- Steps: steps,
- Needs: strs,
- },
- Status: model2.STATUS_FAIL,
- }
- var stageDetails []model2.StageDetail
- stageDetails = append(stageDetails, stageDetail)
- jobDetail := model2.JobDetail{
- Id: 6,
- Job: model2.Job{
- Version: "2",
- Name: "mysql",
- Stages: map[string]model2.Stage{
- "node": {
- Steps: steps,
- Needs: strs,
- },
- },
- },
- Status: model2.STATUS_NOTRUN,
- Stages: stageDetails,
- }
- jobService := NewJobService()
- jobService.SaveJobDetail("sun", &jobDetail)
-}
-
-func Test_GetJob(t *testing.T) {
- jobService := NewJobService()
- data := jobService.GetJob("guo")
- log.Println(data)
- assert.NotNil(t, data)
-}
-
-func Test_UpdateJob(t *testing.T) {
- jobService := NewJobService()
- step1 := model2.Step{
- Name: "jian",
- Uses: "",
- With: map[string]string{
- "pipelie": "string",
- "data": "data",
- },
- RunsOn: "open",
- Run: "stage",
- }
- var steps []model2.Step
- var strs []string
- strs = append(strs, "strings")
- steps = append(steps, step1)
- job := model2.Job{
- Version: "1",
- Name: "mysql",
- Stages: map[string]model2.Stage{
- "node": {
- Steps: steps,
- Needs: strs,
- },
- },
- }
- data, _ := yaml.Marshal(job)
- err := jobService.UpdateJob("guo", "jian", string(data))
- ass.NilError(t, err)
-}
-
-func Test_GetJobDetail(t *testing.T) {
- jobService := NewJobService()
- data := jobService.GetJobDetail("sun", 3)
- assert.NotNil(t, data)
-}
-
-func Test_DeleteJob(t *testing.T) {
- jobService := NewJobService()
- err := jobService.DeleteJob("sun")
- ass.NilError(t, err)
-}
-
-func Test_DeleteJobDetail(t *testing.T) {
- jobService := NewJobService()
- err := jobService.DeleteJobDetail("cdqadqa92d3if4r9n8j0", 1)
- ass.NilError(t, err)
-}
-
-func Test_JobList(t *testing.T) {
- jobService := NewJobService()
- data := jobService.JobList("cdqadqa92d3if4r9n8j0", 1, 10)
- assert.NotNil(t, data)
-}
-
-func Test_JobDetailList(t *testing.T) {
- jobService := NewJobService()
- data := jobService.JobDetailList("sun", 2, 10)
- log.Println(data)
- assert.NotNil(t, data)
-}
-
-func Test_ExecuteJob(t *testing.T) {
- jobService := NewJobService()
- jobService.ExecuteJob("sun")
-}
-
-func TestGetJobLog(t *testing.T) {
- jobService := NewJobService()
- log := jobService.GetJobLog("test", 10001)
- if log == nil {
- t.Error("log is nil")
- }
- spew.Dump(log)
-}
-
-func TestGetStageLog(t *testing.T) {
- jobService := NewJobService()
- log := jobService.GetJobStageLog("maven", 11, "code-compile", 0)
- if log == nil {
- t.Error("log is nil")
- }
- spew.Dump(log)
-}
-
-func TestOpenFile(t *testing.T) {
- cmd := exec.Command("open", "/Users/sunjianguo/Desktop/miner")
- err := cmd.Run()
- if err != nil {
- log.Fatalf("cmd.Run() failed with %s\n", err)
- }
-}
diff --git a/engine/service/template.go b/engine/service/template.go
deleted file mode 100644
index b07d97cb..00000000
--- a/engine/service/template.go
+++ /dev/null
@@ -1,123 +0,0 @@
-package service
-
-import (
- "embed"
- "fmt"
- "github.com/hamster-shared/a-line/engine/consts"
- "github.com/hamster-shared/a-line/engine/model"
- "github.com/jinzhu/copier"
- "gopkg.in/yaml.v2"
- "log"
- "path/filepath"
- "strings"
-)
-
-const (
- // TemplateDesPath template description path
- TemplateDesPath = "template/des"
-
- //TemplatePath templates path
- TemplatePath = "template/templates"
-)
-
-//go:embed template/des
-var TemplateDes embed.FS
-
-//go:embed template/templates
-var TemplateDir embed.FS
-
-type ITemplateService interface {
- //GetTemplates get template list
- GetTemplates(lang string) *[]model.Template
-
- //GetTemplateDetail get template detail
- GetTemplateDetail(id int) (*model.TemplateDetail, error)
-}
-
-type TemplateService struct {
-}
-
-func NewTemplateService() *TemplateService {
- return &TemplateService{}
-}
-
-// GetTemplates get template list
-func (t *TemplateService) GetTemplates(lang string) *[]model.Template {
- var list []model.Template
- files, err := TemplateDes.ReadDir(TemplateDesPath)
- if err != nil {
- log.Println("read template des dir failed ", err.Error())
- return &list
- }
- for _, file := range files {
- var templateData model.Template
- desPath := filepath.Join(TemplateDesPath, file.Name())
- fileContent, err := TemplateDes.ReadFile(desPath)
- if err != nil {
- log.Println("get templates failed", err.Error())
- continue
- }
- if consts.LANG_EN == lang {
- var template model.TemplateEnglish
- err = yaml.Unmarshal(fileContent, &template)
- if err != nil {
- log.Println("get templates failed", err.Error())
- continue
- }
- copier.Copy(&templateData, &template)
- templateData.Description = template.DescriptionEnglish
- }
- if consts.LANG_ZH == lang {
- var template model.TemplateChinese
- err = yaml.Unmarshal(fileContent, &template)
- if err != nil {
- log.Println("get templates failed", err.Error())
- continue
- }
- copier.Copy(&templateData, &template)
- templateData.Description = template.DescriptionChinese
- }
-
- list = append(list, templateData)
- }
- return &list
-}
-
-// GetTemplateDetail get template detail
-func (t *TemplateService) GetTemplateDetail(id int) (*model.TemplateDetail, error) {
- var detailData model.TemplateDetail
- //template description path
- files, err := TemplateDes.ReadDir(TemplateDesPath)
- if err != nil {
- log.Println("get template detail failed ", err.Error())
- return &detailData, err
- }
- //get template file name
- for _, file := range files {
- var templateData model.TemplateVo
- desPath := filepath.Join(TemplateDesPath, file.Name())
- fileContent, err := TemplateDes.ReadFile(desPath)
- if err != nil {
- log.Println("get templates failed", err.Error())
- continue
- }
- err = yaml.Unmarshal(fileContent, &templateData)
- if err != nil {
- log.Println("get templates failed", err.Error())
- continue
- }
- // Determine if it starts with id_
- if strings.HasPrefix(file.Name(), fmt.Sprintf("%d_", id)) {
- copier.Copy(&detailData, &templateData)
- templatePath := filepath.Join(TemplatePath, templateData.Template)
- templateContent, err := TemplateDir.ReadFile(templatePath)
- if err != nil {
- log.Println("get templates yaml content failed", err.Error())
- break
- }
- detailData.Yaml = string(templateContent)
- break
- }
- }
- return &detailData, err
-}
diff --git a/engine/service/template/des/11_gear.yml b/engine/service/template/des/11_gear.yml
deleted file mode 100644
index 0e6e5552..00000000
--- a/engine/service/template/des/11_gear.yml
+++ /dev/null
@@ -1,18 +0,0 @@
-#template id
-id: 11
-
-#Template name
-name: "gear hello world"
-
-#Template Description
-descriptionEnglish: "The template is designed to build Gear smart contracts, enabling fully automated cloning -> token code pulling -> contract compilation -> contract deployment."
-descriptionChinese: "该模版是为了构建Gear智能合约,实现全自动克隆 -> 令牌代码拉取 -> 合约编译 -> 合约部署。"
-
-#Template classification
-tag: "SMART_CONTRACT_TEMPLATE"
-
-#Corresponding picture name
-imageName: "gear"
-
-#Affiliate Template
-template: "gear-hello-world.yml"
diff --git a/engine/service/template/des/12_ink.yml b/engine/service/template/des/12_ink.yml
deleted file mode 100644
index 7a388137..00000000
--- a/engine/service/template/des/12_ink.yml
+++ /dev/null
@@ -1,18 +0,0 @@
-#template id
-id: 12
-
-#Template name
-name: "ink erc20"
-
-#Template Description
-descriptionEnglish: "This template is a blockchain smart contract built on the Substrate framework, which realizes automatic contract compilation ->contract deployment."
-descriptionChinese: "该模版是构建在Substrate框架上的区块链智能合约,实现全自动合约编译 -> 合约部署。"
-
-#Template classification
-tag: "SMART_CONTRACT_TEMPLATE"
-
-#Corresponding picture name
-imageName: "ink"
-
-#Affiliate Template
-template: "ink-erc20.yml"
diff --git a/engine/service/template/des/13_erc20.yml b/engine/service/template/des/13_erc20.yml
deleted file mode 100644
index 04bbcd18..00000000
--- a/engine/service/template/des/13_erc20.yml
+++ /dev/null
@@ -1,18 +0,0 @@
-#template id
-id: 13
-
-#Template name
-name: "defi erc20"
-
-#Template Description
-descriptionEnglish: "This template is used for DApps written on Truffle framework to fully automate code checkout -> check front-end code quality -> edit front-end code -> deploy front-end code."
-descriptionChinese: "该模版用于基于Truffle框架编写的DApp,实现全自动检出代码 -> 检查前端代码质量 -> 编辑前端代码 -> 部署前端代码。"
-
-#Template classification
-tag: "DAPP_TEMPLATE(Frontend)"
-
-#Corresponding picture name
-imageName: "truffle"
-
-#Affiliate Template
-template: "erc20.yml"
diff --git a/engine/service/template/templates/erc20.yml b/engine/service/template/templates/erc20.yml
deleted file mode 100644
index 53b29501..00000000
--- a/engine/service/template/templates/erc20.yml
+++ /dev/null
@@ -1,89 +0,0 @@
-version: 1.0
-name: my-erc20
-stages:
- Initialization:
- steps:
- - name: set workdir
- uses: workdir
- with:
- workdir: $HOME/tmp/my-erc20
- - name: template init
- uses: git-checkout
- with:
- url: https://github.com/abing258/truffle-moonbeam-MC.git
- branch: master
-
- Build Contract:
- needs:
- - Initialization
- steps:
- - name: compile
- run: |
- npm install
- npm install -g truffle
- truffle compile
-
- Check Solidity Contract:
- needs:
- - Build Contract
- steps:
- - name: solidity-check
- run: |
- npm install -g ethlint
- solium --init
- solium -d contracts/
-
- Start Local Chain:
- needs:
- - Check Solidity Contract
- steps:
- - name: ganache
- run: |
- npm install -g ganache
- if [ -f "command.pid" ]; then
- kill -9 `cat command.pid` || (echo 'No such process ')
- fi
- nohup ganache > ganache.log 2>&1& echo $! > command.pid
- sleep 2
-
- Test Contract:
- needs:
- - Start Local Chain
- steps:
- - name: deploy
- run: |
- truffle test
-
- Deploy Contract:
- needs:
- - Test Contract
- steps:
- - name: deploy-contract
- uses: deploy-contract
- with:
- ## network 的值有:default,rinkeby,goerli,mainnet,moonbeam,moonriver,moonbase
- network: moonbase
- private-key: c2790be05286f9f90f43f9fe9e3bf06c1394d480c3bf5233450a8e6b0a748fbe
-
- Build Front-End:
- needs:
- - Deploy Contract
- steps:
- - name: compile
- run: |
- cd app && npm install
- npm run build
-
- Deploy Front-End:
- needs:
- - Build Front-End
- steps:
- - name: deploy
- run: |
- cd app
- if [ -f "node.pid" ]; then
- kill -9 `cat node.pid` || (echo 'No such process ')
- fi
- nohup npm run dev > node.log 2>&1& echo $! > node.pid
- echo 'frontend url is http://localhost:8081'
- sleep 2
diff --git a/engine/service/template/templates/gear-hello-world.yml b/engine/service/template/templates/gear-hello-world.yml
deleted file mode 100644
index eee8eb8b..00000000
--- a/engine/service/template/templates/gear-hello-world.yml
+++ /dev/null
@@ -1,85 +0,0 @@
-version: 1.0
-name: my-gear-hello-world
-stages:
- Initialization:
- steps:
- - name: set workdir
- uses: workdir
- with:
- workdir: $HOME/tmp/my-gear/hello-world
- - name: git clone gear hello world
- uses: git-checkout
- with:
- url: https://github.com/jlvihv/gear-hello-world
- branch: develop
- - name: set workdir
- uses: workdir
- with:
- workdir: $HOME/tmp/my-gear/gear-deploy
- - name: git clone gear deploy script
- uses: git-checkout
- with:
- url: https://github.com/jlvihv/gear-deploy
- branch: hello-world-use-mnemonic
-
- Build Contract:
- needs:
- - Initialization
- steps:
- - name: set workdir
- uses: workdir
- with:
- workdir: $HOME/tmp/my-gear/hello-world
- - name: make hello world
- run: |
- make
-
- Upload Contract:
- needs:
- - Build Contract
- steps:
- - name: set workdir
- uses: workdir
- with:
- workdir: $HOME/tmp/my-gear/gear-deploy
- - name: gear deploy
- run: |
- export NODE_TLS_REJECT_UNAUTHORIZED=0
- export MNEMONIC=//Alice
- export PROVIDER_ADDRESS=wss://rpc-node.gear-tech.io
- npm install
- npm run upload
-
- Build Front-End:
- needs:
- - Upload Contract
- steps:
- - name: set workdir
- uses: workdir
- with:
- workdir: $HOME/tmp/my-gear/hello-world/frontend
- - name: make hello world frontend
- run: |
- cp .env.example .env
- cat ../../gear-deploy/programID.txt >> .env
- echo '' >> .env
- cat ../../gear-deploy/metaString.txt >> .env
- yarn
- yarn add @polkadot/util-crypto
-
- Deploy Front-End:
- needs:
- - Build Front-End
- steps:
- - name: set workdir
- uses: workdir
- with:
- workdir: $HOME/tmp/my-gear/hello-world/frontend
- - name: make hello world frontend
- run: |
- if [ -f "gear_node.pid" ]; then
- kill -9 `cat gear_node.pid` || (echo 'No such process ')
- fi
- nohup yarn run start > node.log 2>&1& echo $! > gear_node.pid
- echo 'frontend url is http://localhost:3000'
- sleep 2
\ No newline at end of file
diff --git a/engine/service/template/templates/gear.yml b/engine/service/template/templates/gear.yml
deleted file mode 100644
index ed1f6f23..00000000
--- a/engine/service/template/templates/gear.yml
+++ /dev/null
@@ -1,46 +0,0 @@
-version: 1.0
-name: my-gear
-stages:
- clone-code-gear-non-fungible-token:
- steps:
- - name: set workdir
- uses: workdir
- with:
- workdir: $HOME/workdir/my-gear/non-fungible-token
- - name: git clone gear non fungible token
- uses: git-checkout
- with:
- url: https://github.com/gear-dapps/non-fungible-token
- branch: master
- clone-code-gear-deploy-script:
- steps:
- - name: set workdir
- uses: workdir
- with:
- workdir: $HOME/workdir/my-gear/gear-deploy
- - name: git clone gear deploy script
- uses: git-checkout
- with:
- url: https://github.com/jlvihv/gear-deploy
- branch: main
-
- gear-code-compile:
- needs:
- - clone-code-gear-non-fungible-token
- - clone-code-gear-deploy-script
- steps:
- - name: set workdir
- uses: workdir
- with:
- workdir: $HOME/workdir/my-gear/non-fungible-token
- - name: make non fungible token
- run: |
- make
- - name: set workdir
- uses: workdir
- with:
- workdir: $HOME/workdir/my-gear/gear-deploy
- - name: gear deploy
- run: |
- npm install
- npm run code:submit
diff --git a/engine/service/template/templates/hardhat.yml b/engine/service/template/templates/hardhat.yml
deleted file mode 100644
index 14cf446b..00000000
--- a/engine/service/template/templates/hardhat.yml
+++ /dev/null
@@ -1,45 +0,0 @@
-version: 1.0
-name: my-hardhat
-stages:
- git-clone:
- steps:
- - name: git-clone
- uses: git-checkout
- with:
- url: https://github.com/mohaijiang/hardhat-example.git
- branch: main
- code-compile:
- needs:
- - git-clone
- steps:
- - name: code-compile
- run: |
- npm install --save-dev hardhat
- npx hardhat compile
-
- contract-lint:
- needs:
- - code-compile
- steps:
- - name: solidity-check
- run: |
- npm install -g ethlint
- solium --init
- solium -d contracts/
-
- contract-test:
- needs:
- - contract-lint
- steps:
- - name: contract test
- run: |
- npx hardhat test
-
- deploy:
- needs:
- - contract-test
- steps:
- - name: contract deploy
- run: |
- npx hardhat run scripts/deploy.ts
-
diff --git a/engine/service/template/templates/ink-erc20.yml b/engine/service/template/templates/ink-erc20.yml
deleted file mode 100644
index 7d560106..00000000
--- a/engine/service/template/templates/ink-erc20.yml
+++ /dev/null
@@ -1,72 +0,0 @@
-version: 1.0
-name: ink-erc20
-stages:
- Initialization:
- steps:
- - name: set workdir
- uses: workdir
- with:
- workdir: $HOME/tmp/ink-erc20
- - name: template init
- uses: git-checkout
- with:
- url: https://github.com/abing258/ink-erc20.git
- branch: master
- - name: set workdir
- uses: workdir
- with:
- workdir: $HOME/tmp/polkadot
- - name: frontend init
- uses: git-checkout
- with:
- url: https://github.com/abing258/polkadot-js-apps.git
- branch: master
-
-
- Build Contract:
- needs:
- - Initialization
- steps:
- - name: set workdir
- uses: workdir
- with:
- workdir: $HOME/tmp/ink-erc20
- - name: Build Contract
- run: |
- cargo +nightly contract build
-
- Deploy Contract:
- needs:
- - Build Contract
- steps:
- - name: Deploy Contract
- uses: deploy-ink-contract
- with:
- ## network的值有:Local,Rococo,Shibuya,Shiden
- network: Local
- mnemonic: laptop lyrics puppy only conduct frog little test tail atom foil wolf
-
- Build Front-End:
- needs:
- - Deploy Contract
- steps:
- - name: set workdir
- uses: workdir
- with:
- workdir: $HOME/tmp/polkadot
- - name: Build Front-End
- run: |
- yarn install
-
- Deploy Front-End:
- needs:
- - Build Front-End
- steps:
- - name: Deploy Front-End
- run: |
- if [ -f "polkadot_node.pid" ]; then
- kill -9 `cat polkadot_node.pid` || (echo 'No such process ')
- fi
- nohup yarn run start > node.log 2>&1& echo $! > polkadot_node.pid
- echo 'frontend url is http://localhost:3000'
- sleep 2
\ No newline at end of file
diff --git a/engine/service/template/templates/maven.yml b/engine/service/template/templates/maven.yml
deleted file mode 100644
index 8a00b0ef..00000000
--- a/engine/service/template/templates/maven.yml
+++ /dev/null
@@ -1,29 +0,0 @@
-version: "1.0"
-name: my-test2
-stages:
- git-clone:
- steps:
- - name: git-clone
- uses: git-checkout
- with:
- url: https://gitee.com/mohaijiang/spring-boot-example.git
- branch: master
- code-compile:
- needs:
- - git-clone
- steps:
- - name: code-compile
- runs-on: maven:3.5-jdk-8
- run: |
- mvn clean package -Dmaven.test.skip=true
- - name: save artifactory
- uses: hamster-artifactory
- with:
- name: some.zip
- path: target/*.jar
- build-image:
- needs:
- - code-compile
- steps:
- - run: |
- docker build -t mohaijiang/spring-boot-example:latest .
diff --git a/engine/service/template/templates/truffle.yml b/engine/service/template/templates/truffle.yml
deleted file mode 100644
index cfcaf0de..00000000
--- a/engine/service/template/templates/truffle.yml
+++ /dev/null
@@ -1,44 +0,0 @@
-version: 1.0
-name: my-truffle
-stages:
- git-clone:
- steps:
- - name: git-clone
- uses: git-checkout
- with:
- url: https://github.com/mohaijiang/truffle-MetaCoin.git
- branch: main
- code-compile:
- needs:
- - git-clone
- steps:
- - name: code-compile
- run: |
- npm install -g truffle
- truffle compile
-
- solidity-lint:
- needs:
- - code-compile
- steps:
- - name: solidity-check
- run: |
- npm install -g ethlint
- solium --init
- solium --rule 'indentation: ["error", "tab"]' -d contracts/
-
- contract-test:
- needs:
- - code-compile
- steps:
- - name: deploy
- run: |
- truffle test
-
- deploy-contract:
- needs:
- - contract-test
- steps:
- - name: deploy
- run: |
- truffle migrate
diff --git a/engine/service/template_test.go b/engine/service/template_test.go
deleted file mode 100644
index f41b38df..00000000
--- a/engine/service/template_test.go
+++ /dev/null
@@ -1,20 +0,0 @@
-package service
-
-import (
- "github.com/stretchr/testify/assert"
- "testing"
-)
-
-func Test_GetTemplates(t *testing.T) {
- templateService := NewTemplateService()
- lang := "en"
- data := templateService.GetTemplates(lang)
- t.Log(data)
- assert.NotEmpty(t, data)
-}
-
-func Test_GetTemplateDetail(t *testing.T) {
- templateService := NewTemplateService()
- detailData, _ := templateService.GetTemplateDetail(4)
- assert.NotNil(t, detailData)
-}
diff --git a/engine/utils/compress.go b/engine/utils/compress.go
deleted file mode 100644
index c7512ffa..00000000
--- a/engine/utils/compress.go
+++ /dev/null
@@ -1,127 +0,0 @@
-package utils
-
-import (
- "archive/zip"
- "io"
- "os"
- "path/filepath"
- "strings"
-)
-
-// CompressZip Compress files to zip
-// files File array, which can be files or folders under different dirs
-// dest Compressed file storage address
-func CompressZip(files []*os.File, dest string) error {
- dir := filepath.Dir(dest)
- _, err := os.Stat(dir)
- if os.IsNotExist(err) {
- err := os.MkdirAll(dir, os.ModePerm)
- if err != nil {
- return err
- }
- }
- d, _ := os.Create(dest)
- defer d.Close()
- w := zip.NewWriter(d)
- defer w.Close()
- for _, file := range files {
- err := compress(file, "", w)
- file.Close()
- if err != nil {
- return err
- }
- }
- return nil
-}
-
-func compress(file *os.File, prefix string, zw *zip.Writer) error {
- info, err := file.Stat()
- if err != nil {
- return err
- }
- if info.IsDir() {
- prefix = prefix + "/" + info.Name()
- fileInfos, err := file.Readdir(-1)
- if err != nil {
- return err
- }
- for _, fi := range fileInfos {
- f, err := os.Open(file.Name() + "/" + fi.Name())
- if err != nil {
- return err
- }
- err = compress(f, prefix, zw)
- if err != nil {
- return err
- }
- }
- } else {
- header, err := zip.FileInfoHeader(info)
- header.Name = prefix + "/" + header.Name
- if err != nil {
- return err
- }
- writer, err := zw.CreateHeader(header)
- if err != nil {
- return err
- }
- _, err = io.Copy(writer, file)
- file.Close()
- if err != nil {
- return err
- }
- }
- return nil
-}
-
-// DeCompressZip Zip unzip
-func DeCompressZip(zipFile, dest string) error {
- reader, err := zip.OpenReader(zipFile)
- if err != nil {
- return err
- }
- defer reader.Close()
- for _, file := range reader.File {
- rc, err := file.Open()
- if err != nil {
- return err
- }
- defer rc.Close()
- filename := dest + file.Name
- err = os.MkdirAll(getDir(filename), 0755)
- if err != nil {
- return err
- }
- w, err := os.Create(filename)
- if err != nil {
- return err
- }
- defer w.Close()
- _, err = io.Copy(w, rc)
- if err != nil {
- return err
- }
- w.Close()
- rc.Close()
- }
- return nil
-}
-
-func getDir(path string) string {
- return subString(path, 0, strings.LastIndex(path, "/"))
-}
-
-func subString(str string, start, end int) string {
- rs := []rune(str)
- length := len(rs)
-
- if start < 0 || start > length {
- panic("start is wrong")
- }
-
- if end < start || end > length {
- panic("end is wrong")
- }
-
- return string(rs[start:end])
-}
diff --git a/engine/utils/create_car.go b/engine/utils/create_car.go
deleted file mode 100644
index f1cb9ed2..00000000
--- a/engine/utils/create_car.go
+++ /dev/null
@@ -1,142 +0,0 @@
-package utils
-
-import (
- "bytes"
- "context"
- "fmt"
- "io"
- "os"
- "path"
-
- blocks "github.com/ipfs/go-block-format"
- "github.com/ipfs/go-cid"
- "github.com/ipfs/go-unixfsnode/data/builder"
- "github.com/ipld/go-car/v2"
- "github.com/ipld/go-car/v2/blockstore"
- dagpb "github.com/ipld/go-codec-dagpb"
- "github.com/ipld/go-ipld-prime"
- cidlink "github.com/ipld/go-ipld-prime/linking/cid"
- "github.com/multiformats/go-multicodec"
- "github.com/multiformats/go-multihash"
-)
-
-// copied from https://github.com/ipld/go-car/blob/master/cmd/car/create.go
-
-func CreateCar(
- ctx context.Context,
- inputDirectory string,
- outputFile string,
- // this can be 1 or 2
- version int,
-) (string, error) {
- // make a cid with the right length that we eventually will patch with the root.
- hasher, err := multihash.GetHasher(multihash.SHA2_256)
- if err != nil {
- return "", err
- }
- digest := hasher.Sum([]byte{})
- hash, err := multihash.Encode(digest, multihash.SHA2_256)
- if err != nil {
- return "", err
- }
- proxyRoot := cid.NewCidV1(uint64(multicodec.DagPb), hash)
-
- options := []car.Option{}
-
- switch version {
- case 1:
- options = []car.Option{blockstore.WriteAsCarV1(true)}
- case 2:
- // already the default
- default:
- return "", fmt.Errorf("invalid CAR version %d", version)
- }
-
- cdest, err := blockstore.OpenReadWrite(outputFile, []cid.Cid{proxyRoot}, options...)
- if err != nil {
- return "", err
- }
-
- // Write the unixfs blocks into the store.
- files, err := os.ReadDir(inputDirectory)
- if err != nil {
- return "", err
- }
-
- carFilePaths := []string{}
- for _, file := range files {
- carFilePaths = append(carFilePaths, fmt.Sprintf("%s/%s", inputDirectory, file.Name()))
- }
-
- root, err := writeFiles(ctx, cdest, carFilePaths...)
- if err != nil {
- return "", err
- }
-
- if err := cdest.Finalize(); err != nil {
- return "", err
- }
- // re-open/finalize with the final root.
- if err := car.ReplaceRootsInFile(outputFile, []cid.Cid{root}); err != nil {
- return "", err
- }
- return root.String(), nil
-}
-
-func writeFiles(ctx context.Context, bs *blockstore.ReadWrite, paths ...string) (cid.Cid, error) {
- ls := cidlink.DefaultLinkSystem()
- ls.TrustedStorage = true
- ls.StorageReadOpener = func(_ ipld.LinkContext, l ipld.Link) (io.Reader, error) {
- cl, ok := l.(cidlink.Link)
- if !ok {
- return nil, fmt.Errorf("not a cidlink")
- }
- blk, err := bs.Get(ctx, cl.Cid)
- if err != nil {
- return nil, err
- }
- return bytes.NewBuffer(blk.RawData()), nil
- }
- ls.StorageWriteOpener = func(_ ipld.LinkContext) (io.Writer, ipld.BlockWriteCommitter, error) {
- buf := bytes.NewBuffer(nil)
- return buf, func(l ipld.Link) error {
- cl, ok := l.(cidlink.Link)
- if !ok {
- return fmt.Errorf("not a cidlink")
- }
- blk, err := blocks.NewBlockWithCid(buf.Bytes(), cl.Cid)
- if err != nil {
- return err
- }
- bs.Put(ctx, blk) //nolint:errcheck
- return nil
- }, nil
- }
-
- topLevel := make([]dagpb.PBLink, 0, len(paths))
- for _, p := range paths {
- l, size, err := builder.BuildUnixFSRecursive(p, &ls)
- if err != nil {
- return cid.Undef, err
- }
- name := path.Base(p)
- entry, err := builder.BuildUnixFSDirectoryEntry(name, int64(size), l)
- if err != nil {
- return cid.Undef, err
- }
- topLevel = append(topLevel, entry)
- }
-
- // make a directory for the file(s).
-
- root, _, err := builder.BuildUnixFSDirectory(topLevel, &ls)
- if err != nil {
- return cid.Undef, nil
- }
- rcl, ok := root.(cidlink.Link)
- if !ok {
- return cid.Undef, fmt.Errorf("could not interpret %s", root)
- }
-
- return rcl.Cid, nil
-}
diff --git a/engine/utils/platform/util_darwin.go b/engine/utils/platform/util_darwin.go
deleted file mode 100644
index 02faa3a9..00000000
--- a/engine/utils/platform/util_darwin.go
+++ /dev/null
@@ -1,29 +0,0 @@
-package platform
-
-import (
- "github.com/hamster-shared/a-line/engine/logger"
- "os"
- "os/exec"
- "syscall"
- "time"
-)
-
-// GetFileCreateTime get file create time
-func GetFileCreateTime(path string) *time.Time {
- var createTime time.Time
- fileInfo, _ := os.Stat(path)
- fileSys := fileInfo.Sys().(*syscall.Stat_t)
- createTime = time.Unix(fileSys.Ctimespec.Sec, 0)
- return &createTime
-}
-
-// OpenDir Open folder
-func OpenDir(path string) error {
- cmd := exec.Command("open", path)
- err := cmd.Run()
- if err != nil {
- logger.Errorf("darwin open dir failed with %s\n", err.Error())
- return err
- }
- return nil
-}
diff --git a/engine/utils/platform/util_linux.go b/engine/utils/platform/util_linux.go
deleted file mode 100644
index 9a6acca6..00000000
--- a/engine/utils/platform/util_linux.go
+++ /dev/null
@@ -1,29 +0,0 @@
-package platform
-
-import (
- "github.com/hamster-shared/a-line/engine/logger"
- "os"
- "os/exec"
- "syscall"
- "time"
-)
-
-// GetFileCreateTime get file create time
-func GetFileCreateTime(path string) *time.Time {
- var createTime time.Time
- fileInfo, _ := os.Stat(path)
- stat_t := fileInfo.Sys().(*syscall.Stat_t)
- createTime = time.Unix(stat_t.Ctim.Sec, 0)
- return &createTime
-}
-
-// OpenDir Open folder
-func OpenDir(path string) error {
- cmd := exec.Command("nautilus", path)
- err := cmd.Run()
- if err != nil {
- logger.Errorf("linux open dir failed with %s\n", err.Error())
- return err
- }
- return nil
-}
diff --git a/engine/utils/platform/util_windows.go b/engine/utils/platform/util_windows.go
deleted file mode 100644
index 786f0c39..00000000
--- a/engine/utils/platform/util_windows.go
+++ /dev/null
@@ -1,33 +0,0 @@
-package platform
-
-import (
- "fmt"
- "github.com/hamster-shared/a-line/engine/logger"
- "os"
- "os/exec"
- "syscall"
- "time"
-)
-
-// GetFileCreateTime get file create time
-func GetFileCreateTime(path string) *time.Time {
- var createTime time.Time
- fileInfo, _ := os.Stat(path)
- wFileSys := fileInfo.Sys().(*syscall.Win32FileAttributeData)
- tNanSeconds := wFileSys.CreationTime.Nanoseconds()
- tSec := tNanSeconds / 1e9
- createTime = time.Unix(tSec, 0)
- fmt.Println("windows create time: ", createTime)
- return &createTime
-}
-
-// OpenDir Open folder
-func OpenDir(path string) error {
- cmd := exec.Command("explorer", path)
- err := cmd.Run()
- if err != nil {
- logger.Errorf("windows open dir failed with %s\n", err.Error())
- return err
- }
- return nil
-}
diff --git a/engine/utils/stack.go b/engine/utils/stack.go
deleted file mode 100644
index 09fec5e7..00000000
--- a/engine/utils/stack.go
+++ /dev/null
@@ -1,32 +0,0 @@
-package utils
-
-import (
- "errors"
-)
-
-// Stack 堆栈
-type Stack[T interface{}] struct {
- elements []T
-}
-
-// Push 入栈
-func (s *Stack[T]) Push(value T) {
- s.elements = append(s.elements, value)
-}
-
-// Pop 出栈
-func (s *Stack[T]) Pop() (T, error) {
- if len(s.elements) == 0 {
- return *new(T), errors.New("empty stack")
- }
- a := s.elements
- defer func() {
- s.elements = a[:len(a)-1]
- }()
- return a[len(a)-1], nil
-}
-
-// IsEmpty 判断堆栈是否为空
-func (s *Stack[T]) IsEmpty() bool {
- return len(s.elements) == 0
-}
diff --git a/engine/utils/template.go b/engine/utils/template.go
deleted file mode 100644
index f383a226..00000000
--- a/engine/utils/template.go
+++ /dev/null
@@ -1,25 +0,0 @@
-package utils
-
-import (
- "regexp"
- "strings"
-)
-
-// ReplaceWithParam 参数替换
-func ReplaceWithParam(content string, paramMap map[string]string) string {
- compileRegex := regexp.MustCompile("\\${{.*?}}")
- matchArr := compileRegex.FindStringSubmatch(content)
-
- result := strings.Clone(content)
- for _, arr := range matchArr {
- key := strings.Replace(arr, "${{", "", 1)
- key = strings.Replace(key, "}}", "", 1)
- key = strings.Fields(key)[0]
- if strings.HasPrefix(key, "param.") {
- key = strings.Replace(key, "param.", "", 1)
- result = strings.Replace(result, arr, paramMap[key], -1)
- }
- }
-
- return result
-}
diff --git a/engine/utils/util.go b/engine/utils/util.go
deleted file mode 100644
index 0dd915b9..00000000
--- a/engine/utils/util.go
+++ /dev/null
@@ -1,109 +0,0 @@
-package utils
-
-import (
- "context"
- "github.com/hamster-shared/a-line/engine/consts"
- "log"
- "math"
- "math/rand"
- "os"
- "os/exec"
- "os/user"
- "path/filepath"
-)
-
-var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
-
-func RandSeq(n int) string {
- b := make([]rune, n)
- for i := range b {
- b[i] = letters[rand.Intn(len(letters))]
- }
- return string(b)
-}
-
-func GetUIDAndGID() (string, string, error) {
- u, err := user.Current()
- if err != nil {
- return "", "", err
- }
- return u.Uid, u.Gid, nil
-}
-
-type Cmd struct {
- ctx context.Context
- *exec.Cmd
-}
-
-// NewCommand is like exec.CommandContext but ensures that subprocesses
-// are killed when the context times out, not just the top level process.
-func NewCommand(ctx context.Context, command string, args ...string) *Cmd {
- return &Cmd{ctx, exec.Command(command, args...)}
-}
-
-func (c *Cmd) Start() error {
- // Force-enable setpgid bit so that we can kill child processes when the
- // context times out or is canceled.
- //if c.Cmd.SysProcAttr == nil {
- // c.Cmd.SysProcAttr = &syscall.SysProcAttr{}
- //}
- //c.Cmd.SysProcAttr.Setpgid = true
- err := c.Cmd.Start()
- if err != nil {
- return err
- }
- go func() {
- <-c.ctx.Done()
- p := c.Cmd.Process
- if p == nil {
- return
- }
- // Kill by negative PID to kill the process group, which includes
- // the top-level process we spawned as well as any subprocesses
- // it spawned.
- //_ = syscall.Kill(-p.Pid, syscall.SIGKILL)
- }()
- return nil
-}
-
-func (c *Cmd) Run() error {
- if err := c.Start(); err != nil {
- return err
- }
- return c.Wait()
-}
-
-func DefaultConfigDir() string {
- userHomeDir, err := os.UserHomeDir()
- if err != nil {
- log.Println("get user home dir failed", err.Error())
- return consts.PIPELINE_DIR_NAME + "."
- }
- dir := filepath.Join(userHomeDir, consts.PIPELINE_DIR_NAME)
- return dir
-}
-
-// SlicePage paging return:page,pageSize,start,end
-func SlicePage(page, pageSize, nums int) (int, int, int, int) {
- if page <= 0 {
- page = 1
- }
- if pageSize < 0 {
- pageSize = 10
- }
- if pageSize > nums {
- return page, pageSize, 0, nums
- }
- // total page
- pageCount := int(math.Ceil(float64(nums) / float64(pageSize)))
- if page > pageCount {
- return page, pageSize, 0, 0
- }
- sliceStart := (page - 1) * pageSize
- sliceEnd := sliceStart + pageSize
-
- if sliceEnd > nums {
- sliceEnd = nums
- }
- return page, pageSize, sliceStart, sliceEnd
-}
diff --git a/go.mod b/go.mod
index 0031b307..efe133ea 100644
--- a/go.mod
+++ b/go.mod
@@ -1,38 +1,27 @@
-module github.com/hamster-shared/a-line
+module github.com/hamster-shared/hamster-develop
go 1.19
require (
- github.com/davecgh/go-spew v1.1.1
github.com/gin-gonic/gin v1.8.1
github.com/go-resty/resty/v2 v2.7.0
github.com/google/go-github/v48 v48.2.0
github.com/goperate/convert v0.0.7
- github.com/ipfs/go-block-format v0.0.3
- github.com/ipfs/go-cid v0.2.0
- github.com/ipfs/go-unixfsnode v1.4.0
- github.com/ipld/go-car/v2 v2.4.1
- github.com/ipld/go-codec-dagpb v1.4.1
- github.com/ipld/go-ipld-prime v0.17.0
+ github.com/hamster-shared/aline-engine v1.0.1
github.com/iris-contrib/go.uuid v2.0.0+incompatible
github.com/jinzhu/copier v0.3.5
- github.com/multiformats/go-multicodec v0.5.0
- github.com/multiformats/go-multihash v0.2.0
github.com/sirupsen/logrus v1.9.0
- github.com/stretchr/testify v1.8.0
+ github.com/stretchr/testify v1.8.1
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
- google.golang.org/grpc v1.51.0
- google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.4.4
gorm.io/gorm v1.24.2
- gotest.tools/v3 v3.4.0
)
require (
- github.com/Stebalien/go-bitfield v1.0.0 // indirect
github.com/btcsuite/btcd v0.22.0-beta // indirect
+ github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
@@ -41,14 +30,15 @@ require (
github.com/goccy/go-json v0.9.11 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
- github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-querystring v1.1.0 // indirect
- github.com/google/uuid v1.2.0 // indirect
+ github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/ipfs/bbloom v0.0.4 // indirect
github.com/ipfs/go-bitfield v1.0.0 // indirect
+ github.com/ipfs/go-block-format v0.0.3 // indirect
github.com/ipfs/go-blockservice v0.3.0 // indirect
+ github.com/ipfs/go-cid v0.3.2 // indirect
github.com/ipfs/go-datastore v0.6.0 // indirect
github.com/ipfs/go-ipfs-blockstore v1.2.0 // indirect
github.com/ipfs/go-ipfs-chunker v0.0.5 // indirect
@@ -62,7 +52,11 @@ require (
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/ipfs/go-merkledag v0.6.0 // indirect
github.com/ipfs/go-metrics-interface v0.0.1 // indirect
+ github.com/ipfs/go-unixfsnode v1.5.1 // indirect
github.com/ipfs/go-verifcid v0.0.1 // indirect
+ github.com/ipld/go-car/v2 v2.5.1 // indirect
+ github.com/ipld/go-codec-dagpb v1.5.0 // indirect
+ github.com/ipld/go-ipld-prime v0.19.0 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
@@ -78,13 +72,14 @@ require (
github.com/multiformats/go-base32 v0.0.4 // indirect
github.com/multiformats/go-base36 v0.1.0 // indirect
github.com/multiformats/go-multibase v0.1.1 // indirect
+ github.com/multiformats/go-multicodec v0.7.0 // indirect
+ github.com/multiformats/go-multihash v0.2.1 // indirect
github.com/multiformats/go-varint v0.0.6 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/petar/GoLLRB v0.0.0-20210522233825-ae3b015fd3e9 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e // indirect
- github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
@@ -100,12 +95,12 @@ require (
golang.org/x/text v0.4.0 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
google.golang.org/appengine v1.6.7 // indirect
- google.golang.org/genproto v0.0.0-20221118155620-16455021b5e6 // indirect
+ google.golang.org/protobuf v1.28.1 // indirect
lukechampine.com/blake3 v1.1.7 // indirect
)
require (
- github.com/antonfisher/nested-logrus-formatter v1.3.1
+ github.com/antonfisher/nested-logrus-formatter v1.3.1 // indirect
github.com/spf13/cobra v1.6.1
golang.org/x/sys v0.2.0 // indirect
)
diff --git a/main.go b/main.go
index efbfcbed..c8d8a3eb 100644
--- a/main.go
+++ b/main.go
@@ -1,8 +1,8 @@
package main
import (
- "github.com/hamster-shared/a-line/cmd"
- "github.com/hamster-shared/a-line/engine/logger"
+ "github.com/hamster-shared/aline-engine/logger"
+ "github.com/hamster-shared/hamster-develop/cmd"
"github.com/sirupsen/logrus"
)
diff --git a/pkg/controller/contract_handler.go b/pkg/controller/contract_handler.go
index 92a438ed..055671b5 100644
--- a/pkg/controller/contract_handler.go
+++ b/pkg/controller/contract_handler.go
@@ -2,10 +2,10 @@ package controller
import (
"github.com/gin-gonic/gin"
- "github.com/hamster-shared/a-line/pkg/application"
- "github.com/hamster-shared/a-line/pkg/db"
- "github.com/hamster-shared/a-line/pkg/parameter"
- "github.com/hamster-shared/a-line/pkg/service"
+ "github.com/hamster-shared/hamster-develop/pkg/application"
+ "github.com/hamster-shared/hamster-develop/pkg/db"
+ "github.com/hamster-shared/hamster-develop/pkg/parameter"
+ "github.com/hamster-shared/hamster-develop/pkg/service"
uuid "github.com/iris-contrib/go.uuid"
"github.com/jinzhu/copier"
"time"
diff --git a/pkg/controller/gin.go b/pkg/controller/gin.go
index 3332115a..562c24fc 100644
--- a/pkg/controller/gin.go
+++ b/pkg/controller/gin.go
@@ -4,7 +4,7 @@ import (
"embed"
"fmt"
"github.com/gin-gonic/gin"
- "github.com/hamster-shared/a-line/pkg/application"
+ "github.com/hamster-shared/hamster-develop/pkg/application"
"gorm.io/gorm"
"io/fs"
"net/http"
diff --git a/pkg/controller/handler.go b/pkg/controller/handler.go
index f3d680c6..98f0437e 100644
--- a/pkg/controller/handler.go
+++ b/pkg/controller/handler.go
@@ -2,14 +2,14 @@ package controller
import (
"github.com/gin-gonic/gin"
- "github.com/hamster-shared/a-line/engine"
- "github.com/hamster-shared/a-line/engine/consts"
- "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/engine/utils"
- "github.com/hamster-shared/a-line/engine/utils/platform"
- "github.com/hamster-shared/a-line/pkg/controller/parameters"
- service2 "github.com/hamster-shared/a-line/pkg/service"
- "github.com/hamster-shared/a-line/pkg/vo"
+ engine "github.com/hamster-shared/aline-engine"
+ "github.com/hamster-shared/aline-engine/consts"
+ "github.com/hamster-shared/aline-engine/model"
+ "github.com/hamster-shared/aline-engine/utils"
+ "github.com/hamster-shared/aline-engine/utils/platform"
+ "github.com/hamster-shared/hamster-develop/pkg/controller/parameters"
+ service2 "github.com/hamster-shared/hamster-develop/pkg/service"
+ "github.com/hamster-shared/hamster-develop/pkg/vo"
"gopkg.in/yaml.v3"
"path/filepath"
"strconv"
diff --git a/pkg/controller/log_handler.go b/pkg/controller/log_handler.go
index 3997c2e7..500a4067 100644
--- a/pkg/controller/log_handler.go
+++ b/pkg/controller/log_handler.go
@@ -2,10 +2,10 @@ package controller
import (
"github.com/gin-gonic/gin"
- "github.com/hamster-shared/a-line/engine"
- "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/pkg/application"
- "github.com/hamster-shared/a-line/pkg/service"
+ engine "github.com/hamster-shared/aline-engine"
+ "github.com/hamster-shared/aline-engine/model"
+ "github.com/hamster-shared/hamster-develop/pkg/application"
+ "github.com/hamster-shared/hamster-develop/pkg/service"
"strconv"
)
diff --git a/pkg/controller/login_handler.go b/pkg/controller/login_handler.go
index 98df68c0..9a116228 100644
--- a/pkg/controller/login_handler.go
+++ b/pkg/controller/login_handler.go
@@ -2,11 +2,11 @@ package controller
import (
"github.com/gin-gonic/gin"
- "github.com/hamster-shared/a-line/pkg/application"
- "github.com/hamster-shared/a-line/pkg/consts"
- "github.com/hamster-shared/a-line/pkg/parameter"
- "github.com/hamster-shared/a-line/pkg/service"
- "github.com/hamster-shared/a-line/pkg/utils"
+ "github.com/hamster-shared/hamster-develop/pkg/application"
+ "github.com/hamster-shared/hamster-develop/pkg/consts"
+ "github.com/hamster-shared/hamster-develop/pkg/parameter"
+ "github.com/hamster-shared/hamster-develop/pkg/service"
+ "github.com/hamster-shared/hamster-develop/pkg/utils"
"net/http"
)
diff --git a/pkg/controller/project_handler.go b/pkg/controller/project_handler.go
index 7cf0e7a1..d26088a2 100644
--- a/pkg/controller/project_handler.go
+++ b/pkg/controller/project_handler.go
@@ -3,12 +3,12 @@ package controller
import (
"embed"
"github.com/gin-gonic/gin"
- "github.com/hamster-shared/a-line/pkg/application"
- "github.com/hamster-shared/a-line/pkg/consts"
- "github.com/hamster-shared/a-line/pkg/parameter"
- "github.com/hamster-shared/a-line/pkg/service"
- "github.com/hamster-shared/a-line/pkg/utils"
- "github.com/hamster-shared/a-line/pkg/vo"
+ "github.com/hamster-shared/hamster-develop/pkg/application"
+ "github.com/hamster-shared/hamster-develop/pkg/consts"
+ "github.com/hamster-shared/hamster-develop/pkg/parameter"
+ "github.com/hamster-shared/hamster-develop/pkg/service"
+ "github.com/hamster-shared/hamster-develop/pkg/utils"
+ "github.com/hamster-shared/hamster-develop/pkg/vo"
uuid "github.com/iris-contrib/go.uuid"
"github.com/jinzhu/copier"
"net/http"
diff --git a/pkg/controller/workflow_handler.go b/pkg/controller/workflow_handler.go
index 96418f7a..e5e63bcf 100644
--- a/pkg/controller/workflow_handler.go
+++ b/pkg/controller/workflow_handler.go
@@ -2,9 +2,9 @@ package controller
import (
"github.com/gin-gonic/gin"
- "github.com/hamster-shared/a-line/engine"
- "github.com/hamster-shared/a-line/pkg/application"
- "github.com/hamster-shared/a-line/pkg/service"
+ engine "github.com/hamster-shared/aline-engine"
+ "github.com/hamster-shared/hamster-develop/pkg/application"
+ "github.com/hamster-shared/hamster-develop/pkg/service"
uuid "github.com/iris-contrib/go.uuid"
"strconv"
)
diff --git a/pkg/db/user_test.go b/pkg/db/user_test.go
index 88a9cfa6..b8ab3121 100644
--- a/pkg/db/user_test.go
+++ b/pkg/db/user_test.go
@@ -2,7 +2,7 @@ package db
import (
"fmt"
- "github.com/hamster-shared/a-line/cmd"
+ "github.com/hamster-shared/hamster-develop/cmd"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/schema"
diff --git a/pkg/parameter/workflow_param.go b/pkg/parameter/workflow_param.go
index 42d01fb2..b03c963e 100644
--- a/pkg/parameter/workflow_param.go
+++ b/pkg/parameter/workflow_param.go
@@ -1,7 +1,7 @@
package parameter
import (
- "github.com/hamster-shared/a-line/pkg/consts"
+ "github.com/hamster-shared/hamster-develop/pkg/consts"
uuid "github.com/iris-contrib/go.uuid"
)
diff --git a/pkg/service/contract.go b/pkg/service/contract.go
index ed443c34..b0a1cd9f 100644
--- a/pkg/service/contract.go
+++ b/pkg/service/contract.go
@@ -4,10 +4,10 @@ import (
"database/sql"
"fmt"
"github.com/goperate/convert/core/array"
- "github.com/hamster-shared/a-line/pkg/application"
- db2 "github.com/hamster-shared/a-line/pkg/db"
- "github.com/hamster-shared/a-line/pkg/utils"
- "github.com/hamster-shared/a-line/pkg/vo"
+ "github.com/hamster-shared/hamster-develop/pkg/application"
+ db2 "github.com/hamster-shared/hamster-develop/pkg/db"
+ "github.com/hamster-shared/hamster-develop/pkg/utils"
+ "github.com/hamster-shared/hamster-develop/pkg/vo"
"github.com/jinzhu/copier"
"gorm.io/gorm"
)
diff --git a/pkg/service/github.go b/pkg/service/github.go
index ca5d03d7..47bc8348 100644
--- a/pkg/service/github.go
+++ b/pkg/service/github.go
@@ -3,7 +3,7 @@ package service
import (
"context"
"github.com/google/go-github/v48/github"
- "github.com/hamster-shared/a-line/pkg/utils"
+ "github.com/hamster-shared/hamster-develop/pkg/utils"
"log"
)
diff --git a/pkg/service/login.go b/pkg/service/login.go
index cf0c7c56..d4146563 100644
--- a/pkg/service/login.go
+++ b/pkg/service/login.go
@@ -3,11 +3,11 @@ package service
import (
"errors"
"fmt"
- "github.com/hamster-shared/a-line/pkg/application"
- "github.com/hamster-shared/a-line/pkg/consts"
- db2 "github.com/hamster-shared/a-line/pkg/db"
- "github.com/hamster-shared/a-line/pkg/parameter"
- "github.com/hamster-shared/a-line/pkg/utils"
+ "github.com/hamster-shared/hamster-develop/pkg/application"
+ "github.com/hamster-shared/hamster-develop/pkg/consts"
+ db2 "github.com/hamster-shared/hamster-develop/pkg/db"
+ "github.com/hamster-shared/hamster-develop/pkg/parameter"
+ "github.com/hamster-shared/hamster-develop/pkg/utils"
"gorm.io/gorm"
"log"
"time"
diff --git a/pkg/service/project.go b/pkg/service/project.go
index 4d6a3946..3934480a 100644
--- a/pkg/service/project.go
+++ b/pkg/service/project.go
@@ -3,9 +3,9 @@ package service
import (
"errors"
"fmt"
- "github.com/hamster-shared/a-line/pkg/consts"
- db2 "github.com/hamster-shared/a-line/pkg/db"
- "github.com/hamster-shared/a-line/pkg/vo"
+ "github.com/hamster-shared/hamster-develop/pkg/consts"
+ db2 "github.com/hamster-shared/hamster-develop/pkg/db"
+ "github.com/hamster-shared/hamster-develop/pkg/vo"
uuid "github.com/iris-contrib/go.uuid"
"github.com/jinzhu/copier"
"gorm.io/gorm"
diff --git a/pkg/service/report.go b/pkg/service/report.go
index 23b9791e..6c9674fc 100644
--- a/pkg/service/report.go
+++ b/pkg/service/report.go
@@ -1,9 +1,9 @@
package service
import (
- "github.com/hamster-shared/a-line/pkg/application"
- db2 "github.com/hamster-shared/a-line/pkg/db"
- "github.com/hamster-shared/a-line/pkg/vo"
+ "github.com/hamster-shared/hamster-develop/pkg/application"
+ db2 "github.com/hamster-shared/hamster-develop/pkg/db"
+ "github.com/hamster-shared/hamster-develop/pkg/vo"
"github.com/jinzhu/copier"
"gorm.io/gorm"
)
diff --git a/pkg/service/template.go b/pkg/service/template.go
index 2d826478..16ca73cd 100644
--- a/pkg/service/template.go
+++ b/pkg/service/template.go
@@ -1,8 +1,8 @@
package service
import (
- db2 "github.com/hamster-shared/a-line/pkg/db"
- "github.com/hamster-shared/a-line/pkg/vo"
+ db2 "github.com/hamster-shared/hamster-develop/pkg/db"
+ "github.com/hamster-shared/hamster-develop/pkg/vo"
"github.com/jinzhu/copier"
"gorm.io/gorm"
)
diff --git a/pkg/service/user.go b/pkg/service/user.go
index 8af9b70c..d2e27dde 100644
--- a/pkg/service/user.go
+++ b/pkg/service/user.go
@@ -1,8 +1,8 @@
package service
import (
- "github.com/hamster-shared/a-line/pkg/application"
- db2 "github.com/hamster-shared/a-line/pkg/db"
+ "github.com/hamster-shared/hamster-develop/pkg/application"
+ db2 "github.com/hamster-shared/hamster-develop/pkg/db"
"gorm.io/gorm"
)
diff --git a/pkg/service/workflow.go b/pkg/service/workflow.go
index 6765ed8d..33bc0351 100644
--- a/pkg/service/workflow.go
+++ b/pkg/service/workflow.go
@@ -6,15 +6,15 @@ import (
"encoding/json"
"errors"
"fmt"
- "github.com/hamster-shared/a-line/engine"
- "github.com/hamster-shared/a-line/engine/logger"
- "github.com/hamster-shared/a-line/engine/model"
- "github.com/hamster-shared/a-line/pkg/application"
- "github.com/hamster-shared/a-line/pkg/consts"
- "github.com/hamster-shared/a-line/pkg/db"
- db2 "github.com/hamster-shared/a-line/pkg/db"
- "github.com/hamster-shared/a-line/pkg/parameter"
- "github.com/hamster-shared/a-line/pkg/vo"
+ engine "github.com/hamster-shared/aline-engine"
+ "github.com/hamster-shared/aline-engine/logger"
+ "github.com/hamster-shared/aline-engine/model"
+ "github.com/hamster-shared/hamster-develop/pkg/application"
+ "github.com/hamster-shared/hamster-develop/pkg/consts"
+ "github.com/hamster-shared/hamster-develop/pkg/db"
+ db2 "github.com/hamster-shared/hamster-develop/pkg/db"
+ "github.com/hamster-shared/hamster-develop/pkg/parameter"
+ "github.com/hamster-shared/hamster-develop/pkg/vo"
uuid "github.com/iris-contrib/go.uuid"
"github.com/jinzhu/copier"
"gopkg.in/yaml.v2"
diff --git a/pkg/utils/cryptography_test.go b/pkg/utils/cryptography_test.go
index 476a974c..6a88883d 100644
--- a/pkg/utils/cryptography_test.go
+++ b/pkg/utils/cryptography_test.go
@@ -1,7 +1,7 @@
package utils
import (
- "github.com/hamster-shared/a-line/pkg/consts"
+ "github.com/hamster-shared/hamster-develop/pkg/consts"
"log"
"testing"
)