Skip to content

Commit 908c04c

Browse files
authored
fix: allows scanning of root Earthfile (#86)
1 parent 37d6f60 commit 908c04c

File tree

3 files changed

+34
-26
lines changed

3 files changed

+34
-26
lines changed

Earthfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
VERSION 0.8
2+
3+
# This target exists solely for validating the root Earthfile is scanned
4+
test:
5+
FROM ubuntu:latest
6+
7+
RUN echo "Testing"

cli/cmd/testdata/scan/3.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ exec forge --ci scan --earthfile .
77
cmp stdout golden_ci.txt
88

99
-- golden.txt --
10-
{"./dir1":["foo","bar"],"./dir1/dir2":["foo","bar"],"./dir3/dir4/dir5":["foo"]}
10+
{".":["foo","bar"],"./dir1":["foo","bar"],"./dir1/dir2":["foo","bar"],"./dir3/dir4/dir5":["foo"]}
1111
-- golden_ci.txt --
12-
["./dir1+bar","./dir1+foo","./dir1/dir2+bar","./dir1/dir2+foo","./dir3/dir4/dir5+foo"]
12+
[".+bar",".+foo","./dir1+bar","./dir1+foo","./dir1/dir2+bar","./dir1/dir2+foo","./dir3/dir4/dir5+foo"]
1313
-- blueprint.cue --
1414
version: "1.0"
1515
-- Earthfile --

lib/project/project/loader.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,6 @@ func (p *DefaultProjectLoader) Load(projectPath string) (Project, error) {
6161
return Project{}, fmt.Errorf("failed to load blueprint: %w", err)
6262
}
6363

64-
if !rbp.Get("project").Exists() {
65-
p.logger.Debug("No project config found in blueprint, assuming root config")
66-
bp, err := validateAndDecode(rbp)
67-
if err != nil {
68-
p.logger.Error("Failed loading blueprint", "error", err)
69-
return Project{}, fmt.Errorf("failed loading blueprint: %w", err)
70-
}
71-
72-
return Project{
73-
Blueprint: bp,
74-
Path: projectPath,
75-
RawBlueprint: rbp,
76-
Repo: repo,
77-
RepoRoot: gitRoot,
78-
logger: p.logger,
79-
ctx: p.ctx,
80-
}, nil
81-
}
82-
83-
var name string
84-
if err := rbp.DecodePath("project.name", &name); err != nil {
85-
return Project{}, fmt.Errorf("failed to get project name: %w", err)
86-
}
87-
8864
efPath := filepath.Join(projectPath, "Earthfile")
8965
exists, err := afero.Exists(p.fs, efPath)
9066
if err != nil {
@@ -109,6 +85,31 @@ func (p *DefaultProjectLoader) Load(projectPath string) (Project, error) {
10985
ef = &efs
11086
}
11187

88+
if !rbp.Get("project").Exists() {
89+
p.logger.Debug("No project config found in blueprint, assuming root config")
90+
bp, err := validateAndDecode(rbp)
91+
if err != nil {
92+
p.logger.Error("Failed loading blueprint", "error", err)
93+
return Project{}, fmt.Errorf("failed loading blueprint: %w", err)
94+
}
95+
96+
return Project{
97+
Blueprint: bp,
98+
Earthfile: ef,
99+
Path: projectPath,
100+
RawBlueprint: rbp,
101+
Repo: repo,
102+
RepoRoot: gitRoot,
103+
logger: p.logger,
104+
ctx: p.ctx,
105+
}, nil
106+
}
107+
108+
var name string
109+
if err := rbp.DecodePath("project.name", &name); err != nil {
110+
return Project{}, fmt.Errorf("failed to get project name: %w", err)
111+
}
112+
112113
p.logger.Info("Loading tag data")
113114
var tag *ProjectTag
114115
gitTag, err := git.GetTag(repo)

0 commit comments

Comments
 (0)