project

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package project owns the per-project .citadel/ directory that lives next to citadel.yml: committed metadata (project.yml), the last deploy per env (state/), and per-deploy step logs (runs/). Callers never build paths under .citadel/ themselves.

It is distinct from the global ~/.citadel/ (deployments.db, registry.yml), which holds cross-project data.

Index

Constants

View Source
const (
	StatusInProgress = "in_progress"
	StatusSuccess    = "success"
	StatusFailed     = "failed"
	StatusSkipped    = "skipped"
)

Run and step statuses written to run.json and state/<env>.json.

View Source
const DirName = ".citadel"

DirName is the project directory created next to citadel.yml.

View Source
const MaxRuns = 50

MaxRuns is how many run folders NewRun keeps under .citadel/runs/.

Variables

This section is empty.

Functions

func WriteFileAtomic

func WriteFileAtomic(path string, data []byte) error

WriteFileAtomic writes data to path via a temp file in the same directory and a rename, so readers never observe a partially written file and an interrupted write leaves the previous content intact.

Types

type Dir

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

Dir is an opened .citadel/ directory.

func Existing

func Existing(configDir string) (*Dir, error)

Existing returns the .citadel/ directory inside configDir without creating anything. The error wraps os.ErrNotExist when there is none.

func Open

func Open(configDir string) (*Dir, error)

Open returns the .citadel/ directory inside configDir, creating it and its .gitignore when missing. It is idempotent and never rewrites an existing .gitignore, so users may add their own lines.

func (*Dir) EnsureProject

func (d *Dir) EnsureProject(m Meta) (*Meta, bool, error)

EnsureProject returns the existing project.yml, or writes m when there is none. created reports whether m was written.

func (*Dir) NewRun

func (d *Dir) NewRun(info RunInfo, term io.Writer) (*Run, error)

NewRun creates a new run folder, writes its initial run.json and prunes runs beyond MaxRuns. term receives step output alongside the log files.

func (*Dir) Path

func (d *Dir) Path() string

Path returns the absolute or relative path of the .citadel/ directory.

func (*Dir) Project

func (d *Dir) Project() (*Meta, error)

Project reads project.yml. The error wraps os.ErrNotExist when it is missing.

func (*Dir) ReadState

func (d *Dir) ReadState(env string) (*State, error)

ReadState reads state/<env>.json. The error wraps os.ErrNotExist when env has never been deployed from this checkout.

func (*Dir) WriteProject

func (d *Dir) WriteProject(m Meta) error

WriteProject atomically writes project.yml.

func (*Dir) WriteState

func (d *Dir) WriteState(env string, s State) error

WriteState atomically writes state/<env>.json.

type Meta

type Meta struct {
	ID          string    `yaml:"id"`
	Name        string    `yaml:"name"`
	Runtime     string    `yaml:"runtime"`
	CreatedAt   time.Time `yaml:"created_at"`
	CreatedWith string    `yaml:"created_with"`
}

Meta is the committed project.yml. Fields may be added over time but never removed; unknown fields are ignored on read.

func NewMeta

func NewMeta(name, runtime, version string, now time.Time) Meta

NewMeta returns metadata for a new project with a fresh random id. The id is the project's stable identity, independent of name changes.

type Run

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

Run records one deploy under .citadel/runs/<id>/: run.json plus one NN-<step>.log per executed step. Logging is best-effort: the first I/O failure prints a single warning to the terminal and the Run carries on writing to the terminal only. A terminal-only Run (TerminalRun) records nothing on disk.

func TerminalRun

func TerminalRun(term io.Writer) *Run

TerminalRun returns a Run that sends step output to term only and records nothing on disk. Used for --dry-run and when .citadel/ is unavailable.

func (*Run) Dir

func (r *Run) Dir() string

Dir returns the run folder, or "" when nothing is recorded on disk.

func (*Run) Finish

func (r *Run) Finish(err error, st State)

Finish records the outcome in run.json and state/<env>.json, filling st's RunID, Status, GitSHA and times. Only the first call has effect, so callers can both defer it and call it early (e.g. before blocking on log streaming).

func (*Run) ID

func (r *Run) ID() string

ID returns the run id, or "" for a terminal-only run.

func (*Run) Skip

func (r *Run) Skip(name string)

Skip records a step that did not run. It gets no number and no log file.

func (*Run) Step

func (r *Run) Step(name string) *Step

Step starts a named step. Its Out() writer mirrors to the terminal and to NN-<name>.log, where NN counts executed steps from 01.

type RunInfo

type RunInfo struct {
	Env     string
	Message string
	GitSHA  string
}

RunInfo describes the deploy a Run records.

type State

type State struct {
	RunID      string    `json:"run_id"`
	Status     string    `json:"status"`
	GitSHA     string    `json:"git_sha"`
	ImageURI   string    `json:"image_uri"`
	Target     string    `json:"target"`
	DeployedBy string    `json:"deployed_by"`
	StartedAt  time.Time `json:"started_at"`
	FinishedAt time.Time `json:"finished_at"`
}

State is the last deploy of one environment from this checkout, stored in .citadel/state/<env>.json (git-ignored).

type Step

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

Step is one named stage of a Run.

func (*Step) End

func (s *Step) End(err error)

End closes the step's log and records its status and duration. Only the first call has effect.

func (*Step) Out

func (s *Step) Out() io.Writer

Out is where the step writes its output.

type StepRecord

type StepRecord struct {
	Name       string     `json:"name"`
	Status     string     `json:"status"`
	StartedAt  *time.Time `json:"started_at,omitempty"`
	DurationMS int64      `json:"duration_ms"`
	Error      string     `json:"error,omitempty"`
}

StepRecord is one entry of run.json's steps list.

Jump to

Keyboard shortcuts

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