diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f1b49ec..d2f2393 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,8 +37,7 @@ jobs: sudo apt-get install -y golang - name: Build run: | - make -j $(nproc) - go build -o bin/autobump ./cmd/autobump + make build strip -s bin/autobump - name: Package run: | diff --git a/Makefile b/Makefile index abc9409..859ab57 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,11 @@ build: go build -o bin/autobump ./cmd/autobump strip -s bin/autobump +build-musl: + CGO_ENABLED=1 CC=musl-gcc go build \ + --ldflags 'linkmode external -extldflags="-static"' -o bin/autobump ./cmd/autobump + strip -s bin/autobump + run: go run ./cmd/autobump diff --git a/cmd/autobump/main.go b/cmd/autobump/main.go index 2c6d948..2e33086 100644 --- a/cmd/autobump/main.go +++ b/cmd/autobump/main.go @@ -15,6 +15,14 @@ var ( Use: "autobump", Short: "AutoBump is a tool that automatically updates CHANGELOG.md", Run: func(cmd *cobra.Command, args []string) { + // find the config file if not manually set + configPath, err := findConfigOnMissing(configPath) + if err != nil { + log.Fatalf("Failed to locate config file") + os.Exit(1) + } + + // read the config file globalConfig, err := readConfig(configPath) if err != nil { log.Fatalf("Failed to read config: %v", err) @@ -54,6 +62,14 @@ var ( Use: "batch", Short: "Run AutoBump for all projects in the configuration", Run: func(cmd *cobra.Command, args []string) { + // find the config file if not manually set + configPath, err := findConfigOnMissing(configPath) + if err != nil { + log.Fatalf("Failed to locate config file") + os.Exit(1) + } + + // read the config file globalConfig, err := readConfig(configPath) if err != nil { log.Fatalf("Failed to read config: %v", err) @@ -65,24 +81,26 @@ var ( } ) -// program entry point -func main() { - rootCmd.Flags().StringVarP(&configPath, "config", "c", "", "config file path") - rootCmd.Flags().StringVarP(&language, "language", "l", "", "project language") - - // search for config file in default locations +func findConfigOnMissing(configPath string) (string, error) { if configPath == "" { log.Info("No config file specified, searching for default locations") var err error configPath, err = findConfig() if err != nil { - log.Fatalf("Failed to locate config file: \"%v\"", err) - os.Exit(1) + return "", err } log.Infof("Using config file: \"%v\"", configPath) + return configPath, nil } + return configPath, nil +} + +// program entry point +func main() { + rootCmd.Flags().StringVarP(&configPath, "config", "c", "", "config file path") + rootCmd.Flags().StringVarP(&language, "language", "l", "", "project language") rootCmd.AddCommand(batchCmd) rootCmd.Execute()