From 71bf70a95a451481a83f179a42910ac40cde534b Mon Sep 17 00:00:00 2001 From: Joshua Gilman Date: Wed, 23 Oct 2024 08:04:40 -0700 Subject: [PATCH 1/3] fix: allows scanning of root Earthfile --- Earthfile | 6 +++++ lib/project/project/loader.go | 49 ++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 Earthfile diff --git a/Earthfile b/Earthfile new file mode 100644 index 0000000..b9cf8ba --- /dev/null +++ b/Earthfile @@ -0,0 +1,6 @@ +VERSION 0.8 + +test: + FROM ubuntu:latest + + RUN echo "Testing" \ No newline at end of file diff --git a/lib/project/project/loader.go b/lib/project/project/loader.go index 33d0477..363d28a 100644 --- a/lib/project/project/loader.go +++ b/lib/project/project/loader.go @@ -61,30 +61,6 @@ func (p *DefaultProjectLoader) Load(projectPath string) (Project, error) { return Project{}, fmt.Errorf("failed to load blueprint: %w", err) } - if !rbp.Get("project").Exists() { - p.logger.Debug("No project config found in blueprint, assuming root config") - bp, err := validateAndDecode(rbp) - if err != nil { - p.logger.Error("Failed loading blueprint", "error", err) - return Project{}, fmt.Errorf("failed loading blueprint: %w", err) - } - - return Project{ - Blueprint: bp, - Path: projectPath, - RawBlueprint: rbp, - Repo: repo, - RepoRoot: gitRoot, - logger: p.logger, - ctx: p.ctx, - }, nil - } - - var name string - if err := rbp.DecodePath("project.name", &name); err != nil { - return Project{}, fmt.Errorf("failed to get project name: %w", err) - } - efPath := filepath.Join(projectPath, "Earthfile") exists, err := afero.Exists(p.fs, efPath) if err != nil { @@ -109,6 +85,31 @@ func (p *DefaultProjectLoader) Load(projectPath string) (Project, error) { ef = &efs } + if !rbp.Get("project").Exists() { + p.logger.Debug("No project config found in blueprint, assuming root config") + bp, err := validateAndDecode(rbp) + if err != nil { + p.logger.Error("Failed loading blueprint", "error", err) + return Project{}, fmt.Errorf("failed loading blueprint: %w", err) + } + + return Project{ + Blueprint: bp, + Earthfile: ef, + Path: projectPath, + RawBlueprint: rbp, + Repo: repo, + RepoRoot: gitRoot, + logger: p.logger, + ctx: p.ctx, + }, nil + } + + var name string + if err := rbp.DecodePath("project.name", &name); err != nil { + return Project{}, fmt.Errorf("failed to get project name: %w", err) + } + p.logger.Info("Loading tag data") var tag *ProjectTag gitTag, err := git.GetTag(repo) From 33dd3595d3471b7a946dfc5f9babd2d96aa949c0 Mon Sep 17 00:00:00 2001 From: Joshua Gilman Date: Wed, 23 Oct 2024 08:10:51 -0700 Subject: [PATCH 2/3] wip: fix test --- cli/cmd/testdata/scan/3.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/cmd/testdata/scan/3.txt b/cli/cmd/testdata/scan/3.txt index feaac32..1b1aacb 100644 --- a/cli/cmd/testdata/scan/3.txt +++ b/cli/cmd/testdata/scan/3.txt @@ -7,9 +7,9 @@ exec forge --ci scan --earthfile . cmp stdout golden_ci.txt -- golden.txt -- -{"./dir1":["foo","bar"],"./dir1/dir2":["foo","bar"],"./dir3/dir4/dir5":["foo"]} +{".":["foo","bar"],"./dir1":["foo","bar"],"./dir1/dir2":["foo","bar"],"./dir3/dir4/dir5":["foo"]} -- golden_ci.txt -- -["./dir1+bar","./dir1+foo","./dir1/dir2+bar","./dir1/dir2+foo","./dir3/dir4/dir5+foo"] +[".+bar",".+foo","./dir1+bar","./dir1+foo","./dir1/dir2+bar","./dir1/dir2+foo","./dir3/dir4/dir5+foo"] -- blueprint.cue -- version: "1.0" -- Earthfile -- From 1ee33a7e37d9d82b20dbf3ce1ffa885a0ee8df31 Mon Sep 17 00:00:00 2001 From: Joshua Gilman Date: Wed, 23 Oct 2024 08:17:52 -0700 Subject: [PATCH 3/3] wip: adds comment --- Earthfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Earthfile b/Earthfile index b9cf8ba..2da4035 100644 --- a/Earthfile +++ b/Earthfile @@ -1,5 +1,6 @@ VERSION 0.8 +# This target exists solely for validating the root Earthfile is scanned test: FROM ubuntu:latest