fix(api): resolve release workflow paths relative to project

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-01 19:24:30 +00:00
parent 0625288a73
commit 39adee8bbb
2 changed files with 27 additions and 0 deletions

View file

@ -8,6 +8,7 @@ package api
import (
"io/fs"
"net/http"
"path/filepath"
"dappco.re/go/core/api"
"dappco.re/go/core/api/pkg/provider"
@ -531,6 +532,8 @@ func (p *BuildProvider) generateReleaseWorkflow(c *gin.Context) {
path := req.Path
if path == "" {
path = build.ReleaseWorkflowPath(dir)
} else if !filepath.IsAbs(path) {
path = ax.Join(dir, path)
}
if err := build.WriteReleaseWorkflow(p.medium, path); err != nil {

View file

@ -182,3 +182,27 @@ func TestProvider_GenerateReleaseWorkflow_Good(t *testing.T) {
assert.Contains(t, content, "workflow_call:")
assert.Contains(t, content, "workflow_dispatch:")
}
func TestProvider_GenerateReleaseWorkflow_CustomPath_Good(t *testing.T) {
gin.SetMode(gin.TestMode)
projectDir := t.TempDir()
p := NewProvider(projectDir, nil)
recorder := httptest.NewRecorder()
request := httptest.NewRequest(http.MethodPost, "/release/workflow", bytes.NewBufferString(`{"path":"ci/release.yml"}`))
request.Header.Set("Content-Type", "application/json")
ctx, _ := gin.CreateTestContext(recorder)
ctx.Request = request
p.generateReleaseWorkflow(ctx)
assert.Equal(t, http.StatusOK, recorder.Code)
path := ax.Join(projectDir, "ci", "release.yml")
content, err := io.Local.Read(path)
require.NoError(t, err)
assert.Contains(t, content, "workflow_call:")
assert.Contains(t, content, "workflow_dispatch:")
}