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

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

54 lines
1.1 KiB
Go

// Package dist provides checks to make sure the dist directory is always
// empty.
package dist
import (
"fmt"
"os"
"github.com/caarlos0/log"
"github.com/goreleaser/goreleaser/v2/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 directory", ctx.Config.Dist)
return mkdir(ctx)
}
if ctx.Clean {
log.Infof("cleaning %s", ctx.Config.Dist)
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 --clean 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)
}