ci

package
v1.14.0-alpha2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: MPL-2.0 Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ci implements the "bogform ci" commands, which run Bogform from repository pipelines and report the results on pull requests.

Index

Constants

View Source
const (
	PlatformNone      = "none"
	PlatformGitHub    = "github"
	PlatformGitLab    = "gitlab"
	PlatformAzure     = "azure"
	PlatformBitbucket = "bitbucket"
)

Names of the supported pipeline platforms.

View Source
const (
	ServerURLEnvName   = "BOG_SERVER_URL"
	ServerTokenEnvName = "BOG_SERVER_TOKEN"
)

Names of the variables that connect pipelines to a Bogform server.

View Source
const (
	KindPlan  = "plan"
	KindApply = "apply"
	KindDrift = "drift"
)

Kinds of run.

View Source
const (
	StatusNoChanges = "no_changes"
	StatusChanges   = "changes"
	StatusApplied   = "applied"
	StatusDrifted   = "drifted"
	StatusFailed    = "failed"
)

Results of a run.

View Source
const (
	ExitOK      = 0
	ExitFailed  = 1
	ExitDrifted = 2
)

Exit codes of the "ci" commands.

View Source
const (
	ApplyManual = "manual"
	ApplyMerge  = "merge"
)

When a pipeline applies changes.

View Source
const ReportFormatVersion = 1

ReportFormatVersion is the version of the report.json format.

View Source
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.

View Source
const WorkDir = ".bogform-ci"

WorkDir is the directory, relative to the configuration, where runs keep their plan and report.

Variables

View Source
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

func DetectPlatformFromRemote(remote string) string

DetectPlatformFromRemote guesses the platform from a Git remote URL, or returns an empty string.

func Marker

func Marker(kind, directory, workspace string) string

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

type Change struct {
	Address string   `json:"address"`
	Actions []string `json:"actions"`
}

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.

func NewCommenter

func NewCommenter(run Context, token string, client *http.Client) (Commenter, error)

NewCommenter returns the Commenter for the current pipeline platform.

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.

func Detect

func Detect(env EnvFunc) Context

Detect works out the current pipeline platform from its environment variables.

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.

func (Counts) Total

func (c Counts) Total() int

Total is the number of resources that would change.

type EnvFunc

type EnvFunc func(string) string

EnvFunc looks up an environment variable. os.Getenv satisfies it.

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

type Runner struct {
	Options
	Context Context
	// contains filtered or unexported fields
}

Runner carries out "ci" commands by running the bogform executable, exactly as a person would.

func NewRunner

func NewRunner(opts Options) *Runner

NewRunner detects the pipeline and prepares the environment for the commands it runs.

func (*Runner) Apply

func (r *Runner) Apply(ctx context.Context) int

Apply runs "ci apply".

func (*Runner) Drift

func (r *Runner) Drift(ctx context.Context) int

Drift runs "ci drift".

func (*Runner) Plan

func (r *Runner) Plan(ctx context.Context) int

Plan runs "ci plan".

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL