Skip to content

Commit

Permalink
feat(app-run): polish handlerPipelineYmlName logic, support ./ prefix (
Browse files Browse the repository at this point in the history
…#49)

* update erda-project/erda deps to latest

* polish handlerPipelineYmlName logic, support ./ prefix

* update base image

* update image in dice.yml
  • Loading branch information
sfwn authored Jul 23, 2024
1 parent 7c04b76 commit 44f8500
Show file tree
Hide file tree
Showing 6 changed files with 2,044 additions and 418 deletions.
2 changes: 1 addition & 1 deletion actions/app-run/1.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$TARGETPLATFORM registry.erda.cloud/erda/terminus-golang:1.17.12 AS builder
FROM --platform=$TARGETPLATFORM registry.erda.cloud/retag/golang:1.22-bookworm AS builder

COPY . /go/src/github.com/erda-project/erda-actions
WORKDIR /go/src/github.com/erda-project/erda-actions
Expand Down
2 changes: 1 addition & 1 deletion actions/app-run/1.0/dice.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
### job 配置项
jobs:
api-run:
image: registry.erda.cloud/erda-actions/app-run-action:1.0-20220606213931-ef81cb1
image: registry.erda.cloud/erda-actions/app-run-action:1.0-20240723154012-e87ca79
resources:
cpu: 0.5
mem: 1024
20 changes: 13 additions & 7 deletions actions/app-run/1.0/internal/appRun/appRun.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ import (
"github.com/erda-project/erda/pkg/strutil"
)

const (
erdaPipelinesPrefix = ".erda/pipelines/"
dicePipelinesPrefix = ".dice/pipelines/"
)

func handlerPipelineYmlName(ymlName string) string {
if strings.HasPrefix(ymlName, ".erda/pipelines") {
return ymlName
}
ymlName = strings.TrimPrefix(ymlName, "./")

if strings.HasPrefix(ymlName, ".dice/pipelines") {
if strutil.HasPrefixes(ymlName, erdaPipelinesPrefix, dicePipelinesPrefix) {
return ymlName
}

if ymlName == "pipeline.yml" {
return ymlName
}

return ".dice/pipelines/" + ymlName
return dicePipelinesPrefix + ymlName
}

func handleAPIs() error {
Expand All @@ -57,14 +60,17 @@ func handleAPIs() error {

logrus.Infof("start run pipeline %s", conf.ActionPipelineYmlName())
// start pipeline
pipelineDTO, err := startPipeline(apistructs.PipelineCreateRequest{
req := apistructs.PipelineCreateRequest{
AppID: existApp.ID,
Branch: conf.ActionBranch(),
PipelineYmlSource: apistructs.PipelineYmlSourceGittar,
PipelineYmlName: handlerPipelineYmlName(conf.ActionPipelineYmlName()),
Source: apistructs.PipelineSourceDice,
AutoRun: true,
})
}
b, _ := json.Marshal(&req)
logrus.Infof("req: %s", string(b))
pipelineDTO, err := startPipeline(req)
if err != nil {
return err
}
Expand Down
7 changes: 7 additions & 0 deletions actions/app-run/1.0/internal/appRun/appRun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ func Test_handlerPipelineYmlName(t *testing.T) {
},
want: "pipeline.yml",
},
{
name: "test ./.erda/pipelines/aa.yml",
args: args{
ymlName: "./.erda/pipelines/aa.yml",
},
want: ".erda/pipelines/aa.yml",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
Loading

0 comments on commit 44f8500

Please sign in to comment.