mirror of
https://github.com/goreleaser/goreleaser.git
synced 2025-01-10 03:47:03 +02:00
fe7e2123bd
* feat: replacing logs Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: tests et al Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * feat: update termenv/lipgloss Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * wip: output Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: pin dep Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: update Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: tests Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: tests Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: deps Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com> * fix: dep Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
// Package dist provides checks to make sure the dist folder is always
|
|
// empty.
|
|
package dist
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/caarlos0/log"
|
|
"github.com/goreleaser/goreleaser/pkg/context"
|
|
)
|
|
|
|
// Pipe for dist.
|
|
type Pipe struct{}
|
|
|
|
func (Pipe) String() string {
|
|
return "checking distribution directory"
|
|
}
|
|
|
|
// Run the pipe.
|
|
func (Pipe) Run(ctx *context.Context) (err error) {
|
|
_, err = os.Stat(ctx.Config.Dist)
|
|
if os.IsNotExist(err) {
|
|
log.Debugf("%s doesn't exist, creating empty folder", ctx.Config.Dist)
|
|
return mkdir(ctx)
|
|
}
|
|
if ctx.RmDist {
|
|
log.Info("--rm-dist is set, cleaning it up")
|
|
err = os.RemoveAll(ctx.Config.Dist)
|
|
if err == nil {
|
|
err = mkdir(ctx)
|
|
}
|
|
return err
|
|
}
|
|
files, err := os.ReadDir(ctx.Config.Dist)
|
|
if err != nil {
|
|
return
|
|
}
|
|
if len(files) != 0 {
|
|
log.Debugf("there are %d files on %s", len(files), ctx.Config.Dist)
|
|
return fmt.Errorf(
|
|
"%s is not empty, remove it before running goreleaser or use the --rm-dist flag",
|
|
ctx.Config.Dist,
|
|
)
|
|
}
|
|
log.Debugf("%s is empty", ctx.Config.Dist)
|
|
return mkdir(ctx)
|
|
}
|
|
|
|
func mkdir(ctx *context.Context) error {
|
|
// #nosec
|
|
return os.MkdirAll(ctx.Config.Dist, 0o755)
|
|
}
|