1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-10 03:47:03 +02:00
goreleaser/internal/pipeline/dist/dist.go
Carlos Alexandro Becker 64b1f14a86
refactor: better code organization (#757)
* refactor: merging archive in the same repo

* refactor: merging archive in the same repo

* refactor: better organizing packages

* refactor: fixing renames

* fix: new dep version

* fix: makefile

* fix: zip/tar tests

* fix: gitigonore

* fix: s3 tests

* fix: archive test
2018-08-14 23:50:20 -03:00

55 lines
1.1 KiB
Go

// Package dist provides checks to make sure the dist folder is always
// empty.
package dist
import (
"fmt"
"io/ioutil"
"os"
"github.com/apex/log"
"github.com/goreleaser/goreleaser/pkg/context"
)
// Pipe for cleandis
type Pipe struct{}
func (Pipe) String() string {
return "checking ./dist"
}
// Run the pipe
func (Pipe) Run(ctx *context.Context) (err error) {
_, err = os.Stat(ctx.Config.Dist)
if os.IsNotExist(err) {
log.Debug("./dist doesn't exist, creating empty folder")
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 := ioutil.ReadDir(ctx.Config.Dist)
if err != nil {
return
}
if len(files) > 0 {
log.Debugf("there are %d files on ./dist", len(files))
return fmt.Errorf(
"%s is not empty, remove it before running goreleaser or use the --rm-dist flag",
ctx.Config.Dist,
)
}
log.Debug("./dist is empty")
return mkdir(ctx)
}
func mkdir(ctx *context.Context) error {
// #nosec
return os.MkdirAll(ctx.Config.Dist, 0755)
}