Skip to content

Commit

Permalink
nullstone iac test will find IaC files with .yml *or* .yaml fil…
Browse files Browse the repository at this point in the history
…e extension.
  • Loading branch information
BSick7 committed Oct 31, 2024
1 parent 9994874 commit 9cc27de
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.0.126 (Oct 31, 2024)
* `nullstone iac test` will find IaC files with `.yml` *or* `.yaml` file extension.

# 0.0.125 (Oct 25, 2024)
* `nullstone iac test` now emits previous and updated values for `module_version`, `env_variable`, `variable`, and `connection` changes.
* Eliminated diffs in `nullstone iac test` for similar values.
Expand Down
16 changes: 10 additions & 6 deletions git/root_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,29 @@ import (
"path/filepath"
)

func GetRootDir(curDir string) (string, error) {
func GetRootDir(curDir string) (string, *git.Repository, error) {
if curDir == "" {
curDir = "."
}
repo, err := git.PlainOpen(curDir)
if err != nil {
if errors.Is(err, git.ErrRepositoryNotExists) {
return "", nil
return "", nil, nil
}
return "", err
return "", nil, err
}

worktree, err := repo.Worktree()
if err != nil {
if errors.Is(err, git.ErrIsBareRepository) {
return "", nil
return "", repo, nil
}
return "", err
return "", repo, err
}

return filepath.Abs(worktree.Filesystem.Root())
dir, err := filepath.Abs(worktree.Filesystem.Root())
if err != nil {
return "", nil, err
}
return dir, repo, nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/gosuri/uilive v0.0.4
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
github.com/nullstone-io/deployment-sdk v0.0.0-20240704122950-a55160b619cd
github.com/nullstone-io/iac v0.0.0-20241025133315-2ceba267e009
github.com/nullstone-io/iac v0.0.0-20241031195625-8151ddbc32b5
github.com/nullstone-io/module v0.2.9
github.com/ryanuber/columnize v2.1.2+incompatible
github.com/stretchr/testify v1.8.4
Expand Down
14 changes: 2 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -773,16 +773,10 @@ github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nullstone-io/deployment-sdk v0.0.0-20240704122950-a55160b619cd h1:3DWDfyQ9UGUfkfrK0PshA43fCp7PZuC/BjqYUBTZhi8=
github.com/nullstone-io/deployment-sdk v0.0.0-20240704122950-a55160b619cd/go.mod h1:7wc/0tmIELFoBTjNB5+hsyvTQD60mnt+BJ9/AU2/Cb8=
github.com/nullstone-io/iac v0.0.0-20241024171902-14c37bc7b1bf h1:y78wtR+Uz8NmnVkn1GL/qbXOJOp+dZR+zeepYXtCYsE=
github.com/nullstone-io/iac v0.0.0-20241024171902-14c37bc7b1bf/go.mod h1:pIufg9ixnvS3QZMOYLMAQ0evtP7ije4UKSfEvNyvaXk=
github.com/nullstone-io/iac v0.0.0-20241025124438-8b705a8f65d1 h1:7q+HosArU21aTz4ek/3nCKWbzlHSiOWYUM1AvwpFyS4=
github.com/nullstone-io/iac v0.0.0-20241025124438-8b705a8f65d1/go.mod h1:Mkgo0pxPwhbNus/zcrbYHoMO7o/bbJOOe8oQ/p/MgGQ=
github.com/nullstone-io/iac v0.0.0-20241025125212-d7e7df1a8f90 h1:FDMunMX4z2nHozF63thcbaeb7spLuH7vNRUvaGOzAtg=
github.com/nullstone-io/iac v0.0.0-20241025125212-d7e7df1a8f90/go.mod h1:QPw/RbUF3Fu4zs2cu63i+LFon5mU8HEkOCUrSJ7hC6U=
github.com/nullstone-io/iac v0.0.0-20241025130910-d1bacb7ce2a7 h1:YNP7/jL9BgAht5T4Wg05qQrkjZpaZRmfWMwvlFs6q9g=
github.com/nullstone-io/iac v0.0.0-20241025130910-d1bacb7ce2a7/go.mod h1:QPw/RbUF3Fu4zs2cu63i+LFon5mU8HEkOCUrSJ7hC6U=
github.com/nullstone-io/iac v0.0.0-20241025133315-2ceba267e009 h1:n/N00nAI27Og5ohn9Zg9Gw/1QKgAYNt4W3sFHuZlO/o=
github.com/nullstone-io/iac v0.0.0-20241025133315-2ceba267e009/go.mod h1:QPw/RbUF3Fu4zs2cu63i+LFon5mU8HEkOCUrSJ7hC6U=
github.com/nullstone-io/iac v0.0.0-20241031195625-8151ddbc32b5 h1:3G1Y+YdoKx0yTtOnqGfBjNyHs6G56J4jVbai1UaUTvo=
github.com/nullstone-io/iac v0.0.0-20241031195625-8151ddbc32b5/go.mod h1:QPw/RbUF3Fu4zs2cu63i+LFon5mU8HEkOCUrSJ7hC6U=
github.com/nullstone-io/module v0.2.9 h1:PcYhPEemBbc+RdP+Q/DF0+XlwJkkNb5R17Hfv8qaYyc=
github.com/nullstone-io/module v0.2.9/go.mod h1:btQiO0giVWDvvaQ7CLnPmuPPakJc55lAr8OlE1LK6hg=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down Expand Up @@ -1468,10 +1462,6 @@ gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKW
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/nullstone-io/go-api-client.v0 v0.0.0-20241024171723-15d99426ed39 h1:a4p5niu9gA0cV3MDbaqOF3OcViTk/K5RHewXkqRWJoM=
gopkg.in/nullstone-io/go-api-client.v0 v0.0.0-20241024171723-15d99426ed39/go.mod h1:EHFRYFcg303Tc9FDxBmvUrT8AncZ4KMT8FrRoGJnqDk=
gopkg.in/nullstone-io/go-api-client.v0 v0.0.0-20241025124353-3f5b48ade1c4 h1:Ge4+wevKyF+R8/KLJeF230WW7eJaG4KcE8MDJgLc87Q=
gopkg.in/nullstone-io/go-api-client.v0 v0.0.0-20241025124353-3f5b48ade1c4/go.mod h1:EHFRYFcg303Tc9FDxBmvUrT8AncZ4KMT8FrRoGJnqDk=
gopkg.in/nullstone-io/go-api-client.v0 v0.0.0-20241025125133-d3e3cc5ae079 h1:QM+6o67PfrdBSEEEbxkFWSmNU7d1kD3Ex6aVTJsqgtg=
gopkg.in/nullstone-io/go-api-client.v0 v0.0.0-20241025125133-d3e3cc5ae079/go.mod h1:EHFRYFcg303Tc9FDxBmvUrT8AncZ4KMT8FrRoGJnqDk=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
Expand Down
17 changes: 15 additions & 2 deletions iac/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"github.com/nullstone-io/iac"
"gopkg.in/nullstone-io/nullstone.v0/git"
"io"
"net/url"
"path/filepath"
"strings"
)

func Discover(dir string, w io.Writer) (*iac.ParseMapResult, error) {
Expand Down Expand Up @@ -34,14 +36,25 @@ func Discover(dir string, w io.Writer) (*iac.ParseMapResult, error) {
}

func parseIacFiles(dir string) (*iac.ParseMapResult, error) {
rootDir, err := git.GetRootDir(dir)
rootDir, repo, err := git.GetRootDir(dir)
if err != nil {
return nil, fmt.Errorf("error looking for repository root directory: %w", err)
} else if rootDir == "" {
rootDir = dir
}

pmr, err := iac.ParseConfigDir(filepath.Join(rootDir, ".nullstone"))
parseContext := "local"
remote, err := repo.Remote("origin")
if err == nil && remote != nil {
if remoteConfig := remote.Config(); remoteConfig != nil && len(remoteConfig.URLs) > 0 {
remoteUrl, err := url.Parse(remoteConfig.URLs[0])
if err == nil && remoteUrl != nil {
parseContext = strings.TrimSuffix(strings.TrimPrefix(remoteUrl.Path, "/"), ".git")
}
}
}

pmr, err := iac.ParseConfigDir(parseContext, filepath.Join(rootDir, ".nullstone"))
if err != nil {
return nil, fmt.Errorf("error parsing nullstone IaC files: %w", err)
}
Expand Down

0 comments on commit 9cc27de

Please sign in to comment.