grim/convey

Bump the version for release
v0.14.0-alpha3
2018-02-20, Gary Kramlich
166a6d1979fa
Bump the version for release
// Convey
// Copyright 2016-2018 Gary Kramlich <grim@reaperworld.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package convey
import (
"fmt"
"strings"
"github.com/aphistic/gomol"
"github.com/go-yaml/yaml"
cConfig "bitbucket.org/rw_grim/convey/config"
"bitbucket.org/rw_grim/convey/tasks"
)
func loadLegacyTask(rawEngine, rawType string, logger *gomol.LogAdapter) (tasks.Task, error) {
legacyEngine := "docker"
// there are only two intrinsic tasks, so check them first
if rawType == "clean" || rawType == "extend" {
legacyEngine = "convey"
}
// figure out the engine
if rawEngine != "" {
msg := "the engine attribute is deprecated and will be removed in a future version. Please update to the new type format as this format will be removed in a future version."
if err := logger.Warn(msg); err != nil {
fmt.Printf("error reporting warning: %s\n", err)
}
if rawEngine == "intrinsic" {
msg := "the intrinsic engine is deprecated, using convey instead"
if err := logger.Warn(msg); err != nil {
fmt.Printf("error reporting warning: %s\n", err)
}
rawEngine = "convey"
}
legacyEngine = rawEngine
}
// figure out the type
legacyType := "run"
if rawType != "" {
legacyType = rawType
}
typeName := fmt.Sprintf("%s/%s", legacyEngine, legacyType)
msgFmt := "converted deprecated task format {engine: '%s', type: '%s'} to type %s. Please update to the new type format as this format will be removed in a future version."
if err := logger.Warnf(msgFmt, rawEngine, rawType, typeName); err != nil {
fmt.Printf("error reporting warning: %s\n", err)
}
task, ok := cConfig.TasksMap[typeName]
if !ok {
return nil, fmt.Errorf(
"failed to find task with engine '%s' and type '%s'",
rawEngine,
rawType,
)
}
return task, nil
}
func loadTask(name string, yamlTask yaml.MapSlice, logger *gomol.LogAdapter, disableDeprecated bool) (tasks.Task, error) {
// figure out the engine and type for the task
var (
rawEngine string
rawType string
)
// task is a yaml.MapSlice since we can't unmarshal it into the proper data
// structure right away, so we have to walk it and grab the attributes
// we're interested in.
for _, item := range yamlTask {
switch item.Key.(string) {
case "engine":
rawEngine = item.Value.(string)
case "type":
rawType = item.Value.(string)
}
}
task, ok := cConfig.TasksMap[rawType]
// if the task isn't in the new format try to lookup the old format
if !ok {
// TODO remove when the old format for task types is removed.
// if deprecated tasks are disabled, just bomb out
if disableDeprecated || strings.ContainsRune(rawType, '/') {
return nil, fmt.Errorf("task '%s' not found", rawType)
}
rawTask, err := loadLegacyTask(rawEngine, rawType, logger)
if err != nil {
return nil, err
}
task = rawTask
}
realTask, err := tasks.CloneTask(yamlTask, task)
if err != nil {
return nil, err
}
err = realTask.Valid()
if err != nil {
return nil, fmt.Errorf("%s: %s", name, err.Error())
}
return realTask, nil
}
func loadTasks(path string, raw map[string]yaml.MapSlice, logger *gomol.LogAdapter, disableDeprecated bool) (map[string]tasks.Task, error) {
realTasks := map[string]tasks.Task{}
for name, task := range raw {
realTask, err := loadTask(name, task, logger, disableDeprecated)
if err != nil {
return nil, err
}
realTasks[name] = realTask
}
return realTasks, nil
}