Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) start migration from drone-yaml dependency. use docker compiler for lint #210

Merged
merged 2 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions drone/convert/convert.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package convert

import (
"bytes"
"io"
"io/ioutil"
"os"

"github.com/drone/drone-yaml/yaml/converter"
"github.com/urfave/cli"
)

// Command exports the convert command.
var Command = cli.Command{
Name: "convert",
Usage: "convert legacy format",
Usage: "<deprecated. this operation is a no-op> convert legacy format",
ArgsUsage: "<source>",
Action: convert,
Flags: []cli.Flag{
Expand All @@ -30,20 +26,9 @@ func convert(c *cli.Context) error {
path = ".drone.yml"
}

raw, err := ioutil.ReadFile(path)
_, err := ioutil.ReadFile(path)
if err != nil {
return err
}

res, err := converter.Convert(raw, converter.Metadata{Filename: path})
if err != nil {
return err
}

if c.Bool("save") {
return ioutil.WriteFile(path, res, 0644)
}

_, err = io.Copy(os.Stderr, bytes.NewReader(res))
return err
}
82 changes: 82 additions & 0 deletions drone/exec/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2019 Drone.IO Inc. All rights reserved.
// Use of this source code is governed by the Polyform License
// that can be found in the LICENSE file.

package exec

import (
"github.com/drone-runners/drone-runner-docker/engine/compiler"
"github.com/drone/drone-go/drone"
"github.com/urfave/cli"
)

// Flags maps
type Flags struct {
Build *drone.Build
Netrc *drone.Netrc
Repo *drone.Repo
Stage *drone.Stage
System *drone.System
}

type execCommand struct {
*Flags

Source string
Include []string
Exclude []string
Privileged []string
Networks []string
Volumes map[string]string
Environ map[string]string
Labels map[string]string
Secrets map[string]string
Resources compiler.Resources
Tmate compiler.Tmate
Clone bool
Config string
Pretty bool
Procs int64
Debug bool
Trace bool
Dump bool
PublicKey string
PrivateKey string
}

func mapOldToExecCommand(input *cli.Context) (returnVal *execCommand) {
returnVal = &execCommand{
Flags: &Flags{
Build: &drone.Build{
Event: input.String("event"),
Ref: input.String("ref"),
Deploy: input.String("deploy-to"),
},
Repo: &drone.Repo{
Trusted: input.Bool("trusted"),
Timeout: int64(input.Int("timeout")),
Branch: input.String("branch"),
Name: input.String("name"),
},
Stage: &drone.Stage{
Name: input.String("pipeline"),
},
Netrc: &drone.Netrc{
Machine: input.String("netrc-machine"),
Login: input.String("netrc-username"),
Password: input.String("netrc-password"),
},
System: &drone.System{
Host: input.String("instance"),
},
},
Source: input.Args().First(),
Include: input.StringSlice("include"),
Exclude: input.StringSlice("exclude"),
Clone: input.Bool("clone"),
Networks: input.StringSlice("network"),
Privileged: input.StringSlice("privileged"),
}

return returnVal
}
65 changes: 65 additions & 0 deletions drone/exec2/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package exec2

import (
"os"
"strings"

"github.com/urfave/cli"
)

func getEnv(c *cli.Context) map[string]string {
env := prefixedEnviron(
os.Environ(),
)
if c.IsSet("branch") {
v := c.String("branch")
env["DRONE_BRANCH"] = v
env["DRONE_COMMIT_BRANCH"] = v
env["DRONE_TARGET_BRANCH"] = v
}
if c.IsSet("event") {
v := c.String("event")
env["DRONE_EVENT"] = v
}
if c.IsSet("instance") {
v := c.String("instance")
env["DRONE_SYSTEM_HOST"] = v
env["DRONE_SYSTEM_HOSTNAME"] = v
}
if c.IsSet("ref") {
v := c.String("ref")
env["DRONE_COMMIT_REF"] = v
}
if c.IsSet("sha") {
v := c.String("sha")
env["DRONE_COMMIT_SHA"] = v
}
if c.IsSet("repo") {
v := c.String("repo")
env["DRONE_REPO"] = v
}
if c.IsSet("deploy-to") {
v := c.String("deploy-to")
env["DRONE_DEPLOY_TO"] = v
}
return env
}

// helper function returns all environment variables
// prefixed with DRONE_.
func prefixedEnviron(environ []string) map[string]string {
envs := map[string]string{}
for _, env := range environ {
if !strings.HasPrefix(env, "DRONE_") {
continue
}
parts := strings.SplitN(env, "=", 2)
if len(parts) != 2 {
continue
}
key := parts[0]
val := parts[1]
envs[key] = val
}
return envs
}
Loading