From 7f80c971c35caf3af3d60d41d03ec76795e0ef43 Mon Sep 17 00:00:00 2001 From: Michael Amann Date: Thu, 27 Oct 2022 18:04:35 +0200 Subject: [PATCH] updated to match deprecations, added otherOptions --- urfave/build.go | 179 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 122 insertions(+), 57 deletions(-) diff --git a/urfave/build.go b/urfave/build.go index e9bd113..dd7fdb1 100644 --- a/urfave/build.go +++ b/urfave/build.go @@ -20,17 +20,28 @@ import ( "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 { return frontend.Metadata{ Repo: frontend.Repo{ - Name: c.String("repo-name"), + Name: c.String("repo"), Link: c.String("repo-link"), Remote: c.String("repo-remote-url"), Private: c.Bool("repo-private"), + Branch: c.String("repo-branch"), }, Curr: frontend.Build{ Number: c.Int64("build-number"), - Parent: c.Int64("parent-build-number"), + Parent: c.Int64("build-parent"), Created: c.Int64("build-created"), Started: c.Int64("build-started"), Finished: c.Int64("build-finished"), @@ -45,7 +56,7 @@ func BuildMetadataFromContext(c *cli.Context, axis matrix.Axis) frontend.Metadat Branch: c.String("commit-branch"), Message: c.String("commit-message"), Author: frontend.Author{ - Name: c.String("commit-author-name"), + Name: c.String("commit-author"), Email: c.String("commit-author-email"), Avatar: c.String("commit-author-avatar"), }, @@ -53,12 +64,14 @@ func BuildMetadataFromContext(c *cli.Context, axis matrix.Axis) frontend.Metadat }, Prev: frontend.Build{ Number: c.Int64("prev-build-number"), + Parent: c.Int64("prev-build-parent"), Created: c.Int64("prev-build-created"), Started: c.Int64("prev-build-started"), Finished: c.Int64("prev-build-finished"), Status: c.String("prev-build-status"), Event: c.String("prev-build-event"), Link: c.String("prev-build-link"), + Target: c.String("prev-build-target"), Commit: frontend.Commit{ Sha: c.String("prev-commit-sha"), 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"), Message: c.String("prev-commit-message"), Author: frontend.Author{ - Name: c.String("prev-commit-author-name"), + Name: c.String("prev-commit-author"), Email: c.String("prev-commit-author-email"), Avatar: c.String("prev-commit-author-avatar"), }, @@ -77,44 +90,38 @@ func BuildMetadataFromContext(c *cli.Context, axis matrix.Axis) frontend.Metadat Matrix: axis, }, Sys: frontend.System{ - Name: c.String("system-name"), - Link: c.String("system-link"), - Arch: c.String("system-arch"), + Name: c.String("system-name"), + Host: c.String("system-host"), + 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 { return []cli.Flag{ + // repo &cli.StringFlag{ - EnvVars: []string{"CI_WORKSPACE_BASE"}, - Name: "workspace-base", - 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", + EnvVars: []string{"CI_REPO"}, + Name: "repo", }, &cli.StringFlag{ EnvVars: []string{"CI_REPO_LINK"}, @@ -124,17 +131,22 @@ func BuildFlags() []cli.Flag { EnvVars: []string{"CI_REPO_REMOTE"}, Name: "repo-remote-url", }, - &cli.StringFlag{ + &cli.BoolFlag{ EnvVars: []string{"CI_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"}, Name: "build-number", }, - &cli.IntFlag{ - EnvVars: []string{"CI_PARENT_BUILD_NUMBER"}, - Name: "parent-build-number", + &cli.Int64Flag{ + EnvVars: []string{"CI_PARENT"}, + Name: "build-parent", }, &cli.Int64Flag{ EnvVars: []string{"CI_BUILD_CREATED"}, @@ -161,9 +173,10 @@ func BuildFlags() []cli.Flag { Name: "build-link", }, &cli.StringFlag{ - EnvVars: []string{"CI_BUILD_TARGET"}, + EnvVars: []string{"CI_BUILD_DEPLOY_TARGET"}, Name: "build-target", }, + // current commit &cli.StringFlag{ EnvVars: []string{"CI_COMMIT_SHA"}, Name: "commit-sha", @@ -184,22 +197,28 @@ func BuildFlags() []cli.Flag { EnvVars: []string{"CI_COMMIT_MESSAGE"}, Name: "commit-message", }, + // current commit author &cli.StringFlag{ - EnvVars: []string{"CI_COMMIT_AUTHOR_NAME"}, - Name: "commit-author-name", - }, - &cli.StringFlag{ - EnvVars: []string{"CI_COMMIT_AUTHOR_AVATAR"}, - Name: "commit-author-avatar", + EnvVars: []string{"CI_COMMIT_AUTHOR"}, + Name: "commit-author", }, &cli.StringFlag{ EnvVars: []string{"CI_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"}, Name: "prev-build-number", }, + &cli.Int64Flag{ + EnvVars: []string{"CI_PREV_BUILD_PARENT"}, + Name: "prev-build-parent", + }, &cli.Int64Flag{ EnvVars: []string{"CI_PREV_BUILD_CREATED"}, Name: "prev-build-created", @@ -224,6 +243,11 @@ func BuildFlags() []cli.Flag { EnvVars: []string{"CI_PREV_BUILD_LINK"}, Name: "prev-build-link", }, + &cli.StringFlag{ + EnvVars: []string{"CI_PREV_BUILD_DEPLOY_TARGET"}, + Name: "prev-build-target", + }, + // previous commit &cli.StringFlag{ EnvVars: []string{"CI_PREV_COMMIT_SHA"}, Name: "prev-commit-sha", @@ -244,25 +268,66 @@ func BuildFlags() []cli.Flag { EnvVars: []string{"CI_PREV_COMMIT_MESSAGE"}, Name: "prev-commit-message", }, + // previous commit author &cli.StringFlag{ - EnvVars: []string{"CI_PREV_COMMIT_AUTHOR_NAME"}, - Name: "prev-commit-author-name", - }, - &cli.StringFlag{ - EnvVars: []string{"CI_PREV_COMMIT_AUTHOR_AVATAR"}, - Name: "prev-commit-author-avatar", + EnvVars: []string{"CI_PREV_COMMIT_AUTHOR"}, + Name: "prev-commit-author", }, &cli.StringFlag{ EnvVars: []string{"CI_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{ EnvVars: []string{"CI_JOB_NUMBER"}, Name: "job-number", }, - &cli.StringSliceFlag{ - EnvVars: []string{"CI_ENV"}, - Name: "env", + // System + &cli.StringFlag{ + 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", }, } }