// Copyright 2021 Woodpecker Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package urfave import ( "git.kle.li/woodpecker/plugin-lib/common" "github.com/urfave/cli/v2" "github.com/woodpecker-ci/woodpecker/pipeline/frontend" "github.com/woodpecker-ci/woodpecker/pipeline/frontend/yaml/matrix" ) func BuildDataFromContext(c *cli.Context, axis matrix.Axis) common.BuildData { bdata := common.BuildData{ Metadata: frontend.Metadata{ Repo: frontend.Repo{ 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("build-parent"), Created: c.Int64("build-created"), Started: c.Int64("build-started"), Finished: c.Int64("build-finished"), Status: c.String("build-status"), Event: c.String("build-event"), Link: c.String("build-link"), Target: c.String("build-target"), Commit: frontend.Commit{ Sha: c.String("commit-sha"), Ref: c.String("commit-ref"), Refspec: c.String("commit-refspec"), Branch: c.String("commit-branch"), Message: c.String("commit-message"), Author: frontend.Author{ Name: c.String("commit-author"), Email: c.String("commit-author-email"), Avatar: c.String("commit-author-avatar"), }, }, }, 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"), Refspec: c.String("prev-commit-refspec"), Branch: c.String("prev-commit-branch"), Message: c.String("prev-commit-message"), Author: frontend.Author{ Name: c.String("prev-commit-author"), Email: c.String("prev-commit-author-email"), Avatar: c.String("prev-commit-author-avatar"), }, }, }, Job: frontend.Job{ Number: c.Int("job-number"), Matrix: axis, }, Sys: frontend.System{ 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"), }, }, AdditionalData: common.AdditionalData{ WorkspaceBase: c.String("workspace-base"), WorkspacePath: c.String("workspace-path"), Workspace: c.String("workspace"), SCM: c.String("repo-scm"), }, } return bdata } func BuildFlags() []cli.Flag { return []cli.Flag{ // repo &cli.StringFlag{ EnvVars: []string{"CI_REPO"}, Name: "repo", }, &cli.StringFlag{ EnvVars: []string{"CI_REPO_LINK"}, Name: "repo-link", }, &cli.StringFlag{ EnvVars: []string{"CI_REPO_REMOTE"}, Name: "repo-remote-url", }, &cli.BoolFlag{ EnvVars: []string{"CI_REPO_PRIVATE"}, Name: "repo-private", }, &cli.StringFlag{ EnvVars: []string{"CI_REPO_DEFAULT_BRANCH"}, Name: "repo-branch", }, // current build &cli.Int64Flag{ EnvVars: []string{"CI_BUILD_NUMBER"}, Name: "build-number", }, &cli.Int64Flag{ EnvVars: []string{"CI_PARENT"}, Name: "build-parent", }, &cli.Int64Flag{ EnvVars: []string{"CI_BUILD_CREATED"}, Name: "build-created", }, &cli.Int64Flag{ EnvVars: []string{"CI_BUILD_STARTED"}, Name: "build-started", }, &cli.Int64Flag{ EnvVars: []string{"CI_BUILD_FINISHED"}, Name: "build-finished", }, &cli.StringFlag{ EnvVars: []string{"CI_BUILD_STATUS"}, Name: "build-status", }, &cli.StringFlag{ EnvVars: []string{"CI_BUILD_EVENT"}, Name: "build-event", }, &cli.StringFlag{ EnvVars: []string{"CI_BUILD_LINK"}, Name: "build-link", }, &cli.StringFlag{ EnvVars: []string{"CI_BUILD_DEPLOY_TARGET"}, Name: "build-target", }, // current commit &cli.StringFlag{ EnvVars: []string{"CI_COMMIT_SHA"}, Name: "commit-sha", }, &cli.StringFlag{ EnvVars: []string{"CI_COMMIT_REF"}, Name: "commit-ref", }, &cli.StringFlag{ EnvVars: []string{"CI_COMMIT_REFSPEC"}, Name: "commit-refspec", }, &cli.StringFlag{ EnvVars: []string{"CI_COMMIT_BRANCH"}, Name: "commit-branch", }, &cli.StringFlag{ EnvVars: []string{"CI_COMMIT_MESSAGE"}, Name: "commit-message", }, // current commit author &cli.StringFlag{ EnvVars: []string{"CI_COMMIT_AUTHOR"}, Name: "commit-author", }, &cli.StringFlag{ EnvVars: []string{"CI_COMMIT_AUTHOR_EMAIL"}, Name: "commit-author-email", }, &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", }, &cli.Int64Flag{ EnvVars: []string{"CI_PREV_BUILD_STARTED"}, Name: "prev-build-started", }, &cli.Int64Flag{ EnvVars: []string{"CI_PREV_BUILD_FINISHED"}, Name: "prev-build-finished", }, &cli.StringFlag{ EnvVars: []string{"CI_PREV_BUILD_STATUS"}, Name: "prev-build-status", }, &cli.StringFlag{ EnvVars: []string{"CI_PREV_BUILD_EVENT"}, Name: "prev-build-event", }, &cli.StringFlag{ 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", }, &cli.StringFlag{ EnvVars: []string{"CI_PREV_COMMIT_REF"}, Name: "prev-commit-ref", }, &cli.StringFlag{ EnvVars: []string{"CI_PREV_COMMIT_REFSPEC"}, Name: "prev-commit-refspec", }, &cli.StringFlag{ EnvVars: []string{"CI_PREV_COMMIT_BRANCH"}, Name: "prev-commit-branch", }, &cli.StringFlag{ EnvVars: []string{"CI_PREV_COMMIT_MESSAGE"}, Name: "prev-commit-message", }, // previous commit author &cli.StringFlag{ 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", }, // 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_REPO_SCM"}, Name: "repo-scm", Value: "git", }, } }