updated to match deprecations, added otherOptions

main v0.0.3
gapodo 2022-10-27 18:04:35 +02:00
parent 21005e3ee7
commit 7f80c971c3
1 changed files with 122 additions and 57 deletions

View File

@ -20,17 +20,28 @@ import (
"github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/matrix" "github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/matrix"
) )
type (
OtherBuildData struct {
Tag string
PullRequest string
WorkspaceBase string
WorkspacePath string
Workspace string
}
)
func BuildMetadataFromContext(c *cli.Context, axis matrix.Axis) frontend.Metadata { func BuildMetadataFromContext(c *cli.Context, axis matrix.Axis) frontend.Metadata {
return frontend.Metadata{ return frontend.Metadata{
Repo: frontend.Repo{ Repo: frontend.Repo{
Name: c.String("repo-name"), Name: c.String("repo"),
Link: c.String("repo-link"), Link: c.String("repo-link"),
Remote: c.String("repo-remote-url"), Remote: c.String("repo-remote-url"),
Private: c.Bool("repo-private"), Private: c.Bool("repo-private"),
Branch: c.String("repo-branch"),
}, },
Curr: frontend.Build{ Curr: frontend.Build{
Number: c.Int64("build-number"), Number: c.Int64("build-number"),
Parent: c.Int64("parent-build-number"), Parent: c.Int64("build-parent"),
Created: c.Int64("build-created"), Created: c.Int64("build-created"),
Started: c.Int64("build-started"), Started: c.Int64("build-started"),
Finished: c.Int64("build-finished"), Finished: c.Int64("build-finished"),
@ -45,7 +56,7 @@ func BuildMetadataFromContext(c *cli.Context, axis matrix.Axis) frontend.Metadat
Branch: c.String("commit-branch"), Branch: c.String("commit-branch"),
Message: c.String("commit-message"), Message: c.String("commit-message"),
Author: frontend.Author{ Author: frontend.Author{
Name: c.String("commit-author-name"), Name: c.String("commit-author"),
Email: c.String("commit-author-email"), Email: c.String("commit-author-email"),
Avatar: c.String("commit-author-avatar"), Avatar: c.String("commit-author-avatar"),
}, },
@ -53,12 +64,14 @@ func BuildMetadataFromContext(c *cli.Context, axis matrix.Axis) frontend.Metadat
}, },
Prev: frontend.Build{ Prev: frontend.Build{
Number: c.Int64("prev-build-number"), Number: c.Int64("prev-build-number"),
Parent: c.Int64("prev-build-parent"),
Created: c.Int64("prev-build-created"), Created: c.Int64("prev-build-created"),
Started: c.Int64("prev-build-started"), Started: c.Int64("prev-build-started"),
Finished: c.Int64("prev-build-finished"), Finished: c.Int64("prev-build-finished"),
Status: c.String("prev-build-status"), Status: c.String("prev-build-status"),
Event: c.String("prev-build-event"), Event: c.String("prev-build-event"),
Link: c.String("prev-build-link"), Link: c.String("prev-build-link"),
Target: c.String("prev-build-target"),
Commit: frontend.Commit{ Commit: frontend.Commit{
Sha: c.String("prev-commit-sha"), Sha: c.String("prev-commit-sha"),
Ref: c.String("prev-commit-ref"), Ref: c.String("prev-commit-ref"),
@ -66,7 +79,7 @@ func BuildMetadataFromContext(c *cli.Context, axis matrix.Axis) frontend.Metadat
Branch: c.String("prev-commit-branch"), Branch: c.String("prev-commit-branch"),
Message: c.String("prev-commit-message"), Message: c.String("prev-commit-message"),
Author: frontend.Author{ Author: frontend.Author{
Name: c.String("prev-commit-author-name"), Name: c.String("prev-commit-author"),
Email: c.String("prev-commit-author-email"), Email: c.String("prev-commit-author-email"),
Avatar: c.String("prev-commit-author-avatar"), Avatar: c.String("prev-commit-author-avatar"),
}, },
@ -77,44 +90,38 @@ func BuildMetadataFromContext(c *cli.Context, axis matrix.Axis) frontend.Metadat
Matrix: axis, Matrix: axis,
}, },
Sys: frontend.System{ Sys: frontend.System{
Name: c.String("system-name"), Name: c.String("system-name"),
Link: c.String("system-link"), Host: c.String("system-host"),
Arch: c.String("system-arch"), Link: c.String("system-link"),
Arch: c.String("system-arch"),
Version: c.String("system-version"),
}, },
} }
} }
func NonMetadataFromBuildContext(c *cli.Context) OtherBuildData {
opts := OtherBuildData{
WorkspaceBase: c.String("workspace-base"),
WorkspacePath: c.String("workspace-path"),
Workspace: c.String("workspace"),
}
if c.String("build-event") == frontend.EventPull {
opts.PullRequest = c.String("commit-pr")
}
if c.String("build-event") == frontend.EventTag {
opts.Tag = c.String("commit-tag")
}
return opts
}
func BuildFlags() []cli.Flag { func BuildFlags() []cli.Flag {
return []cli.Flag{ return []cli.Flag{
// repo
&cli.StringFlag{ &cli.StringFlag{
EnvVars: []string{"CI_WORKSPACE_BASE"}, EnvVars: []string{"CI_REPO"},
Name: "workspace-base", Name: "repo",
Value: "/woodpecker",
},
&cli.StringFlag{
EnvVars: []string{"CI_WORKSPACE_PATH"},
Name: "workspace-path",
Value: "src",
},
&cli.StringFlag{
EnvVars: []string{"CI_WORKSPACE"},
Name: "workspace",
Value: "/woodpecker/src",
},
//
// metadata parameters
//
&cli.StringFlag{
EnvVars: []string{"CI_SYSTEM_NAME"},
Name: "system-name",
},
&cli.StringFlag{
EnvVars: []string{"CI_SYSTEM_LINK"},
Name: "system-link",
},
&cli.StringFlag{
EnvVars: []string{"CI_REPO_NAME"},
Name: "repo-name",
}, },
&cli.StringFlag{ &cli.StringFlag{
EnvVars: []string{"CI_REPO_LINK"}, EnvVars: []string{"CI_REPO_LINK"},
@ -124,17 +131,22 @@ func BuildFlags() []cli.Flag {
EnvVars: []string{"CI_REPO_REMOTE"}, EnvVars: []string{"CI_REPO_REMOTE"},
Name: "repo-remote-url", Name: "repo-remote-url",
}, },
&cli.StringFlag{ &cli.BoolFlag{
EnvVars: []string{"CI_REPO_PRIVATE"}, EnvVars: []string{"CI_REPO_PRIVATE"},
Name: "repo-private", Name: "repo-private",
}, },
&cli.IntFlag{ &cli.StringFlag{
EnvVars: []string{"CI_REPO_DEFAULT_BRANCH"},
Name: "repo-branch",
},
// current build
&cli.Int64Flag{
EnvVars: []string{"CI_BUILD_NUMBER"}, EnvVars: []string{"CI_BUILD_NUMBER"},
Name: "build-number", Name: "build-number",
}, },
&cli.IntFlag{ &cli.Int64Flag{
EnvVars: []string{"CI_PARENT_BUILD_NUMBER"}, EnvVars: []string{"CI_PARENT"},
Name: "parent-build-number", Name: "build-parent",
}, },
&cli.Int64Flag{ &cli.Int64Flag{
EnvVars: []string{"CI_BUILD_CREATED"}, EnvVars: []string{"CI_BUILD_CREATED"},
@ -161,9 +173,10 @@ func BuildFlags() []cli.Flag {
Name: "build-link", Name: "build-link",
}, },
&cli.StringFlag{ &cli.StringFlag{
EnvVars: []string{"CI_BUILD_TARGET"}, EnvVars: []string{"CI_BUILD_DEPLOY_TARGET"},
Name: "build-target", Name: "build-target",
}, },
// current commit
&cli.StringFlag{ &cli.StringFlag{
EnvVars: []string{"CI_COMMIT_SHA"}, EnvVars: []string{"CI_COMMIT_SHA"},
Name: "commit-sha", Name: "commit-sha",
@ -184,22 +197,28 @@ func BuildFlags() []cli.Flag {
EnvVars: []string{"CI_COMMIT_MESSAGE"}, EnvVars: []string{"CI_COMMIT_MESSAGE"},
Name: "commit-message", Name: "commit-message",
}, },
// current commit author
&cli.StringFlag{ &cli.StringFlag{
EnvVars: []string{"CI_COMMIT_AUTHOR_NAME"}, EnvVars: []string{"CI_COMMIT_AUTHOR"},
Name: "commit-author-name", Name: "commit-author",
},
&cli.StringFlag{
EnvVars: []string{"CI_COMMIT_AUTHOR_AVATAR"},
Name: "commit-author-avatar",
}, },
&cli.StringFlag{ &cli.StringFlag{
EnvVars: []string{"CI_COMMIT_AUTHOR_EMAIL"}, EnvVars: []string{"CI_COMMIT_AUTHOR_EMAIL"},
Name: "commit-author-email", Name: "commit-author-email",
}, },
&cli.IntFlag{ &cli.StringFlag{
EnvVars: []string{"CI_COMMIT_AUTHOR_AVATAR"},
Name: "commit-author-avatar",
},
// previous build
&cli.Int64Flag{
EnvVars: []string{"CI_PREV_BUILD_NUMBER"}, EnvVars: []string{"CI_PREV_BUILD_NUMBER"},
Name: "prev-build-number", Name: "prev-build-number",
}, },
&cli.Int64Flag{
EnvVars: []string{"CI_PREV_BUILD_PARENT"},
Name: "prev-build-parent",
},
&cli.Int64Flag{ &cli.Int64Flag{
EnvVars: []string{"CI_PREV_BUILD_CREATED"}, EnvVars: []string{"CI_PREV_BUILD_CREATED"},
Name: "prev-build-created", Name: "prev-build-created",
@ -224,6 +243,11 @@ func BuildFlags() []cli.Flag {
EnvVars: []string{"CI_PREV_BUILD_LINK"}, EnvVars: []string{"CI_PREV_BUILD_LINK"},
Name: "prev-build-link", Name: "prev-build-link",
}, },
&cli.StringFlag{
EnvVars: []string{"CI_PREV_BUILD_DEPLOY_TARGET"},
Name: "prev-build-target",
},
// previous commit
&cli.StringFlag{ &cli.StringFlag{
EnvVars: []string{"CI_PREV_COMMIT_SHA"}, EnvVars: []string{"CI_PREV_COMMIT_SHA"},
Name: "prev-commit-sha", Name: "prev-commit-sha",
@ -244,25 +268,66 @@ func BuildFlags() []cli.Flag {
EnvVars: []string{"CI_PREV_COMMIT_MESSAGE"}, EnvVars: []string{"CI_PREV_COMMIT_MESSAGE"},
Name: "prev-commit-message", Name: "prev-commit-message",
}, },
// previous commit author
&cli.StringFlag{ &cli.StringFlag{
EnvVars: []string{"CI_PREV_COMMIT_AUTHOR_NAME"}, EnvVars: []string{"CI_PREV_COMMIT_AUTHOR"},
Name: "prev-commit-author-name", Name: "prev-commit-author",
},
&cli.StringFlag{
EnvVars: []string{"CI_PREV_COMMIT_AUTHOR_AVATAR"},
Name: "prev-commit-author-avatar",
}, },
&cli.StringFlag{ &cli.StringFlag{
EnvVars: []string{"CI_PREV_COMMIT_AUTHOR_EMAIL"}, EnvVars: []string{"CI_PREV_COMMIT_AUTHOR_EMAIL"},
Name: "prev-commit-author-email", Name: "prev-commit-author-email",
}, },
&cli.StringFlag{
EnvVars: []string{"CI_PREV_COMMIT_AUTHOR_AVATAR"},
Name: "prev-commit-author-avatar",
},
// Job
&cli.IntFlag{ &cli.IntFlag{
EnvVars: []string{"CI_JOB_NUMBER"}, EnvVars: []string{"CI_JOB_NUMBER"},
Name: "job-number", Name: "job-number",
}, },
&cli.StringSliceFlag{ // System
EnvVars: []string{"CI_ENV"}, &cli.StringFlag{
Name: "env", EnvVars: []string{"CI_SYSTEM_NAME"},
Name: "system-name",
},
&cli.StringFlag{
EnvVars: []string{"CI_SYSTEM_HOST"},
Name: "system-host",
},
&cli.StringFlag{
EnvVars: []string{"CI_SYSTEM_LINK"},
Name: "system-link",
},
&cli.StringFlag{
EnvVars: []string{"CI_SYSTEM_ARCH"},
Name: "system-arch",
},
&cli.StringFlag{
EnvVars: []string{"CI_SYSTEM_VERSION"},
Name: "system-version",
},
// other
&cli.StringFlag{
EnvVars: []string{"CI_WORKSPACE_BASE"},
Name: "workspace-base",
},
&cli.StringFlag{
EnvVars: []string{"CI_WORKSPACE_PATH"},
Name: "workspace-path",
},
&cli.StringFlag{
EnvVars: []string{"CI_WORKSPACE"},
Name: "workspace",
},
&cli.StringFlag{
EnvVars: []string{"CI_COMMIT_TAG"},
Name: "commit-tag",
},
&cli.StringFlag{
EnvVars: []string{"CI_COMMIT_PULL_REQUEST"},
Name: "commit-pr",
}, },
} }
} }