cisinkwrite

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 4 Imported by: ? 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.

README

cisink-write-go

The fleet's one typed emitter for CI variable-set and step-output exports — so no tool hand-rolls the echo "NAME=value" >> $GITHUB_OUTPUT (and three other dialects') incantations.

What

A Writer (built with functional options) whose SetVariable(name, value) and SetOutput(name, value) emit the right export bytes for the active CI provider to a caller-supplied io.Writer:

Provider Dialect
GitHub Actions NAME=value (heredoc framing for multiline)
GitLab CI dotenv NAME=value (artifacts:reports:dotenv)
Bitbucket Pipelines export NAME='value' (shell, on stdout)
Buildkite buildkite-agent meta-data set (output) / export (env)

It is the writer half of the CI-export pattern; its sibling ci-sink-go is the reader that detects the provider and resolves the cisink.Sink this writer consumes. The writer never shells out and never opens a file — it writes dialect bytes to an io.Writer the caller owns, so it is pure and hermetically testable. Invalid names, multiline values a dialect cannot represent, and unsupported providers become typed, code-carrying errors via errors-go.

Why

Emitting a CI variable recurs across every release/build tool, and the four dialects diverge in subtle, breakage-prone ways (GitHub's heredoc framing, GitLab's dotenv, shell quoting, Buildkite's metadata CLI). One typed emitter keyed off a cisink.Sink means the dialect is chosen once, correctly — never a hand-rolled >> $GITHUB_OUTPUT again.

Install

go get github.com/pleme-io/cisink-write-go

Usage

ctx, _ := cisink.Read()                       // ci-sink-go: detect + resolve sink
w := cisinkwrite.FromSink(ctx.Sink, os.Stdout) // writer keyed off the sink
if err := w.SetOutput("release", "v1.2.3"); err != nil {
    return errs.Exit(err)
}

// Forced dialect, no reader:
w = cisinkwrite.New(cisink.ProviderGitHub, githubEnvFile)
err := w.SetVariable("TOKEN_TTL", "3600")

Configuration

A typed Config (yaml-tagged) pins the dialect declaratively when a tool loads config via shikumi-go. Load once at main, then cisinkwrite.FromConfig(cfg.CISinkWrite, out):

provider: github   # optional; empty → supply a sink via WithSink

FromConfig consumes the already-loaded sub-struct and never calls shikumi.Load itself (BOREALIS §3.5).

Release

Pull-model (Go modules): an annotated vX.Y.Z tag is the release; pkg.go.dev indexes it. See the GSDS module delivery FSM.

Documentation

Overview

Package cisinkwrite emits CI variable-set and step-output exports in the dialect of the active CI provider. It is the WRITER half of the CI-export pattern; its sibling ci-sink-go is the READER that detects the provider and resolves the cisink.Sink this package writes into.

Each provider exports variables and outputs through a different mechanism:

  • GitHub Actions appends `NAME=value` (with heredoc framing for multiline values) to the files named by $GITHUB_ENV and $GITHUB_OUTPUT.
  • GitLab CI has no per-step env-append file; the portable channel is a dotenv file (`NAME=value` lines) declared via artifacts:reports:dotenv.
  • Bitbucket Pipelines exports via shell `export NAME=value` lines on stdout.
  • Buildkite sets build metadata via `buildkite-agent meta-data set` and exports env via shell `export NAME=value` lines on stdout.

This package writes the *bytes* of each dialect to an io.Writer; it never shells out (Buildkite's metadata command is emitted as the line a caller runs or appends). That keeps it pure stdlib + errors-go and hermetically testable.

The model is borealis-style (BOREALIS.md §3.5): New(required…, opts…) / FromConfig(cfg); errors are typed and code-carrying via errors-go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Provider, when non-empty, pins the emit dialect. Valid values are the
	// cisink.Provider string constants ("github"/"gitlab"/"bitbucket"/
	// "buildkite"). Empty means the caller must supply a sink via
	// [WithSink] (typically the one ci-sink-go's reader resolved), and an
	// unconfigured emit is then a codeUnsupported error.
	Provider string `yaml:"provider"`
}

Config is the typed, shikumi-loadable knob surface for a Writer. It exists so a tool that already loads a config file can pin the dialect declaratively rather than threading a Provider through code.

type Kind

type Kind int

Kind distinguishes the two export channels a provider may offer.

const (
	// KindEnv exports a variable into the environment of subsequent steps.
	KindEnv Kind = iota
	// KindOutput exports a named step output consumed by later steps.
	KindOutput
)

func (Kind) String

func (k Kind) String() string

String reports the channel name, for diagnostics.

type Option

type Option func(*Writer)

Option configures a Writer during New / FromSink. Options apply in order; a later option of the same kind overrides an earlier one.

func WithSink

func WithSink(s cisink.Sink) Option

WithSink overrides the destination cisink.Sink of the writer. The Sink's Provider selects the dialect, and its file paths are informational only — the emitted bytes go to the configured io.Writer, never to the Sink's files directly (the caller owns file opening, so the writer stays pure and testable). The default sink (when constructed via New without this option) is an empty Sink with cisink.ProviderUnknown, which makes every emit a codeUnsupported error until a real sink is supplied.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer emits CI exports in the dialect of its cisink.Sink's provider to a caller-supplied io.Writer. Construct it with New (provider + io.Writer) or FromSink (a resolved sink + io.Writer). A Writer is stateless across emits and safe to reuse.

func FromConfig

func FromConfig(cfg Config, out io.Writer, opts ...Option) *Writer

FromConfig constructs a Writer from an already-loaded Config and a destination (§3.5). It does NOT call shikumi.Load — the caller loads cfg once at main and hands this the sub-struct. When cfg.Provider is empty the writer is constructed for cisink.ProviderUnknown; supply WithSink (e.g. from a ci-sink-go read) to give it a real dialect.

func FromSink

func FromSink(s cisink.Sink, out io.Writer, opts ...Option) *Writer

FromSink constructs a Writer from an already-resolved cisink.Sink (the value ci-sink-go's reader produces) and a destination. It is the canonical reader→writer hand-off:

ctx, _ := cisink.Read()
w := cisinkwrite.FromSink(ctx.Sink, os.Stdout)

func New

func New(p cisink.Provider, out io.Writer, opts ...Option) *Writer

New constructs a Writer that emits the dialect for provider p to out (§3.5 Construct shape: New(required…, opts…)). The required positional args are the provider and the destination; options refine the sink (e.g. to carry file paths through). For most callers FromSink is more direct.

func (*Writer) Provider

func (w *Writer) Provider() cisink.Provider

Provider reports the provider whose dialect this writer emits.

func (*Writer) SetOutput

func (w *Writer) SetOutput(name, value string) error

SetOutput emits an export that makes name=value available as a named step output (the KindOutput channel). Providers without a distinct output channel (GitLab/Bitbucket/Buildkite) fall back to their variable dialect.

func (*Writer) SetVariable

func (w *Writer) SetVariable(name, value string) error

SetVariable emits an export that makes name=value available as an environment variable to subsequent steps, in the active provider's dialect. It is the most common verb (the KindEnv channel).

Jump to

Keyboard shortcuts

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