Commit e81cdd47 authored by Kamil Trzciński's avatar Kamil Trzciński

Optimize build path to make it shorter, more readable and allowing to fix shebang issue

parent d04a2d46
Pipeline #46504 passed with stage
......@@ -2,6 +2,7 @@ v 0.4.0
- Added CI=true and GITLAB_CI=true to environment variables
- Added output_limit (in kilobytes) to runner config which allows to enlarge default build log size
- Added support for custom variables received from CI
- Optimize build path to make it shorter, more readable and allowing to fix shebang issue
- Make the debug log human readable
- Make default build log limit set to 4096 (4MB)
- Make default concurrent set to 1
......
......@@ -93,11 +93,6 @@ func (b *Build) ProjectUniqueName() string {
b.Runner.ShortDescription(), b.ProjectID, b.ProjectRunnerID)
}
func (b *Build) ProjectUniqueDir() string {
return fmt.Sprintf("%s-%d-%d",
b.Runner.ShortDescription(), b.ProjectID, b.ProjectRunnerID)
}
func (b *Build) ProjectSlug() (string, error) {
url, err := url.Parse(b.RepoURL)
if err != nil {
......@@ -107,8 +102,7 @@ func (b *Build) ProjectSlug() (string, error) {
return "", errors.New("only URI reference supported")
}
host := strings.Split(url.Host, ":")
slug := filepath.Join(host[0], url.Path)
slug := url.Path
slug = strings.TrimSuffix(slug, ".git")
slug = filepath.Clean(slug)
if slug == "." {
......@@ -120,6 +114,25 @@ func (b *Build) ProjectSlug() (string, error) {
return slug, nil
}
func (b *Build) ProjectUniqueDir(sharedDir bool) string {
dir, err := b.ProjectSlug()
if err != nil {
dir = fmt.Sprintf("project-%d", b.ProjectID)
}
// for shared dirs path is constructed like this:
// <some-path>/runner-short-id/concurrent-id/group-name/project-name/
// ex.<some-path>/r01234567/0/group/repo/
if sharedDir {
dir = filepath.Join(
fmt.Sprintf("runner-%s", b.Runner.ShortDescription()),
fmt.Sprintf("%d", b.ProjectRunnerID),
dir,
)
}
return dir
}
func (b *Build) FullProjectDir() string {
return b.BuildDir
}
......
......@@ -154,13 +154,7 @@ func (e *AbstractExecutor) startBuild() error {
// Deduce build directory
buildsDir := helpers.StringOrDefault(e.Config.BuildsDir, e.DefaultBuildsDir)
if e.SharedBuildsDir {
buildsDir = filepath.Join(buildsDir, e.Build.ProjectUniqueDir())
}
if slug, err := e.Build.ProjectSlug(); err == nil {
buildsDir = filepath.Join(buildsDir, slug)
}
buildsDir = filepath.Join(buildsDir, e.Build.ProjectUniqueDir(e.SharedBuildsDir))
// Start actual build
e.Build.StartBuild(buildsDir)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment