Skip to content

Commit

Permalink
global step info handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Krisztián Gödrei committed Dec 16, 2015
1 parent ff863dd commit aa88983
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 21 deletions.
58 changes: 48 additions & 10 deletions cli/step_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"encoding/json"
"fmt"
"path"

log "github.com/Sirupsen/logrus"
envmanModels "github.com/bitrise-io/envman/models"
Expand Down Expand Up @@ -66,6 +67,16 @@ func printRawStepInfo(stepInfo models.StepInfoModel, isShort, isLocal bool) {
fmt.Println(colorstring.Bluef("Step info in StepLib (%s):", stepInfo.StepLib))
}

if stepInfo.GlobalInfo.RemovalDate != "" {
fmt.Println("")
fmt.Printf(colorstring.Red("This step is deprecated!\n"))
fmt.Printf("%s %s\n", colorstring.Red("removal date:"), stepInfo.GlobalInfo.RemovalDate)

if stepInfo.GlobalInfo.DeprecateNotes != "" {
fmt.Printf("%s\n%s\n", colorstring.Red("deprecate notes:"), stepInfo.GlobalInfo.DeprecateNotes)
}
}

if stepInfo.ID != "" {
fmt.Printf("%s: %s\n", colorstring.Blue("ID"), stepInfo.ID)
}
Expand Down Expand Up @@ -125,7 +136,7 @@ func printStepInfo(stepInfo models.StepInfoModel, format string, isShort, isLoca
}
break
default:
return fmt.Errorf("[STEPMAN] - Invalid format: %s", format)
return fmt.Errorf("Invalid format: %s", format)
}
return nil
}
Expand All @@ -152,12 +163,12 @@ func stepInfo(c *cli.Context) {

inputs, err := getEnvInfos(step.Inputs)
if err != nil {
log.Fatalf("[STEPMAN] - Failed to get step (path:%s) input infos, err: %s", YMLPath, err)
log.Fatalf("Failed to get step (path:%s) input infos, err: %s", YMLPath, err)
}

outputs, err := getEnvInfos(step.Outputs)
if err != nil {
log.Fatalf("[STEPMAN] - Failed to get step (path:%s) output infos, err: %s", YMLPath, err)
log.Fatalf("Failed to get step (path:%s) output infos, err: %s", YMLPath, err)
}

stepInfo := models.StepInfoModel{
Expand All @@ -168,6 +179,17 @@ func stepInfo(c *cli.Context) {
Outputs: outputs,
}

dir := path.Dir(YMLPath)
globalStepInfoPth := path.Join(dir, "step-info.yml")
globalInfo, found, err := stepman.ParseGlobalStepInfoYML(globalStepInfoPth)
if err != nil {
log.Fatalf("Failed to get step (path:%s) output infos, err: %s", YMLPath, err)
}

if found {
stepInfo.GlobalInfo = globalInfo
}

if err := printStepInfo(stepInfo, format, isShort, true); err != nil {
log.Fatalf("Failed to print step info, err: %s", err)
}
Expand All @@ -186,7 +208,7 @@ func stepInfo(c *cli.Context) {

id := c.String(IDKey)
if id == "" {
log.Fatal("[STEPMAN] - Missing step id")
log.Fatal("Missing step id")
}

version := c.String(VersionKey)
Expand All @@ -195,21 +217,21 @@ func stepInfo(c *cli.Context) {
// Check if step exist in collection
collection, err := stepman.ReadStepSpec(collectionURI)
if err != nil {
log.Fatalf("[STEPMAN] - Failed to read steps spec (spec.json), err: %s", err)
log.Fatalf("Failed to read steps spec (spec.json), err: %s", err)
}

step, stepFound := collection.GetStep(id, version)
if !stepFound {
if version == "" {
log.Fatalf("[STEPMAN] - Collection doesn't contain any version of step (id:%s)", id)
log.Fatalf("Collection doesn't contain any version of step (id:%s)", id)
} else {
log.Fatalf("[STEPMAN] - Collection doesn't contain step (id:%s) (version:%s)", id, version)
log.Fatalf("Collection doesn't contain step (id:%s) (version:%s)", id, version)
}
}

latest, err := collection.GetLatestStepVersion(id)
if err != nil {
log.Fatalf("[STEPMAN] - Failed to get latest version of step (id:%s)", id)
log.Fatalf("Failed to get latest version of step (id:%s)", id)
}

if version == "" {
Expand All @@ -218,12 +240,12 @@ func stepInfo(c *cli.Context) {

inputs, err := getEnvInfos(step.Inputs)
if err != nil {
log.Fatalf("[STEPMAN] - Failed to get step (id:%s) input infos, err: %s", id, err)
log.Fatalf("Failed to get step (id:%s) input infos, err: %s", id, err)
}

outputs, err := getEnvInfos(step.Outputs)
if err != nil {
log.Fatalf("[STEPMAN] - Failed to get step (id:%s) output infos, err: %s", id, err)
log.Fatalf("Failed to get step (id:%s) output infos, err: %s", id, err)
}

stepInfo := models.StepInfoModel{
Expand All @@ -237,6 +259,22 @@ func stepInfo(c *cli.Context) {
Outputs: outputs,
}

route, found := stepman.ReadRoute(collectionURI)
if !found {
log.Fatalf("No route found for collection: %s", collectionURI)
}
globalStepInfoPth := stepman.GetStepGlobalInfoPath(route, id)
if globalStepInfoPth != "" {
globalInfo, found, err := stepman.ParseGlobalStepInfoYML(globalStepInfoPth)
if err != nil {
log.Fatalf("Failed to get step (path:%s) output infos, err: %s", YMLPath, err)
}

if found {
stepInfo.GlobalInfo = globalInfo
}
}

if err := printStepInfo(stepInfo, format, isShort, false); err != nil {
log.Fatalf("Failed to print step info, err: %s", err)
}
Expand Down
29 changes: 18 additions & 11 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import (
envmanModels "github.com/bitrise-io/envman/models"
)

// GlobalStepInfoModel ...
type GlobalStepInfoModel struct {
RemovalDate string `json:"removal_date,omitempty" yaml:"removal_date,omitempty"`
DeprecateNotes string `json:"deprecate_notes,omitempty" yaml:"deprecate_notes,omitempty"`
}

// StepSourceModel ...
type StepSourceModel struct {
Git string `json:"git,omitempty" yaml:"git,omitempty"`
Expand Down Expand Up @@ -111,17 +117,18 @@ type EnvInfoModel struct {

// StepInfoModel ...
type StepInfoModel struct {
ID string `json:"step_id,omitempty" yaml:"step_id,omitempty"`
Title string `json:"step_title,omitempty" yaml:"step_title,omitempty"`
Version string `json:"step_version,omitempty" yaml:"step_version,omitempty"`
Latest string `json:"latest_version,omitempty" yaml:"latest_version,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Source string `json:"source,omitempty" yaml:"source,omitempty"`
StepLib string `json:"steplib,omitempty" yaml:"steplib,omitempty"`
SupportURL string `json:"support_url,omitempty" yaml:"support_url,omitempty"`
SourceCodeURL string `json:"source_code_url,omitempty" yaml:"source_code_url,omitempty"`
Inputs []EnvInfoModel `json:"inputs,omitempty" yaml:"inputs,omitempty"`
Outputs []EnvInfoModel `json:"outputs,omitempty" yaml:"outputs,omitempty"`
ID string `json:"step_id,omitempty" yaml:"step_id,omitempty"`
Title string `json:"step_title,omitempty" yaml:"step_title,omitempty"`
Version string `json:"step_version,omitempty" yaml:"step_version,omitempty"`
Latest string `json:"latest_version,omitempty" yaml:"latest_version,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Source string `json:"source,omitempty" yaml:"source,omitempty"`
StepLib string `json:"steplib,omitempty" yaml:"steplib,omitempty"`
SupportURL string `json:"support_url,omitempty" yaml:"support_url,omitempty"`
SourceCodeURL string `json:"source_code_url,omitempty" yaml:"source_code_url,omitempty"`
Inputs []EnvInfoModel `json:"inputs,omitempty" yaml:"inputs,omitempty"`
Outputs []EnvInfoModel `json:"outputs,omitempty" yaml:"outputs,omitempty"`
GlobalInfo GlobalStepInfoModel `json:"global_info,omitempty" yaml:"global_info,omitempty"`
}

// StepListModel ...
Expand Down
5 changes: 5 additions & 0 deletions stepman/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ func GetStepCacheDirPath(route SteplibRoute, id, version string) string {
return path.Join(GetCacheBaseDir(route), id, version)
}

// GetStepGlobalInfoPath ...
func GetStepGlobalInfoPath(route SteplibRoute, id string) string {
return path.Join(GetCollectionBaseDirPath(route), "steps", id, "step-info.yml")
}

// GetStepCollectionDirPath ...
// Step's Collection dir path, where it's spec (step.yml) lives.
func GetStepCollectionDirPath(route SteplibRoute, id, version string) string {
Expand Down
21 changes: 21 additions & 0 deletions stepman/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ import (
// DebugMode ...
var DebugMode bool

// ParseGlobalStepInfoYML ...
func ParseGlobalStepInfoYML(pth string) (models.GlobalStepInfoModel, bool, error) {
if exist, err := pathutil.IsPathExists(pth); err != nil {
return models.GlobalStepInfoModel{}, false, err
} else if !exist {
return models.GlobalStepInfoModel{}, false, nil
}

bytes, err := fileutil.ReadBytesFromFile(pth)
if err != nil {
return models.GlobalStepInfoModel{}, true, err
}

var globalStepInfo models.GlobalStepInfoModel
if err := yaml.Unmarshal(bytes, &globalStepInfo); err != nil {
return models.GlobalStepInfoModel{}, true, err
}

return globalStepInfo, true, nil
}

// ParseStepYml ...
func ParseStepYml(pth string, validate bool) (models.StepModel, error) {
bytes, err := fileutil.ReadBytesFromFile(pth)
Expand Down

0 comments on commit aa88983

Please sign in to comment.