deploy

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package deploy publishes the built site to a git remote. It keeps a local repository at ~/.cache/npub/<repo>/git and uses the build output at ~/.cache/npub/<repo>/build as a temporary work-tree (via git's --git-dir and --work-tree options), so the site is never copied into a separate working copy. It never clones the remote in full: by default it fetches only the current branch tip (shallow) to commit onto.

By default a deploy is non-destructive: it appends a commit onto the remote's branch tip and pushes normally. With Options.Force it instead builds a single root commit from the build output and force-pushes it, replacing the remote's history with one revision — useful when the deploy repo is pure transport and its history is not worth keeping.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDir

func BuildDir(cacheDir string) string

BuildDir returns the build subdirectory of cacheDir, where `npub build` writes the rendered site. cacheDir is the per-site cache directory resolved by the caller.

func CacheRoot

func CacheRoot() (string, error)

CacheRoot returns the root directory used for deploy artifacts.

func Commit

func Commit(gitDir, buildDir, message string, opt Options) (bool, error)

Commit captures the entire contents of buildDir as a new commit and points HEAD at it. The index is rebuilt from scratch each time so files removed since the last deploy drop out of the published tree. With opt.Force the commit is a parentless root (collapsing history to one revision); otherwise it is a child of the current HEAD (the remote tip Prepare positioned). Returns false (no commit) when the build output matches HEAD's tree, so an unchanged build is a no-op rather than an empty push.

func DefaultCacheDir

func DefaultCacheDir(repoURL string) (string, error)

DefaultCacheDir returns the conventional per-repo cache directory for repoURL, ~/.cache/npub/<repo>. Callers may pass any directory to BuildDir and GitDir; this is just the default when no override is configured.

func GitDir

func GitDir(cacheDir string) string

GitDir returns the git subdirectory of cacheDir, where `npub deploy` initializes a local repository on first use.

func LockPath added in v0.2.17

func LockPath(cacheDir string) string

LockPath returns the sentinel file used to serialize cache-mutating npub commands for a cache directory.

func Prepare

func Prepare(repoURL, gitDir, buildDir string, opt Options) error

Prepare validates buildDir and ensures gitDir is a local repository wired to repoURL as origin. On first use it runs `git init`; on subsequent runs it verifies origin still points at repoURL. Unless opt.Force is set, it then shallow-fetches the remote's current branch tip and positions HEAD there, so the commit Commit builds lands as that tip's child. With opt.Force it skips the fetch, leaving HEAD where it is so Commit can build a fresh root commit.

func Push

func Push(gitDir string, opt Options) error

Push publishes HEAD to origin's default branch. A normal deploy pushes fast-forward; with opt.Force it force-pushes, replacing whatever the remote held with the single root commit Commit built.

func RepoSlug

func RepoSlug(repoURL string) string

RepoSlug derives a directory name from a git repository URL. It strips a trailing ".git" and returns the final path component, suitable as a local directory name.

Types

type Lock added in v0.2.17

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

Lock is an exclusive npub cache lock. Call Release when the cache operation is finished.

func AcquireLock added in v0.2.17

func AcquireLock(cacheDir string) (*Lock, error)

AcquireLock takes an exclusive, non-blocking lock for cacheDir. It fails fast when another npub process already holds the same cache lock.

func (*Lock) Release added in v0.2.17

func (l *Lock) Release() error

Release unlocks and closes the lock file.

type Options

type Options struct {
	Stdout io.Writer
	Stderr io.Writer
	// Force collapses the deploy to a single root commit and force-pushes it,
	// replacing the remote's history. When false (the default), deploy appends
	// a commit onto the remote's current branch tip and pushes normally.
	Force bool
}

Options controls Prepare, Commit, and Push.

Jump to

Keyboard shortcuts

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