Skip to content

Commit

Permalink
Merge pull request #2 from launchrctl/1-update_error_codes
Browse files Browse the repository at this point in the history
#1: update returning errors, go.mod, fix typos.
  • Loading branch information
iignatevich authored Dec 21, 2023
2 parents 7ba44bf + 6c31e88 commit 5a1fcf9
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 70 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# bump-updated
Update the version of Ansible roles which were updated in last commit
Update the version of resources that were updated in last commit

### List of excluded files
- README.md
- README.svg
29 changes: 20 additions & 9 deletions bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
)

var (
errEmptyPath = errors.New("empty resource path")
errFailedMeta = errors.New("failed to open plasma.yaml")
errEmptyPath = errors.New("empty resource path")
errNoUpdate = errors.New("no resources to update")
errSkipBadCommit = errors.New("skipping bump, as the latest commit is already by the bumper tool")
errFailedMeta = errors.New("failed to open plasma.yaml")
)

var kinds = map[string]string{
Expand All @@ -29,8 +31,9 @@ var kinds = map[string]string{
"entity": "entities",
}

var unversionableFiles = map[string]bool{
"README.md": true,
var unversionedFiles = map[string]struct{}{
"README.md": {},
"README.svg": {},
}

// PromptError prints an error.
Expand Down Expand Up @@ -156,16 +159,25 @@ func (k *bumpUpdatedService) ServiceInfo() launchr.ServiceInfo {
return launchr.ServiceInfo{}
}

func printMemo() {
fmt.Println("List of unversioned files:")
for k := range unversionedFiles {
fmt.Println(k)
}
fmt.Print("\n")
}

func (k *bumpUpdatedService) Bump() error {
fmt.Println("Bump updated versions...")
printMemo()

git, err := getRepo()
if err != nil {
return err
}

if git.IsOwnCommit() {
fmt.Println("Skipping bump, as the latest commit is already by the bumper tool.")
return nil
return errSkipBadCommit
}

files, err := git.getLatestModifiedFiles()
Expand All @@ -175,8 +187,7 @@ func (k *bumpUpdatedService) Bump() error {

resources := k.collectResources(files)
if len(resources) == 0 {
fmt.Println("There are no resources to update.")
return nil
return errNoUpdate
}

version, err := git.GetLastCommitShortHash()
Expand Down Expand Up @@ -251,7 +262,7 @@ func isUpdatableKind(kind string) bool {

func isVersionableFile(path string) bool {
name := filepath.Base(path)
_, ok := unversionableFiles[name]
_, ok := unversionedFiles[name]
return !ok
}

Expand Down
2 changes: 1 addition & 1 deletion git.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (r *BumperRepo) getLatestModifiedFiles() ([]string, error) {

// Commit stores the current changes to the Git repository with the default commit message and author.
func (r *BumperRepo) Commit() error {
fmt.Println("Commits changes to updated resources")
fmt.Println("Commit changes to updated resources")
w, _ := r.git.Worktree()
status, _ := w.Status()

Expand Down
38 changes: 20 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,58 +1,60 @@
module github.com/launchrctl/bump-updated

go 1.20
go 1.21

toolchain go1.21.4

require (
github.com/launchrctl/launchr v0.2.1
github.com/launchrctl/launchr v0.5.2
github.com/spf13/cobra v1.7.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230923063757-afb1ddc0824c // indirect
github.com/a8m/envsubst v1.4.2 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/containerd/containerd v1.7.7 // indirect
github.com/cloudflare/circl v1.3.6 // indirect
github.com/containerd/containerd v1.7.11 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v24.0.6+incompatible // indirect
github.com/docker/docker v24.0.7+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.10.0
github.com/go-git/go-git/v5 v5.11.0
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/klauspost/compress v1.17.1 // indirect
github.com/moby/moby v24.0.6+incompatible // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/moby/moby v24.0.7+incompatible // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/signal v0.7.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc5 // indirect
github.com/opencontainers/runc v1.1.9 // indirect
github.com/opencontainers/runc v1.1.10 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.2.0 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/tools v0.16.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1
)
Loading

0 comments on commit 5a1fcf9

Please sign in to comment.