mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-14 03:51:24 +02:00
feat: version in the yaml file
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
parent
3009ac1989
commit
896366f3dc
@ -1,5 +1,7 @@
|
||||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
|
||||
# vim: set ts=2 sw=2 tw=0 fo=jcroql
|
||||
version: 1
|
||||
|
||||
env:
|
||||
- GO111MODULE=on
|
||||
|
||||
|
@ -6,6 +6,8 @@
|
||||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
|
||||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
|
||||
|
||||
version: 1
|
||||
|
||||
before:
|
||||
hooks:
|
||||
# You may remove this if you don't use go modules.
|
||||
|
@ -11,11 +11,16 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/goreleaser/goreleaser/internal/logext"
|
||||
"github.com/goreleaser/goreleaser/internal/yaml"
|
||||
"github.com/goreleaser/nfpm/v2/files"
|
||||
"github.com/invopop/jsonschema"
|
||||
)
|
||||
|
||||
type Versioned struct {
|
||||
Version int
|
||||
}
|
||||
|
||||
// Git configs.
|
||||
type Git struct {
|
||||
TagSort string `yaml:"tag_sort,omitempty" json:"tag_sort,omitempty" jsonschema:"enum=-version:refname,enum=-version:creatordate,default=-version:refname"`
|
||||
@ -1144,6 +1149,7 @@ type Source struct {
|
||||
|
||||
// Project includes all project configuration.
|
||||
type Project struct {
|
||||
Version int `yaml:"version" json:"version" jsonschema:"enum=1,default=1"`
|
||||
ProjectName string `yaml:"project_name,omitempty" json:"project_name,omitempty"`
|
||||
Env []string `yaml:"env,omitempty" json:"env,omitempty"`
|
||||
Release Release `yaml:"release,omitempty" json:"release,omitempty"`
|
||||
@ -1339,12 +1345,31 @@ func Load(file string) (config Project, err error) {
|
||||
return LoadReader(f)
|
||||
}
|
||||
|
||||
type VersionError struct {
|
||||
current int
|
||||
}
|
||||
|
||||
func (e VersionError) Error() string {
|
||||
return fmt.Sprintf(
|
||||
"only configurations files on %s are supported, yours is %s, please update your configuration",
|
||||
logext.Keyword("version: 1"),
|
||||
logext.Keyword(fmt.Sprintf("version: %d", e.current)),
|
||||
)
|
||||
}
|
||||
|
||||
// LoadReader config via io.Reader.
|
||||
func LoadReader(fd io.Reader) (config Project, err error) {
|
||||
data, err := io.ReadAll(fd)
|
||||
if err != nil {
|
||||
return config, err
|
||||
}
|
||||
|
||||
var versioned Versioned
|
||||
_ = yaml.Unmarshal(data, &versioned)
|
||||
if versioned.Version != 0 && versioned.Version != 1 {
|
||||
return config, VersionError{versioned.Version}
|
||||
}
|
||||
|
||||
err = yaml.UnmarshalStrict(data, &config)
|
||||
return config, err
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -72,3 +73,23 @@ func TestConfigWithAnchors(t *testing.T) {
|
||||
_, err := Load("testdata/anchor.yaml")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestVersion(t *testing.T) {
|
||||
t.Run("allow no version", func(t *testing.T) {
|
||||
_, err := LoadReader(bytes.NewReader(nil))
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Run("allow v0", func(t *testing.T) {
|
||||
_, err := LoadReader(strings.NewReader("version: 0"))
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Run("allow v1", func(t *testing.T) {
|
||||
_, err := LoadReader(strings.NewReader("version: 1"))
|
||||
require.NoError(t, err)
|
||||
})
|
||||
t.Run("do not allow v2", func(t *testing.T) {
|
||||
_, err := LoadReader(strings.NewReader("version: 2"))
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, VersionError{2})
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user