Skip to content

Commit

Permalink
handle workir properly (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
jney authored Aug 25, 2022
1 parent 30fc6fd commit e8e0ffb
Show file tree
Hide file tree
Showing 12 changed files with 416 additions and 212 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1
jobs:
test:
docker:
- image: circleci/golang:1.16
- image: circleci/golang
steps:
- checkout
- run:
Expand All @@ -11,7 +11,7 @@ jobs:
go test -race ./...
release:
docker:
- image: circleci/golang:1.16
- image: circleci/golang
steps:
- checkout
- run:
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.45
0.0.46
3 changes: 2 additions & 1 deletion commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ var buildCmd = &cobra.Command{
Aliases: []string{"b"},
Short: "build your script for updated files",
Run: func(cmd *cobra.Command, args []string) {
jww.WARN.Println("using 'gally build' is deprecated now use 'gally run build'")
handleVerboseFlag()
var p *string = nil
if projectName != "" {
p = &projectName
}
if tag != "" {
if err := project.BuildTag(p, tag, rootDir); err != nil {
jww.ERROR.Fatalf("could not build properly project: %v", err)
jww.ERROR.Fatalf("could not build properly project %s@%s in %q: %v", *p, tag, rootDir, err)
}
return
}
Expand Down
24 changes: 17 additions & 7 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,25 @@ import (
)

var (
force bool
noDependency bool
projectName string
rootDir string
tag string
updated bool
verbose bool
allProjects bool
force bool
ignoreMissing bool
noDependency bool
projectName string
rootDir string
tag string
updated bool
verbose bool
)

func addAllProjectsFlag(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVarP(&allProjects, "all", "a", false, "all the command")
}

func addIgnoreMissingFlag(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVarP(&ignoreMissing, "--ignore-missing", "", false, "ignore missing script")
}

func addForceFlag(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVarP(&force, "force", "f", false, "force the command")
}
Expand Down
15 changes: 9 additions & 6 deletions commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,37 @@ var runCmd = &cobra.Command{
Use: "run [script]",
Aliases: []string{"exec"},
Short: "run your script on projects having updated files",
Long: `run your script on projects having updated files.
Be careful using without option --ignore-missing would mean the script is defined on *every* project`,
Run: func(cmd *cobra.Command, args []string) {
handleVerboseFlag()
if len(args) == 0 {
jww.ERROR.Fatalf("no script provided in command")
}
projects := project.Projects{}
if projectName != "" {
p := project.FindByName(rootDir, projectName)
if p == nil {
projects[projectName] = project.FindByName(rootDir, projectName)
if projects[projectName] == nil {
jww.ERROR.Fatalf("could not find project %q", projectName)
}
projects[projectName] = project.FindByName(rootDir, projectName)
} else if force {
} else if allProjects {
projects = project.FindAll(rootDir)
} else {
projects = project.FindAllUpdated(rootDir, noDependency)
}
script := args[0]
for _, p := range projects {
if err := p.Run(script); err != nil {
err := p.Run(script)
if err != nil && (!ignoreMissing || err != project.ErrCmdDoesNotExist) {
jww.ERROR.Fatalf("could not run properly script %q for %q: %v", script, p.Name, err)
}
}
},
}

func init() {
addForceFlag(runCmd)
addAllProjectsFlag(runCmd)
addIgnoreMissingFlag(runCmd)
addNoDependencyFlag(runCmd)
addProjectFlag(runCmd)
rootCmd.AddCommand(runCmd)
Expand Down
1 change: 0 additions & 1 deletion examples/notag/.gally.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ strategies:
branch: master
previous-commit:
only: master
build: echo go building notag!
env:
- name: NAMESPACE
value: "demo"
27 changes: 23 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
module github.com/missena-corp/gally

go 1.16
go 1.19

require (
github.com/google/go-cmp v0.5.5
github.com/spf13/cobra v1.1.3
github.com/google/go-cmp v0.5.8
github.com/spf13/cobra v1.5.0
github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/viper v1.7.1
github.com/spf13/viper v1.12.0
)

require (
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.3 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
golang.org/x/sys v0.0.0-20220823224334-20c2bfdbfe24 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit e8e0ffb

Please sign in to comment.