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 ¶
- func BuildDir(cacheDir string) string
- func CacheRoot() (string, error)
- func Commit(gitDir, buildDir, message string, opt Options) (bool, error)
- func DefaultCacheDir(repoURL string) (string, error)
- func GitDir(cacheDir string) string
- func LockPath(cacheDir string) string
- func Prepare(repoURL, gitDir, buildDir string, opt Options) error
- func Push(gitDir string, opt Options) error
- func RepoSlug(repoURL string) string
- type Lock
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildDir ¶
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 Commit ¶
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 ¶
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 ¶
GitDir returns the git subdirectory of cacheDir, where `npub deploy` initializes a local repository on first use.
func LockPath ¶ added in v0.2.17
LockPath returns the sentinel file used to serialize cache-mutating npub commands for a cache directory.
func Prepare ¶
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.
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
AcquireLock takes an exclusive, non-blocking lock for cacheDir. It fails fast when another npub process already holds the same cache lock.
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.