2020-11-25 19:44:45 +00:00
|
|
|
// Copyright (c) 2020, the Drone Plugins project authors.
|
2021-09-13 21:00:00 +00:00
|
|
|
// Copyright (c) 2021, Robert Kaussow <mail@thegeeklab.de>
|
|
|
|
|
2020-11-25 19:44:45 +00:00
|
|
|
// Use of this source code is governed by an Apache 2.0 license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-04-25 10:55:06 +00:00
|
|
|
"fmt"
|
2020-11-25 19:44:45 +00:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/drone-plugins/drone-matrix/plugin"
|
|
|
|
"github.com/joho/godotenv"
|
2022-05-03 20:48:17 +00:00
|
|
|
"github.com/thegeeklab/drone-plugin-lib/errors"
|
|
|
|
"github.com/thegeeklab/drone-plugin-lib/urfave"
|
2020-11-25 19:44:45 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
2022-04-25 10:55:06 +00:00
|
|
|
var (
|
|
|
|
BuildVersion = "devel"
|
|
|
|
BuildDate = "00000000"
|
|
|
|
)
|
2020-11-25 19:44:45 +00:00
|
|
|
|
|
|
|
func main() {
|
|
|
|
settings := &plugin.Settings{}
|
|
|
|
|
|
|
|
if _, err := os.Stat("/run/drone/env"); err == nil {
|
2022-04-25 10:55:06 +00:00
|
|
|
_ = godotenv.Overload("/run/drone/env")
|
|
|
|
}
|
|
|
|
|
|
|
|
cli.VersionPrinter = func(c *cli.Context) {
|
|
|
|
fmt.Printf("%s version=%s date=%s\n", c.App.Name, c.App.Version, BuildDate)
|
2020-11-25 19:44:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app := &cli.App{
|
|
|
|
Name: "drone-matrix",
|
|
|
|
Usage: "build notifications for matrix",
|
2022-04-25 10:55:06 +00:00
|
|
|
Version: BuildVersion,
|
2020-11-25 19:44:45 +00:00
|
|
|
Flags: append(settingsFlags(settings), urfave.Flags()...),
|
|
|
|
Action: run(settings),
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
errors.HandleExit(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func run(settings *plugin.Settings) cli.ActionFunc {
|
|
|
|
return func(ctx *cli.Context) error {
|
|
|
|
urfave.LoggingFromContext(ctx)
|
|
|
|
|
|
|
|
plugin := plugin.New(
|
|
|
|
*settings,
|
|
|
|
urfave.PipelineFromContext(ctx),
|
|
|
|
urfave.NetworkFromContext(ctx),
|
|
|
|
)
|
|
|
|
|
|
|
|
if err := plugin.Validate(); err != nil {
|
|
|
|
if e, ok := err.(errors.ExitCoder); ok {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors.ExitMessagef("validation failed: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := plugin.Execute(); err != nil {
|
|
|
|
if e, ok := err.(errors.ExitCoder); ok {
|
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors.ExitMessagef("execution failed: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|