1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-11-06 09:09:29 +02:00

refactory: make easier to manage merges with pro (#3178)

* refactory: improve cmd code

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: improve time reporting

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: improve artifacts json

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: improve artifacts json

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* fix: diffs

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

* docs: improve root cmd help

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker
2022-06-22 01:48:11 -03:00
committed by GitHub
parent cb70fa5181
commit 9efea360b9
9 changed files with 58 additions and 86 deletions

View File

@@ -112,10 +112,6 @@ func (t Type) String() string {
}
}
func (t Type) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf("%q", t)), nil
}
const (
ExtraID = "ID"
ExtraBinary = "Binary"
@@ -136,8 +132,7 @@ func (e Extras) MarshalJSON() ([]byte, error) {
for k, v := range e {
if k == ExtraRefresh {
// refresh is a func, so we can't serialize it.
// set v to a string representation of the function signature instead.
v = "func() error"
continue
}
m[k] = v
}
@@ -153,7 +148,8 @@ type Artifact struct {
Goarm string `json:"goarm,omitempty"`
Gomips string `json:"gomips,omitempty"`
Goamd64 string `json:"goamd64,omitempty"`
Type Type `json:"type,omitempty"`
Type Type `json:"internal_type,omitempty"`
TypeS string `json:"type,omitempty"`
Extra Extras `json:"extra,omitempty"`
}
@@ -489,7 +485,7 @@ type VisitFn func(a *Artifact) error
// Visit executes the given function for each artifact in the list.
func (artifacts Artifacts) Visit(fn VisitFn) error {
for _, artifact := range artifacts.List() {
for _, artifact := range artifacts.items {
if err := fn(artifact); err != nil {
return err
}

View File

@@ -483,46 +483,6 @@ func TestByFormats(t *testing.T) {
require.Len(t, artifacts.Filter(ByFormats("zip", "tar.gz")).items, 3)
}
func TestTypeToString(t *testing.T) {
for _, a := range []Type{
UploadableArchive,
UploadableBinary,
UploadableFile,
Binary,
UniversalBinary,
LinuxPackage,
PublishableSnapcraft,
Snapcraft,
PublishableDockerImage,
DockerImage,
DockerManifest,
Checksum,
Signature,
Certificate,
UploadableSourceArchive,
BrewTap,
GoFishRig,
KrewPluginManifest,
ScoopManifest,
SBOM,
PkgBuild,
SrcInfo,
} {
t.Run(a.String(), func(t *testing.T) {
require.NotEqual(t, "unknown", a.String())
bts, err := a.MarshalJSON()
require.NoError(t, err)
require.Equal(t, []byte(`"`+a.String()+`"`), bts)
})
}
t.Run("unknown", func(t *testing.T) {
require.Equal(t, "unknown", Type(9999).String())
bts, err := Type(9999).MarshalJSON()
require.NoError(t, err)
require.Equal(t, []byte(`"unknown"`), bts)
})
}
func TestPaths(t *testing.T) {
paths := []string{"a/b", "b/c", "d/e", "f/g"}
artifacts := New()
@@ -900,7 +860,11 @@ func Test_ByBinaryLikeArtifacts(t *testing.T) {
arts.Add(a)
}
actual := arts.Filter(ByBinaryLikeArtifacts(arts)).List()
assert.Equal(t, tt.expected, actual)
expected := New()
for _, a := range tt.expected {
expected.Add(a)
}
assert.Equal(t, expected.List(), actual)
if t.Failed() {
t.Log("expected:")

View File

@@ -1 +1 @@
[{"name":"foo","type":"Binary","extra":{"ID":"adsad"}},{"name":"foo","type":"Archive","extra":{"ID":"adsad"}},{"name":"foo","type":"Checksum","extra":{"Refresh":"func() error"}}]
[{"name":"foo","internal_type":4,"extra":{"ID":"adsad"}},{"name":"foo","internal_type":1,"extra":{"ID":"adsad"}},{"name":"foo","internal_type":12,"extra":{}}]

View File

@@ -8,6 +8,7 @@ import (
"time"
"github.com/caarlos0/log"
"github.com/goreleaser/goreleaser/internal/artifact"
"github.com/goreleaser/goreleaser/pkg/context"
)
@@ -41,6 +42,10 @@ func writeMetadata(ctx *context.Context) error {
}
func writeArtifacts(ctx *context.Context) error {
_ = ctx.Artifacts.Visit(func(a *artifact.Artifact) error {
a.TypeS = a.Type.String()
return nil
})
return writeJSON(ctx, ctx.Artifacts.List(), "artifacts.json")
}

View File

@@ -1 +1 @@
[{"name":"foo","path":"foo.txt","goos":"darwin","goarch":"amd64","goarm":"7","type":"Binary","extra":{"foo":"bar"}}]
[{"name":"foo","path":"foo.txt","goos":"darwin","goarch":"amd64","goarm":"7","internal_type":4,"type":"Binary","extra":{"foo":"bar"}}]