Skip to content

Commit

Permalink
fix: change mkdir perm to 775, delete perm flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Mmx233 committed Oct 12, 2024
1 parent ed36d4c commit 0ec2dec
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 38 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Flags:
compressed file.
--[no-]disable-default-ldflags
Disable ldflags added by default.
--perm="0600" Output file mode.
--mod-download-args=MOD-DOWNLOAD-ARGS
custom args for go mod download.
--ldflags=LDFLAGS Add custom ldflags.
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Flags:
compressed file.
--[no-]disable-default-ldflags
Disable ldflags added by default.
--perm="0600" Output file mode.
--perm="0775" Output file mode.
--mod-download-args=MOD-DOWNLOAD-ARGS
custom args for go mod download.
--ldflags=LDFLAGS Add custom ldflags.
Expand Down
14 changes: 2 additions & 12 deletions cmd/action/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,12 @@ package main
import (
"github.com/Mmx233/GoReleaseCli/internal/global"
"github.com/Mmx233/GoReleaseCli/internal/pkg/builder"
"github.com/caarlos0/env/v11"
log "github.com/sirupsen/logrus"
"runtime"
)

func init() {
if err := env.ParseWithOptions(&global.Config, env.Options{
Prefix: "INPUT_",
}); err != nil {
log.Fatalln(err)
}
if global.Config.Thread == 0 {
global.Config.Thread = uint16(runtime.NumCPU() + 1)
}
if err := global.Init(); err != nil {
log.Fatalln(err)
if err := global.ParseConfigFromEnv(); err != nil {
log.Fatal(err)
}
}

Expand Down
4 changes: 0 additions & 4 deletions cmd/release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ import (
"github.com/Mmx233/GoReleaseCli/internal/global"
"github.com/Mmx233/GoReleaseCli/internal/pkg/builder"
"github.com/alecthomas/kingpin/v2"
log "github.com/sirupsen/logrus"
"os"
)

var Version = "-.-.-"

func main() {
kingpin.MustParse(global.NewCommands(Version).Parse(os.Args[1:]))
if err := global.Init(); err != nil {
log.Fatalln(err)
}
builder.Run()
}
1 change: 0 additions & 1 deletion internal/global/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func NewCommands(version string) *kingpin.Application {
app.Flag("thread", "How many threads to use for parallel compilation.").Short('j').Default(fmt.Sprint(runtime.NumCPU() + 1)).Uint16Var(&Config.Thread)
app.Flag("compress", "Compress the binary into the specified format of compressed file.").Short('c').HintOptions("zip", "tar.gz").StringVar(&Config.Compress)
app.Flag("disable-default-ldflags", "Disable ldflags added by default.").BoolVar(&Config.DisableDefaultLdflags)
app.Flag("perm", "Output file mode.").Default("0600").StringVar(&Config.Perm)

app.Flag("mod-download-args", "custom args for go mod download.").HintOptions("-x").StringVar(&Config.ModDownloadArgs)

Expand Down
18 changes: 0 additions & 18 deletions internal/global/config.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
package global

import (
"os"
"strconv"
)

// Init call after Config is set.
func Init() error {
perm, err := strconv.ParseUint(Config.Perm, 8, 32)
if err != nil {
return err
}
Perm = os.FileMode(perm)
return nil
}

var Config _Config

var Perm os.FileMode

type _Config struct {
Target string `env:"TARGET,required,notEmpty"`
Ldflags string `env:"LDFLAGS"`
Expand All @@ -38,5 +21,4 @@ type _Config struct {

Compress string `env:"COMPRESS"`
Thread uint16 `env:"TREAD"`
Perm string `env:"PERM,notEmpty" envDefault:"0777"`
}
19 changes: 19 additions & 0 deletions internal/global/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package global

import (
"github.com/caarlos0/env/v11"
"runtime"
)

func ParseConfigFromEnv() error {
if err := env.ParseWithOptions(&Config, env.Options{
Prefix: "INPUT_",
}); err != nil {
return err
}

if Config.Thread == 0 {
Config.Thread = uint16(runtime.NumCPU() + 1)
}
return nil
}
2 changes: 1 addition & 1 deletion internal/pkg/builder/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func PrepareDirs(outputDir string) error {
_ = os.RemoveAll(outputDir)
return os.MkdirAll(outputDir, global.Perm)
return os.MkdirAll(outputDir, 0775)
}

func LoadBinaryName() string {
Expand Down

0 comments on commit 0ec2dec

Please sign in to comment.