mirror of
https://github.com/drone-plugins/drone-download.git
synced 2026-06-04 10:15:28 +08:00
(maint) cleaning build up with move to harness
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
/release/
|
/release/
|
||||||
/drone-download*
|
/drone-download*
|
||||||
|
|
||||||
coverage.out
|
coverage.out
|
||||||
.drone.yml
|
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
// Copyright (c) 2020, the Drone Plugins project authors.
|
|
||||||
// Please see the AUTHORS file for details. All rights reserved.
|
|
||||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
|
||||||
// found in the LICENSE file.
|
|
||||||
|
|
||||||
// DO NOT MODIFY THIS FILE DIRECTLY
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/drone-plugins/drone-download/plugin"
|
|
||||||
"github.com/drone-plugins/drone-plugin-lib/errors"
|
|
||||||
"github.com/drone-plugins/drone-plugin-lib/urfave"
|
|
||||||
"github.com/joho/godotenv"
|
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
)
|
|
||||||
|
|
||||||
var version = "unknown"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
settings := &plugin.Settings{}
|
|
||||||
|
|
||||||
if _, err := os.Stat("/run/drone/env"); err == nil {
|
|
||||||
godotenv.Overload("/run/drone/env")
|
|
||||||
}
|
|
||||||
|
|
||||||
app := &cli.App{
|
|
||||||
Name: "drone-download",
|
|
||||||
Usage: "download a file",
|
|
||||||
Version: version,
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,14 +3,72 @@
|
|||||||
// Use of this source code is governed by an Apache 2.0 license that can be
|
// Use of this source code is governed by an Apache 2.0 license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
// DO NOT MODIFY THIS FILE DIRECTLY
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/drone-plugins/drone-download/plugin"
|
"github.com/drone-plugins/drone-download/plugin"
|
||||||
|
"github.com/drone-plugins/drone-plugin-lib/errors"
|
||||||
|
"github.com/drone-plugins/drone-plugin-lib/urfave"
|
||||||
|
"github.com/joho/godotenv"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// settingsFlags has the cli.Flags for the plugin.Settings.
|
var version = "unknown"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
settings := &plugin.Settings{}
|
||||||
|
|
||||||
|
if _, err := os.Stat("/run/drone/env"); err == nil {
|
||||||
|
_ = godotenv.Overload("/run/drone/env")
|
||||||
|
}
|
||||||
|
|
||||||
|
app := &cli.App{
|
||||||
|
Name: "drone-download",
|
||||||
|
Usage: "download a file",
|
||||||
|
Version: version,
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func settingsFlags(settings *plugin.Settings) []cli.Flag {
|
func settingsFlags(settings *plugin.Settings) []cli.Flag {
|
||||||
return []cli.Flag{
|
return []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
+1
-1
@@ -128,7 +128,7 @@ func (p *Plugin) Execute() error {
|
|||||||
|
|
||||||
if exp != "" {
|
if exp != "" {
|
||||||
logrus.WithField("hash", alg).Info("Computing checksum")
|
logrus.WithField("hash", alg).Info("Computing checksum")
|
||||||
target.Seek(0, 0)
|
_, _ = target.Seek(0, 0)
|
||||||
|
|
||||||
if _, err := io.Copy(h, target); err != nil {
|
if _, err := io.Copy(h, target); err != nil {
|
||||||
defer os.Remove(target.Name())
|
defer os.Remove(target.Name())
|
||||||
|
|||||||
Reference in New Issue
Block a user