release

package
v0.0.0-...-a4ce6f4 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Overview

Package release — assets.go orchestrates cross-compilation for Go projects.

Package release — assetsbuild.go contains low-level build helpers for cross-compilation targets.

Package release — assetstargets.go defines the default cross-compile target matrix.

Package release — assetsupload.go uploads release assets via GitHub API.

Package release handles version parsing, release workflows, GitHub integration, and release metadata management.

Package release — checksums.go generates SHA256 checksums for release assets.

Package release — compress.go wraps release assets in archives. Windows assets → .zip, Linux/macOS assets → .tar.gz.

Package release — compresstar.go handles tar.gz archive creation.

Package release — deflate.go provides a max-compression Deflate writer.

Package release handles version parsing, release workflows, and release metadata management.

Package release — githubapi.go provides GitHub API types and helpers.

Package release handles version parsing, release workflows, GitHub integration, and release metadata management.

Package release — installsnippet.go appends a pinned-version installer snippet to the GitHub release body so users who copy the snippet from the release page install EXACTLY that tag, never auto-resolving "latest".

Spec: spec/04-release/08-pinned-version-install-snippet.md

Package release handles version parsing, release workflows, GitHub integration, and release metadata management.

Package release — remoteorigin.go parses git remote origin URLs.

Package release handles version parsing, release workflows, GitHub integration, and release metadata management.

Package release handles version parsing, release workflows, GitHub integration, and release metadata management.

Package release — workflowreleasescript.go bakes the version into copies of release-version.ps1 / release-version.sh and writes them into the staging directory so they ship as per-release snapshot install assets.

Spec: spec/01-app/105-release-version-script.md

Package release — ziparchive.go creates ZIP archives from zip groups with maximum compression (Deflate level 9) for release assets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendPinnedInstallSnippet

func AppendPinnedInstallSnippet(body, tag string) string

AppendPinnedInstallSnippet returns the release body with a markdown section appended that contains PowerShell + bash one-liners pinned to the given tag. Idempotent: if the body already ends with a snippet for the same tag, it is returned unchanged.

func BinaryName

func BinaryName(moduleName string) string

BinaryName extracts the short name from a Go module path. "github.com/alimtvnetwork/gitmap-v9/gitmap" → "gitmap"

func BranchExists

func BranchExists(branch string) bool

BranchExists checks if a local branch exists.

func BuildAdHocArchive

func BuildAdHocArchive(paths []string, bundleName, stagingDir string) []string

BuildAdHocArchive creates a ZIP from ad-hoc paths provided via -Z flags. If bundleName is set, all items go into one archive; otherwise each gets its own archive.

func BuildZipGroupArchives

func BuildZipGroupArchives(db *store.DB, groupNames []string, stagingDir string) []string

BuildZipGroupArchives resolves persistent zip groups from the DB and creates max-compression ZIP archives for each. Returns archive paths.

func CheckoutBranch

func CheckoutBranch(branch string) error

CheckoutBranch checks out an existing branch.

func CleanupStagingDir

func CleanupStagingDir()

CleanupStagingDir removes the staging directory after upload.

func CollectAssets

func CollectAssets(assetsPath string) []string

CollectAssets gathers file paths for release attachment.

func CollectSuccessfulBuilds

func CollectSuccessfulBuilds(results []CrossCompileResult) []string

CollectSuccessfulBuilds filters cross-compile results to only successful outputs.

func CommitExists

func CommitExists(sha string) bool

CommitExists checks if a commit SHA is valid.

func CompressAssets

func CompressAssets(assets []string) ([]string, error)

CompressAssets wraps each file in assets into an archive. Windows binaries (.exe) → .zip, others → .tar.gz. Returns the list of archive paths (originals are removed).

func CreateBranch

func CreateBranch(branchName, sourceRef string) error

CreateBranch creates a release branch from the given source ref.

func CreateBranchFromSHA

func CreateBranchFromSHA(branchName, sha string) error

CreateBranchFromSHA creates a branch at a specific commit without checkout.

func CreateTag

func CreateTag(tag, message string) error

CreateTag creates an annotated git tag.

func CurrentBranchName

func CurrentBranchName() (string, error)

CurrentBranchName returns the current branch name.

func CurrentCommitSHA

func CurrentCommitSHA() (string, error)

CurrentCommitSHA returns the full SHA of HEAD.

func DeleteLocalBranch

func DeleteLocalBranch(branch string) error

DeleteLocalBranch deletes a local branch.

func DeleteRemoteBranches

func DeleteRemoteBranches(branches []string) error

DeleteRemoteBranches deletes multiple branches from the remote.

func DescribeCompression

func DescribeCompression(assets []string) []string

DescribeCompression returns human-readable archive names for dry-run.

func DescribeTargets

func DescribeTargets(binName, version string, targets []BuildTarget) []string

DescribeTargets returns human-readable names for dry-run output.

func DetectChangelog

func DetectChangelog() string

DetectChangelog returns the content of CHANGELOG.md if it exists.

func DetectGoProject

func DetectGoProject() bool

DetectGoProject checks if the current directory contains a buildable Go project.

func DetectReadme

func DetectReadme() string

DetectReadme returns the path to README.md if it exists.

func DryRunAdHoc

func DryRunAdHoc(paths []string, bundleName string)

DryRunAdHoc prints what ad-hoc zip items would produce without creating them.

func DryRunZipGroups

func DryRunZipGroups(db *store.DB, groupNames []string)

DryRunZipGroups prints what zip groups would produce without creating them.

func EnsureGitignore

func EnsureGitignore()

EnsureGitignore appends missing release-related entries to .gitignore.

func EnsureStagingDir

func EnsureStagingDir() (string, error)

EnsureStagingDir creates the release-assets staging directory.

func Execute

func Execute(opts Options) error

Execute runs the full release workflow.

func ExecuteFromBranch

func ExecuteFromBranch(branchName, assetsPath, notes string, isDraft, dryRun, noCommit, yes bool) error

ExecuteFromBranch runs the release workflow from an existing release branch.

func ExecutePending

func ExecutePending(assetsPath, notes string, isDraft, dryRun, noCommit, yes bool) error

ExecutePending finds all release branches without tags and releases them. Also discovers unreleased versions from .gitmap/release/v*.json metadata files.

func ExecuteSelf

func ExecuteSelf(opts Options) error

ExecuteSelf resolves the gitmap source repo, switches to that directory, runs Execute, then returns to the original dir.

func FetchBranch

func FetchBranch(branch string) error

FetchBranch fetches the latest of a remote branch.

func FindMainPackages

func FindMainPackages() []string

FindMainPackages locates buildable main package directories. Checks root main.go first, then cmd/ subdirectories.

func FormatChangelogSection

func FormatChangelogSection(version string, commits []string) string

FormatChangelogSection formats commits as a markdown changelog section.

func GenerateChangelog

func GenerateChangelog(fromTag, toRef string) ([]string, error)

GenerateChangelog returns commit subjects between two tags (or from a tag to HEAD).

func GenerateChecksums

func GenerateChecksums(assets []string) (string, error)

GenerateChecksums computes SHA256 hashes for all assets and writes a checksums.txt file in the same directory as the first asset. Returns the path to the checksums file.

func IsInsideGitRepo

func IsInsideGitRepo() bool

IsInsideGitRepo checks if the current directory is inside a Git repository.

func ListTags

func ListTags() ([]string, error)

ListTags returns all version tags sorted descending by version.

func ListTempReleaseBranches

func ListTempReleaseBranches() ([]string, error)

ListTempReleaseBranches returns all local branches matching temp-release/*.

func NormalizeVersion

func NormalizeVersion(version string) string

NormalizeVersion normalizes a changelog version string to v-prefixed form.

func ParseGitURLExported

func ParseGitURLExported(url string) (string, string, error)

parseGitURL extracts owner/repo from HTTPS or SSH git URLs. ParseGitURLExported is the exported alias for testing.

func ParseRemoteOrigin

func ParseRemoteOrigin() (string, string, error)

ParseRemoteOrigin extracts owner/repo from the git remote origin URL.

func PushBranchAndTag

func PushBranchAndTag(branchName, tag string) error

PushBranchAndTag pushes the branch and tag to origin.

func PushBranches

func PushBranches(branches []string) error

PushBranches pushes multiple branches to origin in a single command.

func ReadModuleName

func ReadModuleName() (string, error)

ReadModuleName reads the module name from go.mod.

func ReadVersionFile

func ReadVersionFile() (string, error)

ReadVersionFile reads version.json from the project root.

func ReleaseExists

func ReleaseExists(version Version) bool

ReleaseExists checks if a release metadata file already exists.

func ResolveSourceRef

func ResolveSourceRef(commit, branch string) (string, string, error)

ResolveSourceRef returns the ref to use as the release base.

func ResolveTagRange

func ResolveTagRange(fromTag, toTag string) (string, string, error)

ResolveTagRange determines the from/to refs based on user input.

func Rollback

func Rollback(branchName, tag, originalBranch string)

Rollback deletes a local branch and tag after a failed push.

func ShouldPrintInstallHint

func ShouldPrintInstallHint(remoteURL string) bool

ShouldPrintInstallHint returns true if the remote URL matches the gitmap source repository prefix.

func TagExistsLocally

func TagExistsLocally(tag string) bool

TagExistsLocally checks if a git tag exists in the local repo.

func TagExistsRemote

func TagExistsRemote(tag string) bool

TagExistsRemote checks if a git tag exists on the remote.

func UploadAllAssets

func UploadAllAssets(owner, repo string, releaseID int, assets []string, token string)

UploadAllAssets uploads all assets to a GitHub release with exponential backoff retry.

func UploadAsset

func UploadAsset(owner, repo string, releaseID int, filePath, token string) error

UploadAsset uploads a single file to a GitHub release.

func WriteLatest

func WriteLatest(v Version) error

WriteLatest updates .gitmap/release/latest.json if the version is the highest stable.

func WriteReleaseMeta

func WriteReleaseMeta(meta ReleaseMeta) error

WriteReleaseMeta writes release metadata to .gitmap/release/vX.Y.Z.json.

Types

type AutoCommitResult

type AutoCommitResult struct {
	Committed bool
	AllFiles  bool
	Message   string
}

AutoCommitResult describes what happened during auto-commit.

func AutoCommit

func AutoCommit(version string, dryRun, yes bool) AutoCommitResult

AutoCommit inspects working tree changes after returning to the original branch. If only .gitmap/release/ files changed, it commits and pushes silently. If other files also changed, it prompts the user (or auto-confirms with yes=true). On decline, it commits only .gitmap/release/.

type BuildTarget

type BuildTarget struct {
	GOOS   string `json:"goos"`
	GOARCH string `json:"goarch"`
}

BuildTarget represents a single GOOS/GOARCH pair for cross-compilation.

func DefaultTargets

func DefaultTargets() []BuildTarget

DefaultTargets returns the standard 6-target cross-compilation matrix.

func ParseTargets

func ParseTargets(input string) ([]BuildTarget, error)

ParseTargets parses a comma-separated "os/arch" string into BuildTargets. Example: "windows/amd64,linux/arm64"

func ResolveTargets

func ResolveTargets(flagTargets string, configTargets []model.ReleaseTarget) ([]BuildTarget, error)

ResolveTargets determines the final target list using three-layer config: CLI flag (highest) → config.json release.targets (middle) → defaults (lowest).

type ChangelogBullet

type ChangelogBullet struct {
	Depth   int
	Ordered bool
	Marker  string // "-", "*", or "1." — preserved for ordered numbering
	Text    string
}

ChangelogBullet represents a single bullet line with its indent depth and whether it was an ordered-list item. Depth 0 = top-level, 1 = nested, etc.

type ChangelogEntry

type ChangelogEntry struct {
	Version string
	Title   string
	Notes   []string
	Bullets []ChangelogBullet
}

ChangelogEntry represents one version section in CHANGELOG.md.

Notes is preserved for backward compatibility (flat top-level bullets). Title and Bullets are populated by the new structured parser used by the pretty-printed `changelog --latest` console output.

func FindChangelogEntry

func FindChangelogEntry(entries []ChangelogEntry, version string) (ChangelogEntry, bool)

FindChangelogEntry returns a changelog entry by version.

func ReadChangelog

func ReadChangelog() ([]ChangelogEntry, error)

ReadChangelog reads concise changelog entries from CHANGELOG.md.

type CrossCompileResult

type CrossCompileResult struct {
	Target  BuildTarget
	Output  string
	Success bool
	Error   string
}

CrossCompileResult holds the outcome of a cross-compile step.

func CrossCompile

func CrossCompile(version string, targets []BuildTarget, packages []string, stagingDir string) []CrossCompileResult

CrossCompile builds binaries for all targets and packages. Returns the list of successfully built binary paths.

type GitHubRelease

type GitHubRelease struct {
	ID        int    `json:"id"`
	UploadURL string `json:"upload_url"`
}

GitHubRelease represents the response from creating a GitHub release.

func CreateGitHubRelease

func CreateGitHubRelease(owner, repo, tag, name, body, token string, draft bool) (*GitHubRelease, error)

CreateGitHubRelease creates a release via the GitHub API and returns the release ID.

type LatestMeta

type LatestMeta struct {
	Version string `json:"version"`
	Tag     string `json:"tag"`
	Branch  string `json:"branch"`
}

LatestMeta holds the pointer to the latest stable release.

func ReadLatest

func ReadLatest() (LatestMeta, error)

ReadLatest reads .gitmap/release/latest.json.

type Options

type Options struct {
	Version       string
	Assets        string
	Commit        string
	Branch        string
	Bump          string
	Notes         string
	Targets       string
	ConfigTargets []model.ReleaseTarget
	ZipGroups     []string
	ZipItems      []string
	BundleName    string
	IsDraft       bool
	DryRun        bool
	Verbose       bool
	Compress      bool
	Checksums     bool
	Bin           bool
	NoCommit      bool
	SkipMeta      bool
	Yes           bool
}

Options holds all parameters for a release operation. v15: boolean fields use the IsX prefix convention.

type ReleaseMeta

type ReleaseMeta struct {
	Version           string            `json:"version"`
	Branch            string            `json:"branch"`
	SourceBranch      string            `json:"sourceBranch"`
	Commit            string            `json:"commit"`
	Tag               string            `json:"tag"`
	Assets            []string          `json:"assets"`
	Changelog         []string          `json:"changelog,omitempty"`
	Notes             string            `json:"notes,omitempty"`
	ZipGroups         []string          `json:"zipGroups,omitempty"`
	ZipGroupChecksums map[string]string `json:"zipGroupChecksums,omitempty"`
	IsDraft           bool              `json:"isDraft"`
	IsPreRelease      bool              `json:"isPreRelease"`
	CreatedAt         string            `json:"createdAt"`
	IsLatest          bool              `json:"isLatest"`
}

ReleaseMeta holds metadata for a single release. v15: boolean fields use the IsX prefix convention. ReadReleaseMeta below adds backward-compat aliases so old "draft"/"preRelease" JSON files load without breakage; new files are written using the IsX form.

var LastMeta *ReleaseMeta

LastMeta holds the most recent release metadata after Execute completes.

func ListReleaseMetaFiles

func ListReleaseMetaFiles() ([]ReleaseMeta, error)

ListReleaseMetaFiles reads all .gitmap/release/v*.json files and returns parsed metadata.

func ReadReleaseMeta

func ReadReleaseMeta(path string) (ReleaseMeta, error)

ReadReleaseMeta reads and unmarshals a single .gitmap/release/vX.Y.Z.json file. Provides backward-compat for the pre-v15 "draft" / "preRelease" JSON keys by overlaying a legacy struct after the primary unmarshal.

type Result

type Result struct {
	Version    Version
	BranchName string
	Tag        string
	Commit     string
	Source     string
	Assets     []string
}

Result holds the outcome of a release operation.

type TagEntry

type TagEntry struct {
	Tag       string
	CreatedAt string
}

TagEntry holds a parsed git tag name and its creation date.

func ListVersionTags

func ListVersionTags() []TagEntry

ListVersionTags returns all semver tags with their creation dates.

type TempReleaseCommit

type TempReleaseCommit struct {
	SHA     string
	Short   string
	Message string
}

TempReleaseCommit holds commit info for temp-release branch creation.

func ListRecentCommits

func ListRecentCommits(count int) ([]TempReleaseCommit, error)

ListRecentCommits returns the last N commits from HEAD (oldest first).

type Version

type Version struct {
	Major      int
	Minor      int
	Patch      int
	PreRelease string
	Raw        string
}

Version represents a parsed semantic version.

func Bump

func Bump(v Version, level string) (Version, error)

Bump increments the version by the given level (major, minor, patch).

func Parse

func Parse(input string) (Version, error)

Parse parses a version string into a Version struct. Accepts formats: v1, v1.2, v1.2.3, v1.2.3-rc.1

func (Version) CoreString

func (v Version) CoreString() string

CoreString returns the version without v prefix (e.g. 1.2.3).

func (Version) GreaterThan

func (v Version) GreaterThan(other Version) bool

GreaterThan returns true if v is strictly greater than other.

func (Version) IsPreRelease

func (v Version) IsPreRelease() bool

IsPreRelease returns true if the version has a pre-release suffix.

func (Version) String

func (v Version) String() string

String returns the padded version with v prefix (e.g. v1.2.3).

type VersionFile

type VersionFile struct {
	Version string `json:"version"`
}

VersionFile represents the version.json file format.

type ZipGroupArchive

type ZipGroupArchive struct {
	GroupName   string
	ArchivePath string
	ItemCount   int
}

ZipGroupArchive holds the result of archiving a zip group.

Jump to

Keyboard shortcuts

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