Skip to content

Commit

Permalink
Merge pull request #7 from rios0rios0/fix/config
Browse files Browse the repository at this point in the history
fix(config): fixed config finder conflicting with arg parser, corrected pipeline commands
  • Loading branch information
k4yt3x authored Jun 30, 2023
2 parents 62af38c + 8e7fdd0 commit d8da6de
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 26 additions & 8 deletions cmd/autobump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit d8da6de

Please sign in to comment.