Documentation
¶
Overview ¶
Package ci implements the "bogform ci" commands, which run Bogform from repository pipelines and report the results on pull requests.
Index ¶
- Constants
- Variables
- func DetectPlatformFromRemote(remote string) string
- func Marker(kind, directory, workspace string) string
- func NewPublisher(serverURL, token string, client *http.Client) (func(context.Context, *Report) error, error)
- func NextSteps(platform string, opts ScaffoldOptions) string
- func RenderPipeline(opts ScaffoldOptions) ([]byte, error)
- func Scaffold(opts ScaffoldOptions) (string, error)
- type Change
- type Commenter
- type Context
- type Counts
- type EnvFunc
- type Options
- type RenderOptions
- type Report
- type Runner
- type ScaffoldOptions
Constants ¶
const ( PlatformNone = "none" PlatformGitHub = "github" PlatformGitLab = "gitlab" PlatformAzure = "azure" PlatformBitbucket = "bitbucket" )
Names of the supported pipeline platforms.
const ( ServerURLEnvName = "BOG_SERVER_URL" ServerTokenEnvName = "BOG_SERVER_TOKEN" )
Names of the variables that connect pipelines to a Bogform server.
const ( KindPlan = "plan" KindApply = "apply" KindDrift = "drift" )
Kinds of run.
const ( StatusNoChanges = "no_changes" StatusChanges = "changes" StatusApplied = "applied" StatusDrifted = "drifted" StatusFailed = "failed" )
Results of a run.
const ( ExitOK = 0 ExitFailed = 1 ExitDrifted = 2 )
Exit codes of the "ci" commands.
const ( ApplyManual = "manual" ApplyMerge = "merge" )
When a pipeline applies changes.
const ReportFormatVersion = 1
ReportFormatVersion is the version of the report.json format.
const TokenEnvName = "BOG_CI_TOKEN"
TokenEnvName is the variable holding the token used to post pull request comments. It's removed from the environment of the commands Bogform runs, so that it doesn't reach them by accident. This isn't a security boundary: code running as the same user can read a parent process's memory. So give this token only the permission to comment.
const WorkDir = ".bogform-ci"
WorkDir is the directory, relative to the configuration, where runs keep their plan and report.
Variables ¶
var ErrNoCommenter = errors.New("this run has no pull request to comment on")
ErrNoCommenter means that the current run can't comment, for example outside a pull request.
Functions ¶
func DetectPlatformFromRemote ¶
DetectPlatformFromRemote guesses the platform from a Git remote URL, or returns an empty string.
func Marker ¶
Marker identifies this directory and workspace's comment on a pull request. A Markdown link reference doesn't render, and unlike an HTML comment that works on every platform.
func NewPublisher ¶
func NewPublisher(serverURL, token string, client *http.Client) (func(context.Context, *Report) error, error)
NewPublisher returns a function that sends reports to a Bogform server. It refuses to send the token over an unencrypted connection, except to this machine.
func NextSteps ¶
func NextSteps(platform string, opts ScaffoldOptions) string
NextSteps explains what to do after generating a pipeline file for a platform.
func RenderPipeline ¶
func RenderPipeline(opts ScaffoldOptions) ([]byte, error)
RenderPipeline returns the contents of a pipeline file.
func Scaffold ¶
func Scaffold(opts ScaffoldOptions) (string, error)
Scaffold writes a pipeline file and returns its path.
Types ¶
type Change ¶
Change is one resource that a plan would change. It holds no attribute values, so reports are safe to store and display even for resources with sensitive data.
type Commenter ¶
type Commenter interface {
// Upsert updates the comment containing marker, or creates one if there isn't any.
Upsert(ctx context.Context, marker, body string) error
// MaxBody is the longest comment that the platform accepts, in bytes.
MaxBody() int
// Collapsible reports whether the platform renders HTML <details> blocks.
Collapsible() bool
}
Commenter creates or updates a single comment on the current pull request.
type Context ¶
type Context struct {
Platform string `json:"platform"`
Repository string `json:"repository,omitempty"`
Branch string `json:"branch,omitempty"`
Commit string `json:"commit,omitempty"`
RunURL string `json:"run_url,omitempty"`
IsPullRequest bool `json:"is_pull_request"`
PullRequest string `json:"pull_request,omitempty"`
FromFork bool `json:"from_fork,omitempty"`
// contains filtered or unexported fields
}
Context describes the pipeline run that Bogform is executing in.
type Counts ¶
type Counts struct {
Add int `json:"add"`
Change int `json:"change"`
Destroy int `json:"destroy"`
Replace int `json:"replace"`
Import int `json:"import"`
Read int `json:"read,omitempty"`
}
Counts summarizes the changes in a plan.
type Options ¶
type Options struct {
Binary string // The bogform executable to run.
Version string
Directory string // The configuration directory, for display.
Workspace string
Vars []string
VarFiles []string
Args []string // More arguments for the plan command.
AllowPullRequestApply bool
NoComment bool
NoOutput bool
Env []string // Environment of this process, as os.Environ returns it.
Stdout io.Writer
Stderr io.Writer
HTTPClient *http.Client
// Publisher, if set, receives the report when a run finishes.
Publisher func(context.Context, *Report) error
Now func() time.Time
}
Options configures a run.
type RenderOptions ¶
type RenderOptions struct {
// MaxBytes limits the size of the result. Zero means no limit.
MaxBytes int
// Collapsible puts long sections inside HTML <details> blocks.
Collapsible bool
// HideOutput leaves out the text of the plan.
HideOutput bool
}
RenderOptions controls how a report is rendered as Markdown.
type Report ¶
type Report struct {
FormatVersion int `json:"format_version"`
Kind string `json:"kind"`
Status string `json:"status"`
BogformVersion string `json:"bogform_version"`
Directory string `json:"directory"`
Workspace string `json:"workspace"`
Run Context `json:"run"`
Counts Counts `json:"counts"`
Changes []Change `json:"changes"`
OutputsChanged []string `json:"outputs_changed,omitempty"`
Error string `json:"error,omitempty"`
StartedAt time.Time `json:"started_at"`
FinishedAt time.Time `json:"finished_at"`
// Output is the text of the plan or the failure. Bogform redacts sensitive values in it, but a
// provider could still print something private, so it's left out of report.json.
Output string `json:"-"`
}
Report is the record of a pipeline run, written to report.json.
func (*Report) Render ¶
func (r *Report) Render(opts RenderOptions) string
Render formats the report as Markdown.
type Runner ¶
Runner carries out "ci" commands by running the bogform executable, exactly as a person would.
type ScaffoldOptions ¶
type ScaffoldOptions struct {
Platform string
Version string // The version of Bogform to pin, or empty to use the latest release.
DefaultBranch string
Directory string
Environment string
// ApplyOn is "manual" to apply only when someone starts the pipeline, or "merge" to apply every
// change merged to the default branch.
ApplyOn string
// GitState sets up the pipeline for the git state backend.
GitState bool
Force bool
Root string // The repository root.
}
ScaffoldOptions configures a generated pipeline file.