grim/convey

Add a .reviewboardrc file

2022-03-26, Gary Kramlich
8fea0c778f8e
Add a .reviewboardrc file
// Convey
// Copyright 2016-2021 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 runner
import (
"context"
"fmt"
"os"
"os/signal"
"path/filepath"
"syscall"
"time"
log "github.com/sirupsen/logrus"
"keep.imfreedom.org/grim/convey/config"
"keep.imfreedom.org/grim/convey/globals"
"keep.imfreedom.org/grim/convey/logging"
"keep.imfreedom.org/grim/convey/runtime"
)
type RunnerCmd struct {
ConfigFile string `kong:"flag,help='The config file to load',placeholder='FILE',short='f',default='convey.yml',name='config'"`
CpuShares string `kong:"flag,help='The amount of cpu shares given to run tasks',placeholder='CPU-SHARES',short='c'"`
ForceSequential bool `kong:"flag,help='Force concurrent stages to be ran sequentially',short='S',default='false'"`
KeepWorkspace bool `kong:"flag,help='Keep the workspace directory after running',default='false'"`
Memory string `kong:"flag,help='The amount of memory shares given to run tasks',placeholder='MEMORY',short='m'"`
Timeout time.Duration `kong:"flag,help='The maximum amount of time a plan can run. 0 to disable. Units must be specified.',placeholder='DURATION',default='15m'"`
Environment []string `kong:"flag,name='env',help='Set an environment variable',short='e',placeholder='ENV'"`
Plans []string `kong:"arg,help='The names of the plans to run',default='default'"`
}
func (c *RunnerCmd) loadConfig() (string, *config.Config, error) {
cfg, err := config.LoadFile(c.ConfigFile)
if err != nil {
return "", nil, err
}
err = cfg.Valid()
if err != nil {
return "", nil, fmt.Errorf("config is invalid: %s", err)
}
err = cfg.HasPlans(c.Plans)
if err != nil {
return "", nil, err
}
configPath, _ := filepath.Split(c.ConfigFile)
if configPath == "" {
cwd, err := os.Getwd()
if err != nil {
return "", nil, err
}
configPath = cwd
}
return configPath, cfg, nil
}
func (c *RunnerCmd) Run(g *globals.Globals) error {
logging.Setup(g.Color, g.Verbose)
configPath, cfg, err := c.loadConfig()
if err != nil {
return err
}
rt := c.Runtime(configPath, cfg)
defer rt.Shutdown()
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
errChan := make(chan error, 1)
ctx, cancel := context.WithCancel(context.Background())
go func(ctx context.Context, cfg *config.Config) {
metaplan := &runtime.MetaPlan{
Plans: c.Plans,
}
errChan <- metaplan.Execute(ctx, rt)
}(ctx, cfg)
for {
select {
case err := <-errChan:
return err
case s := <-signalChan:
log.Infof("caught signal %s, exiting...", s)
cancel()
break
}
}
return nil
}