1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-03-19 20:57:53 +02:00
Carlos Alexandro Becker ec2db4a727
feat!: rename module to /v2 (#4894)
<!--

Hi, thanks for contributing!

Please make sure you read our CONTRIBUTING guide.

Also, add tests and the respective documentation changes as well.

-->


<!-- If applied, this commit will... -->

...

<!-- Why is this change being made? -->

...

<!-- # Provide links to any relevant tickets, URLs or other resources
-->

...

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2024-05-26 15:02:57 -03:00

38 lines
1.0 KiB
Go

package reportsizes
import (
"os"
"github.com/caarlos0/log"
"github.com/docker/go-units"
"github.com/goreleaser/goreleaser/v2/internal/artifact"
"github.com/goreleaser/goreleaser/v2/pkg/context"
)
type Pipe struct{}
func (Pipe) Skip(ctx *context.Context) bool { return !ctx.Config.ReportSizes }
func (Pipe) String() string { return "size reports" }
func (Pipe) Run(ctx *context.Context) error {
return ctx.Artifacts.Filter(artifact.Or(
artifact.ByType(artifact.Binary),
artifact.ByType(artifact.UniversalBinary),
artifact.ByType(artifact.UploadableArchive),
artifact.ByType(artifact.PublishableSnapcraft),
artifact.ByType(artifact.LinuxPackage),
artifact.ByType(artifact.CArchive),
artifact.ByType(artifact.CShared),
artifact.ByType(artifact.Header),
)).Visit(func(a *artifact.Artifact) error {
stat, err := os.Stat(a.Path)
if err != nil {
return err
}
a.Extra[artifact.ExtraSize] = stat.Size()
log.WithField("path", a.Path).
Info(units.BytesSize(float64(stat.Size())))
return nil
})
}