github.com/jasei/goreleaser@v0.62.4-0.20180312171904-62cb6a8963a6/config/config.go (about) 1 // Package config contains the model and loader of the goreleaser configuration 2 // file. 3 package config 4 5 import ( 6 "io" 7 "io/ioutil" 8 "os" 9 10 "github.com/apex/log" 11 "gopkg.in/yaml.v2" 12 ) 13 14 // GitHubURLs holds the URLs to be used when using github enterprise 15 type GitHubURLs struct { 16 API string `yaml:"api,omitempty"` 17 Upload string `yaml:"upload,omitempty"` 18 Download string `yaml:"download,omitempty"` 19 } 20 21 // Repo represents any kind of repo (github, gitlab, etc) 22 type Repo struct { 23 Owner string `yaml:",omitempty"` 24 Name string `yaml:",omitempty"` 25 } 26 27 // String of the repo, e.g. owner/name 28 func (r Repo) String() string { 29 if r.Owner == "" && r.Name == "" { 30 return "" 31 } 32 return r.Owner + "/" + r.Name 33 } 34 35 // Homebrew contains the brew section 36 type Homebrew struct { 37 Name string `yaml:",omitempty"` 38 GitHub Repo `yaml:",omitempty"` 39 CommitAuthor CommitAuthor `yaml:"commit_author,omitempty"` 40 Folder string `yaml:",omitempty"` 41 Caveats string `yaml:",omitempty"` 42 Plist string `yaml:",omitempty"` 43 Install string `yaml:",omitempty"` 44 Dependencies []string `yaml:",omitempty"` 45 Test string `yaml:",omitempty"` 46 Conflicts []string `yaml:",omitempty"` 47 Description string `yaml:",omitempty"` 48 Homepage string `yaml:",omitempty"` 49 SkipUpload bool `yaml:"skip_upload,omitempty"` 50 DownloadStrategy string `yaml:"download_strategy,omitempty"` 51 } 52 53 // Scoop contains the scoop.sh section 54 type Scoop struct { 55 Bucket Repo `yaml:",omitempty"` 56 CommitAuthor CommitAuthor `yaml:"commit_author,omitempty"` 57 Homepage string `yaml:",omitempty"` 58 Description string `yaml:",omitempty"` 59 License string `yaml:",omitempty"` 60 } 61 62 // CommitAuthor is the author of a Git commit 63 type CommitAuthor struct { 64 Name string `yaml:",omitempty"` 65 Email string `yaml:",omitempty"` 66 } 67 68 // Hooks define actions to run before and/or after something 69 type Hooks struct { 70 Pre string `yaml:",omitempty"` 71 Post string `yaml:",omitempty"` 72 } 73 74 // IgnoredBuild represents a build ignored by the user 75 type IgnoredBuild struct { 76 Goos, Goarch, Goarm string 77 } 78 79 // Build contains the build configuration section 80 type Build struct { 81 Goos []string `yaml:",omitempty"` 82 Goarch []string `yaml:",omitempty"` 83 Goarm []string `yaml:",omitempty"` 84 Targets []string `yaml:",omitempty"` 85 Ignore []IgnoredBuild `yaml:",omitempty"` 86 Main string `yaml:",omitempty"` 87 Ldflags string `yaml:",omitempty"` 88 Flags string `yaml:",omitempty"` 89 Binary string `yaml:",omitempty"` 90 Hooks Hooks `yaml:",omitempty"` 91 Env []string `yaml:",omitempty"` 92 Lang string `yaml:",omitempty"` 93 } 94 95 // FormatOverride is used to specify a custom format for a specific GOOS. 96 type FormatOverride struct { 97 Goos string `yaml:",omitempty"` 98 Format string `yaml:",omitempty"` 99 } 100 101 // Archive config used for the archive 102 type Archive struct { 103 NameTemplate string `yaml:"name_template,omitempty"` 104 Replacements map[string]string `yaml:",omitempty"` 105 106 Format string `yaml:",omitempty"` 107 FormatOverrides []FormatOverride `yaml:"format_overrides,omitempty"` 108 WrapInDirectory bool `yaml:"wrap_in_directory,omitempty"` 109 Files []string `yaml:",omitempty"` 110 } 111 112 // Release config used for the GitHub release 113 type Release struct { 114 GitHub Repo `yaml:",omitempty"` 115 Draft bool `yaml:",omitempty"` 116 Prerelease bool `yaml:",omitempty"` 117 NameTemplate string `yaml:"name_template,omitempty"` 118 } 119 120 // NFPM config 121 type NFPM struct { 122 NameTemplate string `yaml:"name_template,omitempty"` 123 Replacements map[string]string `yaml:",omitempty"` 124 125 Formats []string `yaml:",omitempty"` 126 Dependencies []string `yaml:",omitempty"` 127 Recommends []string `yaml:",omitempty"` 128 Suggests []string `yaml:",omitempty"` 129 Conflicts []string `yaml:",omitempty"` 130 Vendor string `yaml:",omitempty"` 131 Homepage string `yaml:",omitempty"` 132 Maintainer string `yaml:",omitempty"` 133 Description string `yaml:",omitempty"` 134 License string `yaml:",omitempty"` 135 Bindir string `yaml:",omitempty"` 136 Files map[string]string `yaml:",omitempty"` 137 ConfigFiles map[string]string `yaml:"config_files,omitempty"` 138 } 139 140 // Sign config 141 type Sign struct { 142 Cmd string `yaml:"cmd,omitempty"` 143 Args []string `yaml:"args,omitempty"` 144 Signature string `yaml:"signature,omitempty"` 145 Artifacts string `yaml:"artifacts,omitempty"` 146 } 147 148 // SnapcraftAppMetadata for the binaries that will be in the snap package 149 type SnapcraftAppMetadata struct { 150 Plugs []string 151 Daemon string 152 } 153 154 // Snapcraft config 155 type Snapcraft struct { 156 NameTemplate string `yaml:"name_template,omitempty"` 157 Replacements map[string]string `yaml:",omitempty"` 158 159 Name string `yaml:",omitempty"` 160 Summary string `yaml:",omitempty"` 161 Description string `yaml:",omitempty"` 162 Grade string `yaml:",omitempty"` 163 Confinement string `yaml:",omitempty"` 164 Apps map[string]SnapcraftAppMetadata `yaml:",omitempty"` 165 } 166 167 // Snapshot config 168 type Snapshot struct { 169 NameTemplate string `yaml:"name_template,omitempty"` 170 } 171 172 // Checksum config 173 type Checksum struct { 174 NameTemplate string `yaml:"name_template,omitempty"` 175 } 176 177 // Docker image config 178 type Docker struct { 179 Binary string `yaml:",omitempty"` 180 Goos string `yaml:",omitempty"` 181 Goarch string `yaml:",omitempty"` 182 Goarm string `yaml:",omitempty"` 183 Image string `yaml:",omitempty"` 184 Dockerfile string `yaml:",omitempty"` 185 Latest bool `yaml:",omitempty"` 186 OldTagTemplate string `yaml:"tag_template,omitempty"` 187 TagTemplates []string `yaml:"tag_templates,omitempty"` 188 Files []string `yaml:"extra_files,omitempty"` 189 } 190 191 // Artifactory server configuration 192 type Artifactory struct { 193 Target string `yaml:",omitempty"` 194 Name string `yaml:",omitempty"` 195 Username string `yaml:",omitempty"` 196 Mode string `yaml:",omitempty"` 197 } 198 199 // Filters config 200 type Filters struct { 201 Exclude []string `yaml:",omitempty"` 202 } 203 204 // Changelog Config 205 type Changelog struct { 206 Filters Filters `yaml:",omitempty"` 207 Sort string `yaml:",omitempty"` 208 } 209 210 // EnvFiles holds paths to files that contains environment variables 211 // values like the github token for example 212 type EnvFiles struct { 213 GitHubToken string `yaml:"github_token,omitempty"` 214 } 215 216 // Git config 217 type Git struct { 218 ShortHash bool `yaml:"short_hash,omitempty"` 219 } 220 221 // Project includes all project configuration 222 type Project struct { 223 ProjectName string `yaml:"project_name,omitempty"` 224 Release Release `yaml:",omitempty"` 225 Brew Homebrew `yaml:",omitempty"` 226 Scoop Scoop `yaml:",omitempty"` 227 Builds []Build `yaml:",omitempty"` 228 Archive Archive `yaml:",omitempty"` 229 FPM NFPM `yaml:",omitempty"` // deprecated 230 NFPM NFPM `yaml:",omitempty"` 231 Snapcraft Snapcraft `yaml:",omitempty"` 232 Snapshot Snapshot `yaml:",omitempty"` 233 Checksum Checksum `yaml:",omitempty"` 234 Dockers []Docker `yaml:",omitempty"` 235 Artifactories []Artifactory `yaml:",omitempty"` 236 Changelog Changelog `yaml:",omitempty"` 237 Dist string `yaml:",omitempty"` 238 Sign Sign `yaml:",omitempty"` 239 EnvFiles EnvFiles `yaml:"env_files,omitempty"` 240 Git Git `yaml:",omitempty"` 241 242 // this is a hack ¯\_(ツ)_/¯ 243 SingleBuild Build `yaml:"build,omitempty"` 244 245 // should be set if using github enterprise 246 GitHubURLs GitHubURLs `yaml:"github_urls,omitempty"` 247 } 248 249 // Load config file 250 func Load(file string) (config Project, err error) { 251 f, err := os.Open(file) 252 if err != nil { 253 return 254 } 255 log.WithField("file", file).Info("loading config file") 256 return LoadReader(f) 257 } 258 259 // LoadReader config via io.Reader 260 func LoadReader(fd io.Reader) (config Project, err error) { 261 data, err := ioutil.ReadAll(fd) 262 if err != nil { 263 return config, err 264 } 265 err = yaml.UnmarshalStrict(data, &config) 266 log.WithField("config", config).Debug("loaded config file") 267 return config, err 268 }