예제 #1
0
func auditStepLibBeforeSharePullRequest(gitURI string) error {
	if exist, err := stepman.RootExistForCollection(gitURI); err != nil {
		return err
	} else if !exist {
		return fmt.Errorf("Missing routing for collection, call 'stepman setup -c %s' before audit.", gitURI)
	}

	collection, err := stepman.ReadStepSpec(gitURI)
	if err != nil {
		return err
	}

	for stepID, stepGroup := range collection.Steps {
		log.Debugf("Start audit StepGrup, with ID: (%s)", stepID)
		for version, step := range stepGroup.Versions {
			log.Debugf("Start audit Step (%s) (%s)", stepID, version)
			if err := auditStepModelBeforeSharePullRequest(step, stepID, version); err != nil {
				log.Errorf(" * "+colorstring.Redf("[FAILED] ")+"Failed audit (%s) (%s)", stepID, version)
				return fmt.Errorf("   Error: %s", err.Error())
			}
			log.Infof(" * "+colorstring.Greenf("[OK] ")+"Success audit (%s) (%s)", stepID, version)
		}
	}
	return nil
}
예제 #2
0
// ReadStepInfo ...
func ReadStepInfo(collectionURI, stepID, stepVersionID string, isSetupCollectionIfMissing, isSilentSetup bool) (models.StepVersionModel, error) {
	// Input validation
	if stepID == "" {
		return models.StepVersionModel{}, errors.New("Missing required input: step id")
	}

	// Check if setup was done for collection
	if exist, err := stepman.RootExistForCollection(collectionURI); err != nil {
		return models.StepVersionModel{}, fmt.Errorf("Failed to check if setup was done for steplib (%s), error: %s", collectionURI, err)
	} else if !exist {
		if !isSetupCollectionIfMissing {
			return models.StepVersionModel{}, fmt.Errorf("Collection does not exist (uri: %s), error: %s", collectionURI, err)
		}

		if err := setupSteplib(collectionURI, isSilentSetup); err != nil {
			return models.StepVersionModel{}, errors.New("Failed to setup steplib")
		}
	}

	// Check if step exist in collection
	collection, err := stepman.ReadStepSpec(collectionURI)
	if err != nil {
		return models.StepVersionModel{}, fmt.Errorf("Failed to read steps spec (spec.json), err: %s", err)
	}

	stepWithVersion, stepFound := collection.GetStepVersion(stepID, stepVersionID)
	if !stepFound {
		if stepVersionID == "" {
			return models.StepVersionModel{}, fmt.Errorf("Collection doesn't contain any version of step (id:%s)", stepID)
		}
		return models.StepVersionModel{}, fmt.Errorf("Collection doesn't contain step (id:%s) (version:%s)", stepID, stepVersionID)
	}

	return stepWithVersion, nil
}
예제 #3
0
func listSteps(stepLibURI, format string) error {
	// Check if setup was done for collection
	if exist, err := stepman.RootExistForCollection(stepLibURI); err != nil {
		return err
	} else if !exist {
		if err := setupSteplib(stepLibURI, format != OutputFormatRaw); err != nil {
			log.Fatal("Failed to setup steplib")
		}
	}

	stepLib, err := stepman.ReadStepSpec(stepLibURI)
	if err != nil {
		return err
	}

	switch format {
	case OutputFormatRaw:
		printRawStepList(stepLibURI, stepLib, false)
		break
	case OutputFormatJSON:
		if err := printJSONStepList(stepLibURI, stepLib, false); err != nil {
			return err
		}
		break
	default:
		return fmt.Errorf("Invalid format: %s", format)
	}
	return nil
}
예제 #4
0
파일: step_info.go 프로젝트: godrei/stepman
func stepInfo(c *cli.Context) error {
	// Input validation
	format := c.String(FormatKey)
	collectionURI := c.String(CollectionKey)
	YMLPath := c.String(StepYMLKey)
	isShort := c.Bool(ShortKey)
	id := c.String(IDKey)
	version := c.String(VersionKey)

	if format == "" {
		format = OutputFormatRaw
	} else if !(format == OutputFormatRaw || format == OutputFormatJSON) {
		return fmt.Errorf("Invalid output format: %s", format)
	}

	if YMLPath == "" && collectionURI == "" {
		return fmt.Errorf("Missing required input: no StepLib, nor step.yml path defined as step info source")
	}

	if YMLPath != "" {
		//
		// Local step info
		step, err := stepman.ParseStepYml(YMLPath, false)
		if err != nil {
			return fmt.Errorf("Failed to parse step.yml (path:%s), err: %s", YMLPath, err)
		}

		inputs, err := getEnvInfos(step.Inputs)
		if err != nil {
			return fmt.Errorf("Failed to get step (path:%s) input infos, err: %s", YMLPath, err)
		}

		outputs, err := getEnvInfos(step.Outputs)
		if err != nil {
			return fmt.Errorf("Failed to get step (path:%s) output infos, err: %s", YMLPath, err)
		}

		stepInfo := models.StepInfoModel{
			StepLib:     YMLPath,
			Description: *step.Description,
			Source:      *step.SourceCodeURL,
			Inputs:      inputs,
			Outputs:     outputs,
		}

		if err := printStepInfo(stepInfo, format, isShort, true); err != nil {
			return fmt.Errorf("Failed to print step info, err: %s", err)
		}
	} else {
		//
		// StepLib step info

		// Input validation
		if id == "" {
			return errors.New("Missing required input: step id")
		}

		// Check if setup was done for collection
		if exist, err := stepman.RootExistForCollection(collectionURI); err != nil {
			return fmt.Errorf("Failed to check if setup was done for steplib (%s), error: %s", collectionURI, err)
		} else if !exist {
			if err := setupSteplib(collectionURI, format != OutputFormatRaw); err != nil {
				return errors.New("Failed to setup steplib")
			}
		}

		// Check if step exist in collection
		collection, err := stepman.ReadStepSpec(collectionURI)
		if err != nil {
			return fmt.Errorf("Failed to read steps spec (spec.json), err: %s", err)
		}

		step, stepFound := collection.GetStep(id, version)
		if !stepFound {
			if version == "" {
				return fmt.Errorf("Collection doesn't contain any version of step (id:%s)", id)
			}
			return fmt.Errorf("Collection doesn't contain step (id:%s) (version:%s)", id, version)
		}

		latest, err := collection.GetLatestStepVersion(id)
		if err != nil {
			return fmt.Errorf("Failed to get latest version of step (id:%s)", id)
		}

		if version == "" {
			version = latest
		}

		inputs, err := getEnvInfos(step.Inputs)
		if err != nil {
			return fmt.Errorf("Failed to get step (id:%s) input infos, err: %s", id, err)
		}

		outputs, err := getEnvInfos(step.Outputs)
		if err != nil {
			return fmt.Errorf("Failed to get step (id:%s) output infos, err: %s", id, err)
		}

		stepInfo := models.StepInfoModel{
			ID:          id,
			Version:     version,
			Latest:      latest,
			Description: *step.Description,
			StepLib:     collectionURI,
			Source:      *step.SourceCodeURL,
			Inputs:      inputs,
			Outputs:     outputs,
		}

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

			if found {
				stepInfo.GlobalInfo = globalInfo
			}
		}

		if err := printStepInfo(stepInfo, format, isShort, false); err != nil {
			return fmt.Errorf("Failed to print step info, err: %s", err)
		}
	}

	return nil
}
예제 #5
0
func setupSteplib(steplibURI string, silent bool) error {
	logger := output.NewLogger(silent)

	if exist, err := stepman.RootExistForCollection(steplibURI); err != nil {
		return fmt.Errorf("Failed to check if routing exist for steplib (%s), error: %s", steplibURI, err)
	} else if exist {

		logger.Debugf("Steplib (%s) already initialized, ready to use", steplibURI)
		return nil
	}

	alias := stepman.GenerateFolderAlias()
	route := stepman.SteplibRoute{
		SteplibURI:  steplibURI,
		FolderAlias: alias,
	}

	// Cleanup
	isSuccess := false
	defer func() {
		if !isSuccess {
			if err := stepman.CleanupRoute(route); err != nil {
				logger.Errorf("Failed to cleanup routing for steplib (%s), error: %s", steplibURI, err)
			}
		}
	}()

	// Setup
	isLocalSteplib := strings.HasPrefix(steplibURI, "file://")

	pth := stepman.GetCollectionBaseDirPath(route)
	if !isLocalSteplib {
		if out, err := gitClone(steplibURI, pth); err != nil {
			return fmt.Errorf("Failed to setup steplib (%s), output: %s, error: %s", steplibURI, out, err)
		}
	} else {
		// Local spec path
		logger.Warn("Using local steplib")
		logger.Infof("Creating steplib dir: %s", pth)

		if err := os.MkdirAll(pth, 0777); err != nil {
			return fmt.Errorf("Failed to create steplib dir (%s), error: %s", pth, err)
		}

		logger.Info("Collection dir created - OK")
		if err := cmdex.CopyDir(steplibURI, pth, true); err != nil {
			return fmt.Errorf("Failed to setup local step spec:", err)
		}
	}

	if err := stepman.ReGenerateStepSpec(route); err != nil {
		return fmt.Errorf("Failed to re-generate steplib (%s), error: %s", steplibURI, err)
	}

	if err := stepman.AddRoute(route); err != nil {
		return fmt.Errorf("Failed to setup routing: %s", err)
	}

	isSuccess = true

	return nil
}
예제 #6
0
파일: export.go 프로젝트: godrei/stepman
func export(c *cli.Context) error {
	// Input validation
	steplibURI := c.String("steplib")
	outputPth := c.String("output")
	exportTypeStr := c.String("export-type")

	if steplibURI == "" {
		return fmt.Errorf("Missing required input: steplib")
	}

	if outputPth == "" {
		return fmt.Errorf("Missing required input: output")
	}

	exportType := exportTypeFull
	if exportTypeStr != "" {
		var err error
		exportType, err = parseExportType(exportTypeStr)
		if err != nil {
			return err
		}
	}

	log.Infof("Exporting StepLib (%s) spec, export-type: %s, output: %s", steplibURI, exportTypeStr, outputPth)

	// Setup StepLib
	if exist, err := stepman.RootExistForCollection(steplibURI); err != nil {
		return fmt.Errorf("Failed to check if setup was done for StepLib, error: %s", err)
	} else if !exist {
		log.Infof("StepLib does not exist, setup...")
		if err := setupSteplib(steplibURI, false); err != nil {
			return fmt.Errorf("Failed to setup StepLib, error: %s", err)
		}
	}

	// Prepare spec
	stepLibSpec, err := stepman.ReadStepSpec(steplibURI)
	if err != nil {
		log.Fatalln("Failed to read StepLib spec, error: %s", err)
	}

	switch exportType {
	case exportTypeMinimal:
		stepLibSpec = convertToMinimalSpec(stepLibSpec)
	case exportTypeLatest:
		stepLibSpec = convertToLatestSpec(stepLibSpec)
	}

	stepLibSpecBytes, err := json.Marshal(stepLibSpec)
	if err != nil {
		return fmt.Errorf("Failed to marshal StepLib, error: %s", err)
	}

	// Export spec
	outputDir := filepath.Dir(outputPth)

	exist, err := pathutil.IsDirExists(outputDir)
	if err != nil {
		return fmt.Errorf("Failed to check if dir (%s) exist, error: %s", outputDir, err)
	}
	if !exist {
		if err := os.MkdirAll(outputDir, 0777); err != nil {
			return fmt.Errorf("Failed to create dir (%s), error: %s", outputDir, err)
		}
	}

	if err := fileutil.WriteBytesToFile(outputPth, stepLibSpecBytes); err != nil {
		return fmt.Errorf("Failed to write StepLib spec to: %s, error: %s", outputPth, err)
	}

	log.Infof("StepLib spec exported to: %s", outputPth)

	return nil
}