This repository has been archived by the owner on Aug 9, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
605 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package engine | ||
|
||
import ( | ||
"capsulecd/pkg/scm" | ||
"capsulecd/pkg/pipeline" | ||
"capsulecd/pkg/config" | ||
"capsulecd/pkg/utils" | ||
"path" | ||
"capsulecd/pkg/errors" | ||
"fmt" | ||
"io/ioutil" | ||
"strings" | ||
) | ||
|
||
type genericMetadata struct { | ||
Version string | ||
} | ||
type engineGeneric struct { | ||
engineBase | ||
|
||
Scm scm.Interface //Interface | ||
CurrentMetadata *genericMetadata | ||
NextMetadata *genericMetadata | ||
} | ||
|
||
func (g *engineGeneric) Init(pipelineData *pipeline.Data, config config.Interface, sourceScm scm.Interface) error { | ||
g.Scm = sourceScm | ||
g.Config = config | ||
g.PipelineData = pipelineData | ||
g.CurrentMetadata = new(genericMetadata) | ||
g.NextMetadata = new(genericMetadata) | ||
|
||
//set command defaults (can be overridden by repo/system configuration) | ||
g.Config.SetDefault("engine_generic_version_path", "VERSION") | ||
g.Config.SetDefault("engine_cmd_compile", "echo 'skipping compile'") | ||
g.Config.SetDefault("engine_cmd_lint", "echo 'skipping lint'") | ||
g.Config.SetDefault("engine_cmd_fmt", "echo 'skipping fmt'") | ||
g.Config.SetDefault("engine_cmd_test", "echo 'skipping test'") | ||
g.Config.SetDefault("engine_cmd_security_check", "echo 'skipping security check'") | ||
return nil | ||
} | ||
|
||
func (g *engineGeneric) ValidateTools() error { | ||
return nil | ||
} | ||
|
||
func (g *engineGeneric) AssembleStep() error { | ||
//validate that the chef metadata.rb file exists | ||
|
||
if !utils.FileExists(path.Join(g.PipelineData.GitLocalPath, g.Config.GetString("engine_generic_version_path"))) { | ||
return errors.EngineBuildPackageInvalid(fmt.Sprintf("version file (%s) is required for metadata storage via generic engine", g.Config.GetString("engine_generic_version_path"))) | ||
} | ||
|
||
// bump up the go package version | ||
if merr := g.retrieveCurrentMetadata(g.PipelineData.GitLocalPath); merr != nil { | ||
return merr | ||
} | ||
|
||
if perr := g.populateNextMetadata(); perr != nil { | ||
return perr | ||
} | ||
|
||
if nerr := g.writeNextMetadata(g.PipelineData.GitLocalPath); nerr != nil { | ||
return nerr | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (g *engineGeneric) DependenciesStep() error { | ||
return nil | ||
} | ||
|
||
func (g *engineGeneric) PackageStep() error { | ||
|
||
if cerr := utils.GitCommit(g.PipelineData.GitLocalPath, fmt.Sprintf("(v%s) Automated packaging of release by CapsuleCD", g.NextMetadata.Version)); cerr != nil { | ||
return cerr | ||
} | ||
tagCommit, terr := utils.GitTag(g.PipelineData.GitLocalPath, fmt.Sprintf("v%s", g.NextMetadata.Version)) | ||
if terr != nil { | ||
return terr | ||
} | ||
|
||
g.PipelineData.ReleaseCommit = tagCommit | ||
g.PipelineData.ReleaseVersion = g.NextMetadata.Version | ||
return nil | ||
} | ||
|
||
func (g *engineGeneric) DistStep() error { | ||
return nil | ||
} | ||
|
||
//Helpers | ||
func (g *engineGeneric) retrieveCurrentMetadata(gitLocalPath string) error { | ||
//read VERSION file. | ||
versionContent, rerr := ioutil.ReadFile(path.Join(gitLocalPath, g.Config.GetString("engine_generic_version_path"))) | ||
if rerr != nil { | ||
return rerr | ||
} | ||
g.CurrentMetadata.Version = strings.TrimSpace(string(versionContent)) | ||
return nil | ||
} | ||
|
||
func (g *engineGeneric) populateNextMetadata() error { | ||
|
||
nextVersion, err := g.BumpVersion(g.CurrentMetadata.Version) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
g.NextMetadata.Version = nextVersion | ||
return nil | ||
} | ||
|
||
func (g *engineGeneric) writeNextMetadata(gitLocalPath string) error { | ||
return ioutil.WriteFile(path.Join(gitLocalPath, g.Config.GetString("engine_generic_version_path")), []byte(g.NextMetadata.Version), 0644) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.