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