Skip to content

Commit

Permalink
Move config to github.com/goccy/go-yaml
Browse files Browse the repository at this point in the history
Mostly motivated by YAML anchors.
  • Loading branch information
bep committed Dec 20, 2024
1 parent 160eef4 commit 31191f0
Show file tree
Hide file tree
Showing 33 changed files with 900 additions and 908 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
shell: bash
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Fmt
if: matrix.platform != 'windows-latest' # :(
run: "diff <(gofmt -d .) <(printf '')"
Expand Down
41 changes: 31 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,30 @@

### Configuration File

Hugoreleaser reads its main configuration from a file named `hugoreleaser.toml` in the working directory. See [this project's configuration](./hugoreleaser.toml) for an annotated example.
Hugoreleaser reads its main configuration from a file named `hugoreleaser.yaml` in the working directory. See [this project's configuration](./hugoreleaser.yaml) for an annotated example.


### Definitions

Hugoreleaser supports YAML anchors and aliases, and has a reserved section for `definitions`. This is useful for defining common settings that can be reused in multiple places, e.g.

```yaml
definitions:
archive_type_zip: &archive_type_zip
type:
format: zip
extension: .zip

- goarch: amd64
archives:
- paths:
- builds/**/windows/**
archive_settings: *archive_type_zip
```
### Archive Aliases
See Hugo's use [here](https://github.com/gohugoio/hugo/blob/ec02c537edf7c027e7470126eb913e84fb626216/hugoreleaser.toml#L11).
See Hugo's use [here](TODO(bep)).
### Template Expansion
Expand Down Expand Up @@ -63,7 +82,7 @@ The order of presedence for environment variables/flags:

A `hugoreleaser.env` file will, if found in the current directory, be parsed and loaded into the environment of the running process. The format is simple, a text files of key-value-pairs on the form `KEY=value`, empty lines and lines starting with `#` is ignored:

Environment variable expressions in `hugoreleaser.toml` on the form `${VAR}` will be expanded before it's parsed.
Environment variable expressions in `hugoreleaser.yaml` on the form `${VAR}` will be expanded before it's parsed.

An example `hugoreleaser.env` with the enviromnent for the next release may look like this:

Expand All @@ -76,12 +95,11 @@ MYPROJECT_RELEASE_DRAFT=false

In the above, the variables prefixed `HUGORELEASER_` will be used to set the flags when running the `hugoreleaser` commands.

The other custom variables can be used in `hugoreleaser.toml`, e.g:
The other custom variables can be used in `hugoreleaser.yaml`, e.g:

```toml
[release_settings]
name = "${MYPROJECT_RELEASE_NAME}"
draft = "${MYPROJECT_RELEASE_DRAFT@U}"
release_settings:
name: ${MYPROJECT_RELEASE_NAME}
```

Note the special `@U` (_Unquoute_) syntax. The field `draft` is a boolean and cannot be quouted, but this would create ugly validation errors in TOML aware editors. The construct above signals that the quoutes (single or double) should be removed before doing any variable expansion.
Expand Down Expand Up @@ -133,12 +151,15 @@ The config map `release_notes_settings` has 3 options for how to handle release
2. Set `generate_on_host=true` and let GitHub do it.
3. Set `generate=true` and let Hugoreleaser do it.

There are more details about change grouping etc. in this [this project's configuration](./hugoreleaser.toml).
There are more details about change grouping etc. in this [this project's configuration](./hugoreleaser.yaml).

For the third option, you can set a custom release notes template to use in `template_filename`. See the default template in [staticfiles/templates/release-notes.gotmpl](./staticfiles/templates/release-notes.gotmpl) for an example.

## Why another Go release tool?

If you need a Go build/release tool with all the bells and whistles, check out [GoReleaser](https://github.com/goreleaser/goreleaser). This project was created because [Hugo](https://github.com/gohugoio/hugo) needed some features not on the road map of that project.
This project was created because [Hugo](https://github.com/gohugoio/hugo) had some issues that seemed unsolvable with Goreleaser:

* We had a CI release that timed out a lot (1 hour). And since Goreleaser creates the tag as the first step, we often ended up having to delete the tag and start over, creating all sorts of issues.
* We wanted to add more build variants, but we couldn't.

Hugo has used this tool for all of its releases since [v0.102.0](https://github.com/gohugoio/hugo/releases/tag/v0.102.0).
Hugo has used this tool for all of its releases since [v0.102.0](https://github.com/gohugoio/hugo/releases/tag/v0.102.0), and the release time has gone down from 50-60 minutes to around 10 minutes.
7 changes: 3 additions & 4 deletions cmd/corecmd/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func New() (*ffcli.Command, *Core) {
}, &cfg
}

const configName = "hugoreleaser.yaml"

// Core holds common config settings and objects.
type Core struct {
// The parsed config.
Expand Down Expand Up @@ -157,7 +159,6 @@ func (c *Core) RegisterFlags(fs *flag.FlagSet) {
fs.StringVar(&c.Tag, "tag", "", "The name of the release tag (e.g. v1.2.0). Does not need to exist.")
fs.Var(&c.Paths, "paths", "Paths to include in the command.")
fs.StringVar(&c.DistDir, "dist", "dist", "Directory to store the built artifacts in.")
fs.StringVar(&c.ConfigFile, "config", "hugoreleaser.toml", "The config file to use.")
fs.IntVar(&c.NumWorkers, "workers", numWorkers, "Number of parallel builds.")
fs.DurationVar(&c.Timeout, "timeout", 55*time.Minute, "Global timeout.")
fs.BoolVar(&c.Quiet, "quiet", false, "Don't output anything to stdout.")
Expand Down Expand Up @@ -342,9 +343,7 @@ func (c *Core) Init() error {
c.NumWorkers = runtime.NumCPU()
}

if !filepath.IsAbs(c.ConfigFile) {
c.ConfigFile = filepath.Join(c.ProjectDir, c.ConfigFile)
}
c.ConfigFile = filepath.Join(c.ProjectDir, configName)

f, err := os.Open(c.ConfigFile)
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/gohugoio/hugoreleaser
go 1.22.0

require (
github.com/bep/execrpc v0.9.0
github.com/bep/execrpc v0.10.0
github.com/bep/helpers v0.5.0
github.com/bep/logg v0.4.0
github.com/bep/workers v1.1.0
Expand All @@ -29,7 +29,8 @@ require (
)

require (
github.com/gohugoio/hugoreleaser-plugins-api v0.7.1-0.20241219160743-c3129de2a262
github.com/goccy/go-yaml v1.15.11
github.com/gohugoio/hugoreleaser-plugins-api v0.7.1-0.20241220094410-1f02562cf9b9
golang.org/x/sync v0.10.0
)

Expand All @@ -44,5 +45,3 @@ require (
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
)

replace github.com/bep/execrpc => /Users/bep/dev/go/bep/execrpc
14 changes: 6 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/bep/clocks v0.5.0 h1:hhvKVGLPQWRVsBP/UB7ErrHYIO42gINVbvqxvYTPVps=
github.com/bep/clocks v0.5.0/go.mod h1:SUq3q+OOq41y2lRQqH5fsOoxN8GbxSiT6jvoVVLCVhU=
github.com/bep/execrpc v0.9.0 h1:SIQnFxUIpJEbfR3FTp94OinpqBrZDQDVWbJ82pgJ77k=
github.com/bep/execrpc v0.9.0/go.mod h1:lGHGK8NX0KvfhlRNH/SebW1quHGwXFeE3Ba+2KLtmrM=
github.com/bep/execrpc v0.10.0 h1:Y8S8pZOFZI/zo95RMqgri98eIFaZEqZ41tbF89hSx/A=
github.com/bep/execrpc v0.10.0/go.mod h1:lGHGK8NX0KvfhlRNH/SebW1quHGwXFeE3Ba+2KLtmrM=
github.com/bep/helpers v0.5.0 h1:rneezhnG7GzLFlsEWO/EnleaBRuluBDGFimalO6Y50o=
github.com/bep/helpers v0.5.0/go.mod h1:dSqCzIvHbzsk5YOesp1M7sKAq5xUcvANsRoKdawxH4Q=
github.com/bep/logg v0.4.0 h1:luAo5mO4ZkhA5M1iDVDqDqnBBnlHjmtZF6VAyTp+nCQ=
Expand All @@ -18,12 +18,10 @@ github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHk
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/gohugoio/hugoreleaser-plugins-api v0.7.1-0.20241219113101-e613cfc24c82 h1:IdctCMa9e/yCyJGQU7IeYmcYYHyiZccu5OcFwSOJoTo=
github.com/gohugoio/hugoreleaser-plugins-api v0.7.1-0.20241219113101-e613cfc24c82/go.mod h1:3pnrMYKsGrzACVwKU/R72UpRUnR+W7E5laXurS2QGMc=
github.com/gohugoio/hugoreleaser-plugins-api v0.7.1-0.20241219154512-07cffd8e9e37 h1:nyRm3Qt2Wl0dyEdPIsXkmmxXuRf5KSMtBC84s8p2h9E=
github.com/gohugoio/hugoreleaser-plugins-api v0.7.1-0.20241219154512-07cffd8e9e37/go.mod h1:3pnrMYKsGrzACVwKU/R72UpRUnR+W7E5laXurS2QGMc=
github.com/gohugoio/hugoreleaser-plugins-api v0.7.1-0.20241219160743-c3129de2a262 h1:T7uoNqJOnE1YiCs0bJus8J5ytTFfdZj31uNhb80GTcE=
github.com/gohugoio/hugoreleaser-plugins-api v0.7.1-0.20241219160743-c3129de2a262/go.mod h1:3pnrMYKsGrzACVwKU/R72UpRUnR+W7E5laXurS2QGMc=
github.com/goccy/go-yaml v1.15.11 h1:XeEd/2INF0TXXWMzJ9ALqJLGjGDl4PIi1gmrK+7KpAs=
github.com/goccy/go-yaml v1.15.11/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/gohugoio/hugoreleaser-plugins-api v0.7.1-0.20241220094410-1f02562cf9b9 h1:JT6XVa3wBdkwrgcV4EYku7fZOfLX2MjWgWWtHtp5IQs=
github.com/gohugoio/hugoreleaser-plugins-api v0.7.1-0.20241220094410-1f02562cf9b9/go.mod h1:Qheg3q6TF7pq9etJBNceTqGaM1VfkYDnm2k2KIIC/Ac=
github.com/gohugoio/hugoreleaser/plugins v0.1.1-0.20220822083757-38d81884db04 h1:VNOiFvTuhXc2eoDvBVQHsfxl1TTS2/EF1wFs1YttIlA=
github.com/gohugoio/hugoreleaser/plugins v0.1.1-0.20220822083757-38d81884db04/go.mod h1:P3JlkmIYwGFlTf8/MhkR4P+mvidrYo28Fudx4wcR7f0=
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
Expand Down
182 changes: 0 additions & 182 deletions hugoreleaser.toml

This file was deleted.

Loading

0 comments on commit 31191f0

Please sign in to comment.