Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc updates #45

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ jobs:
test:
strategy:
matrix:
go-version: [1.21.x, 1.22.x]
go-version: [1.22.x, 1.23.x]
platform: [ macos-latest, ubuntu-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version: ${{ matrix.go-version }}
- name: Install staticcheck
Expand All @@ -25,7 +25,9 @@ jobs:
run: echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
shell: bash
- name: Checkout code
uses: actions/checkout@v1
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.
35 changes: 13 additions & 22 deletions cmd/archivecmd/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"os"
"path"
"path/filepath"
"time"

"github.com/gohugoio/hugoreleaser-plugins-api/archiveplugin"
"github.com/gohugoio/hugoreleaser/cmd/corecmd"
Expand Down Expand Up @@ -64,7 +63,6 @@ func NewArchivist(core *corecmd.Core) *Archivist {
return &Archivist{
core: core,
}

}

func (b *Archivist) Init() error {
Expand All @@ -80,20 +78,19 @@ func (b *Archivist) Init() error {
return nil
}
infoCtx := c.InfoLog.WithField("cmd", fmt.Sprintf("%s %s", commandName, p.ID))
client, err := plugins.StartArchivePlugin(infoCtx, c.Config.GoSettings, p)
cfg := plugins.ArchivePluginConfig{
Infol: infoCtx,
Try: c.Try,
GoSettings: c.Config.GoSettings,
Options: p,
Project: c.Config.Project,
Tag: c.Tag,
}
client, err := plugins.StartArchivePlugin(cfg)
if err != nil {
return fmt.Errorf("error starting archive plugin %q: %w", p.ID, err)
}

// Send a heartbeat to the plugin to make sure it's alive.
heartbeat := fmt.Sprintf("heartbeat-%s", time.Now())
resp, err := client.Execute(archiveplugin.Request{Heartbeat: heartbeat})
if err != nil {
return fmt.Errorf("error testing archive plugin %q: %w", p.ID, err)
}
if resp.Heartbeat != heartbeat {
return fmt.Errorf("error testing archive plugin %q: unexpected heartbeat response", p.ID)
}
infoCtx.Log(logg.String("Archive plugin started and ready for use"))
c.PluginsRegistryArchive[p.ID] = client
return nil
Expand Down Expand Up @@ -134,15 +131,12 @@ func (b *Archivist) Exec(ctx context.Context, args []string) error {
archPath := archPath
archiveSettings := archive.ArchiveSettings
arch := archPath.Arch
buildInfo := model.BuildInfo{
Project: b.core.Config.Project,
Tag: b.core.Tag,
Goos: arch.Os.Goos,
Goarch: arch.Goarch,
goInfo := model.GoInfo{
Goos: arch.Os.Goos,
Goarch: arch.Goarch,
}

r.Run(func() (err error) {

outDir := filepath.Join(archiveDistDir, filepath.FromSlash(archPath.Path))

outFilename := filepath.Join(
Expand Down Expand Up @@ -174,7 +168,7 @@ func (b *Archivist) Exec(ctx context.Context, args []string) error {
}

buildRequest := archiveplugin.Request{
BuildInfo: buildInfo,
GoInfo: goInfo,
Settings: archiveSettings.CustomSettings,
OutFilename: outFilename,
}
Expand All @@ -199,7 +193,6 @@ func (b *Archivist) Exec(ctx context.Context, args []string) error {
archiveSettings,
buildRequest,
)

if err != nil {
return err
}
Expand All @@ -216,12 +209,10 @@ func (b *Archivist) Exec(ctx context.Context, args []string) error {
}

return nil

})

}
}

return r.Wait()

}
14 changes: 6 additions & 8 deletions cmd/corecmd/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/bep/logg/handlers/multi"
"github.com/bep/workers"
"github.com/gohugoio/hugoreleaser-plugins-api/archiveplugin"
apimodel "github.com/gohugoio/hugoreleaser-plugins-api/model"
"github.com/gohugoio/hugoreleaser/internal/common/errorsh"
"github.com/gohugoio/hugoreleaser/internal/common/logging"
"github.com/gohugoio/hugoreleaser/internal/common/matchers"
Expand Down Expand Up @@ -76,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 @@ -134,7 +137,7 @@ type Core struct {
Workforce *workers.Workforce

// Archive plugins started and ready to use.
PluginsRegistryArchive map[string]*execrpc.Client[archiveplugin.Request, archiveplugin.Response]
PluginsRegistryArchive map[string]*execrpc.Client[apimodel.Config, archiveplugin.Request, any, apimodel.Receipt]
}

// Exec function for this command.
Expand All @@ -156,12 +159,10 @@ 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.")
fs.BoolVar(&c.Try, "try", false, "Trial run, no builds, archives or releases.")

}

// PreInit is called before the flags are parsed.
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 All @@ -353,7 +352,6 @@ func (c *Core) Init() error {
defer f.Close()

c.Config, err = config.DecodeAndApplyDefaults(f)

if err != nil {
msg := "error decoding config file"
switch v := err.(type) {
Expand Down Expand Up @@ -416,7 +414,7 @@ func (c *Core) Init() error {
}

// Registry for archive plugins.
c.PluginsRegistryArchive = make(map[string]*execrpc.Client[archiveplugin.Request, archiveplugin.Response])
c.PluginsRegistryArchive = make(map[string]*execrpc.Client[apimodel.Config, archiveplugin.Request, any, apimodel.Receipt])

return nil
}
Expand Down
35 changes: 17 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
module github.com/gohugoio/hugoreleaser

go 1.19
go 1.22.0

require (
github.com/bep/execrpc v0.7.1
github.com/bep/helpers v0.4.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
github.com/fatih/color v1.16.0
github.com/frankban/quicktest v1.14.3
github.com/fatih/color v1.18.0
github.com/frankban/quicktest v1.14.6
github.com/gohugoio/hugoreleaser/plugins v0.1.1-0.20220822083757-38d81884db04
github.com/google/go-github/v45 v45.2.0
github.com/mattn/go-isatty v0.0.20
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.1.1
github.com/pelletier/go-toml/v2 v2.2.3
github.com/peterbourgon/ff/v3 v3.4.0
github.com/rogpeppe/go-internal v1.10.0
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a
golang.org/x/oauth2 v0.17.0
github.com/rogpeppe/go-internal v1.13.1
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
golang.org/x/oauth2 v0.24.0
)

require (
github.com/bep/clocks v0.5.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/pkg/errors v0.9.1 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/sys v0.28.0 // indirect
)

require (
github.com/gohugoio/hugoreleaser-plugins-api v0.7.0
golang.org/x/sync v0.6.0
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
)

require (
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.32.0 // indirect
golang.org/x/tools v0.28.0 // indirect
)

require (
github.com/gobwas/glob v0.2.3
github.com/google/go-cmp v0.5.9 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
)
Loading
Loading