| | | 1 | | package domain |
| | | 2 | | |
| | | 3 | | import ( |
| | | 4 | | "slices" |
| | | 5 | | "strings" |
| | | 6 | | ) |
| | | 7 | | |
| | | 8 | | // Config holds all configuration for the release process. |
| | | 9 | | type Config struct { |
| | | 10 | | // Core settings. |
| | | 11 | | ReleaseMode ReleaseMode `mapstructure:"release_mode"` |
| | | 12 | | TagFormat string `mapstructure:"tag_format"` |
| | | 13 | | ProjectTagFormat string `mapstructure:"project_tag_format"` |
| | | 14 | | DryRun bool `mapstructure:"dry_run"` |
| | | 15 | | CI bool `mapstructure:"ci"` |
| | | 16 | | Debug bool `mapstructure:"debug"` |
| | | 17 | | RepositoryURL string `mapstructure:"repository_url"` |
| | | 18 | | |
| | | 19 | | // Branch and version policies. |
| | | 20 | | Branches []BranchPolicy `mapstructure:"branches"` |
| | | 21 | | CommitTypes map[string]ReleaseType `mapstructure:"commit_types"` |
| | | 22 | | |
| | | 23 | | // Project/monorepo settings. |
| | | 24 | | Projects []ProjectConfig `mapstructure:"projects"` |
| | | 25 | | DiscoverModules bool `mapstructure:"discover_modules"` |
| | | 26 | | DiscoverCmd bool `mapstructure:"discover_cmd"` |
| | | 27 | | IncludePaths []string `mapstructure:"include_paths"` |
| | | 28 | | ExcludePaths []string `mapstructure:"exclude_paths"` |
| | | 29 | | DependencyPropagation bool `mapstructure:"dependency_propagation"` |
| | | 30 | | |
| | | 31 | | // Changelog settings. |
| | | 32 | | ChangelogSections []ChangelogSectionConfig `mapstructure:"changelog_sections"` |
| | | 33 | | ChangelogTemplate string `mapstructure:"changelog_template"` |
| | | 34 | | |
| | | 35 | | // Prepare step settings. |
| | | 36 | | Prepare PrepareConfig `mapstructure:"prepare"` |
| | | 37 | | |
| | | 38 | | // Git settings for pre-tag commits (staging assets, commit message). |
| | | 39 | | Git GitConfig `mapstructure:"git"` |
| | | 40 | | |
| | | 41 | | // Git identity for automated commits. |
| | | 42 | | GitAuthor GitIdentity `mapstructure:"git_author"` |
| | | 43 | | GitCommitter GitIdentity `mapstructure:"git_committer"` |
| | | 44 | | |
| | | 45 | | // GitHub integration. |
| | | 46 | | GitHub GitHubConfig `mapstructure:"github"` |
| | | 47 | | |
| | | 48 | | // GitLab integration. |
| | | 49 | | GitLab GitLabConfig `mapstructure:"gitlab"` |
| | | 50 | | |
| | | 51 | | // Bitbucket integration. |
| | | 52 | | Bitbucket BitbucketConfig `mapstructure:"bitbucket"` |
| | | 53 | | |
| | | 54 | | // Commit linting. |
| | | 55 | | Lint LintConfig `mapstructure:"lint"` |
| | | 56 | | |
| | | 57 | | // Interactive mode. nil means unset (treated as false by IsInteractive). |
| | | 58 | | Interactive *bool `mapstructure:"interactive"` |
| | | 59 | | |
| | | 60 | | // Git backend: "cli" (default) or "go-git". |
| | | 61 | | GitBackend string `mapstructure:"git_backend"` |
| | | 62 | | |
| | | 63 | | // Plugin references for external plugin loading. |
| | | 64 | | Plugins []string `mapstructure:"plugins"` |
| | | 65 | | |
| | | 66 | | // Extends allows inheriting from shared configurations. |
| | | 67 | | Extends []string `mapstructure:"extends"` |
| | | 68 | | } |
| | | 69 | | |
| | | 70 | | // GitLabConfig holds GitLab-specific settings. |
| | | 71 | | type GitLabConfig struct { |
| | | 72 | | ProjectID string `mapstructure:"project_id"` |
| | | 73 | | // Token is the GitLab personal access token. SENSITIVE: do not log this field. |
| | | 74 | | Token string `mapstructure:"token"` |
| | | 75 | | APIURL string `mapstructure:"api_url"` |
| | | 76 | | CreateRelease bool `mapstructure:"create_release"` |
| | | 77 | | Assets []string `mapstructure:"assets"` |
| | | 78 | | Milestones []string `mapstructure:"milestones"` |
| | | 79 | | } |
| | | 80 | | |
| | | 81 | | // BitbucketConfig holds Bitbucket-specific settings. |
| | | 82 | | type BitbucketConfig struct { |
| | | 83 | | Workspace string `mapstructure:"workspace"` |
| | | 84 | | RepoSlug string `mapstructure:"repo_slug"` |
| | | 85 | | // Token is the Bitbucket access token. SENSITIVE: do not log this field. |
| | | 86 | | Token string `mapstructure:"token"` |
| | | 87 | | APIURL string `mapstructure:"api_url"` |
| | | 88 | | CreateRelease bool `mapstructure:"create_release"` |
| | | 89 | | } |
| | | 90 | | |
| | | 91 | | // PrepareConfig holds settings for the prepare lifecycle step. |
| | | 92 | | type PrepareConfig struct { |
| | | 93 | | ChangelogFile string `mapstructure:"changelog_file"` |
| | | 94 | | VersionFile string `mapstructure:"version_file"` |
| | | 95 | | AdditionalFiles []string `mapstructure:"additional_files"` |
| | | 96 | | Command string `mapstructure:"command"` |
| | | 97 | | VersionFiles []string `mapstructure:"version_files"` |
| | | 98 | | } |
| | | 99 | | |
| | | 100 | | // GitConfig holds settings for git operations performed during the release workflow. |
| | | 101 | | type GitConfig struct { |
| | | 102 | | Assets []string `mapstructure:"assets"` |
| | | 103 | | Message string `mapstructure:"message"` |
| | | 104 | | } |
| | | 105 | | |
| | | 106 | | // VersionFileEntry holds a parsed version_files entry. |
| | | 107 | | type VersionFileEntry struct { |
| | | 108 | | Path string // file path relative to repository root |
| | | 109 | | KeyPath string // dot-separated TOML key path; empty for plain-text files |
| | | 110 | | } |
| | | 111 | | |
| | | 112 | | // ParseVersionFileEntry parses a version_files entry of the form "path" or "path:key.path". |
| | | 113 | | // A trailing colon (e.g. "some.toml:") is treated as an empty key path. |
| | | 114 | | func ParseVersionFileEntry(entry string) VersionFileEntry { |
| | | 115 | | i := strings.Index(entry, ":") |
| | | 116 | | if i < 0 { |
| | | 117 | | return VersionFileEntry{Path: entry} |
| | | 118 | | } |
| | | 119 | | return VersionFileEntry{Path: entry[:i], KeyPath: entry[i+1:]} |
| | | 120 | | } |
| | | 121 | | |
| | | 122 | | // ProjectConfig defines a project in the configuration file. |
| | | 123 | | type ProjectConfig struct { |
| | | 124 | | Name string `mapstructure:"name"` |
| | | 125 | | Path string `mapstructure:"path"` |
| | | 126 | | TagPrefix string `mapstructure:"tag_prefix"` |
| | | 127 | | Dependencies []string `mapstructure:"dependencies"` |
| | | 128 | | ChangelogFile string `mapstructure:"changelog_file"` // per-project changelog filename, relative to the project's pa |
| | | 129 | | } |
| | | 130 | | |
| | | 131 | | // GitHubAsset represents a release asset to upload, with an optional display label. |
| | | 132 | | // Both YAML forms are supported: |
| | | 133 | | // |
| | | 134 | | // # simple string — label is empty |
| | | 135 | | // assets: |
| | | 136 | | // - dist/*.tar.gz |
| | | 137 | | // |
| | | 138 | | // # structured — label appears as the download name on the GitHub release page |
| | | 139 | | // assets: |
| | | 140 | | // - path: dist/*.tar.gz |
| | | 141 | | // label: Source Tarballs |
| | | 142 | | type GitHubAsset struct { |
| | | 143 | | // Path is a glob pattern (relative to the repository root) matching the files to upload. |
| | | 144 | | Path string `mapstructure:"path"` |
| | | 145 | | // Label is the display name shown on the GitHub release page. Empty means the filename is used. |
| | | 146 | | Label string `mapstructure:"label"` |
| | | 147 | | } |
| | | 148 | | |
| | | 149 | | // GitHubConfig holds GitHub-specific settings. |
| | | 150 | | type GitHubConfig struct { |
| | | 151 | | Owner string `mapstructure:"owner"` |
| | | 152 | | Repo string `mapstructure:"repo"` |
| | | 153 | | // Token is the GitHub personal access token. SENSITIVE: do not log this field. |
| | | 154 | | Token string `mapstructure:"token"` |
| | | 155 | | APIURL string `mapstructure:"api_url"` |
| | | 156 | | CreateRelease bool `mapstructure:"create_release"` |
| | | 157 | | DraftRelease bool `mapstructure:"draft_release"` |
| | | 158 | | Assets []GitHubAsset `mapstructure:"assets"` |
| | | 159 | | SuccessComment string `mapstructure:"success_comment"` |
| | | 160 | | FailComment string `mapstructure:"fail_comment"` |
| | | 161 | | ReleasedLabels []string `mapstructure:"released_labels"` |
| | | 162 | | FailLabels []string `mapstructure:"fail_labels"` |
| | | 163 | | DiscussionCategoryName string `mapstructure:"discussion_category_name"` |
| | | 164 | | } |
| | | 165 | | |
| | | 166 | | // AnyProjectDefinesChangelog reports whether any configured project has a per-project changelog_file set. |
| | 4 | 167 | | func (c Config) AnyProjectDefinesChangelog() bool { |
| | 4 | 168 | | return slices.ContainsFunc(c.Projects, func(p ProjectConfig) bool { |
| | 4 | 169 | | return p.ChangelogFile != "" |
| | 4 | 170 | | }) |
| | | 171 | | } |
| | | 172 | | |
| | | 173 | | // IsInteractive returns whether interactive mode is enabled. |
| | | 174 | | // Defaults to false when the Interactive field has not been set. |
| | 3 | 175 | | func (c Config) IsInteractive() bool { |
| | 3 | 176 | | return c.Interactive != nil && *c.Interactive |
| | 3 | 177 | | } |
| | | 178 | | |
| | | 179 | | // DefaultConfig returns sensible default configuration. |
| | | 180 | | func DefaultConfig() Config { |
| | | 181 | | return Config{ |
| | | 182 | | ReleaseMode: ReleaseModeRepo, |
| | | 183 | | TagFormat: "v{{.Version}}", |
| | | 184 | | ProjectTagFormat: "{{.Project}}/v{{.Version}}", |
| | | 185 | | DryRun: false, |
| | | 186 | | CI: true, |
| | | 187 | | Branches: DefaultBranchPolicies(), |
| | | 188 | | CommitTypes: DefaultCommitTypeMapping(), |
| | | 189 | | ChangelogSections: DefaultChangelogSections(), |
| | | 190 | | DiscoverModules: false, |
| | | 191 | | DiscoverCmd: false, |
| | | 192 | | DependencyPropagation: false, |
| | | 193 | | Lint: DefaultLintConfig(), |
| | | 194 | | GitAuthor: DefaultGitIdentity(), |
| | | 195 | | GitCommitter: DefaultGitIdentity(), |
| | | 196 | | GitBackend: "cli", |
| | | 197 | | GitHub: GitHubConfig{ |
| | | 198 | | CreateRelease: true, |
| | | 199 | | }, |
| | | 200 | | } |
| | | 201 | | } |