Skip to content

Commit

Permalink
fix: allows scanning of root Earthfile (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgilman authored Oct 23, 2024
1 parent 37d6f60 commit 908c04c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
7 changes: 7 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
VERSION 0.8

# This target exists solely for validating the root Earthfile is scanned
test:
FROM ubuntu:latest

RUN echo "Testing"
4 changes: 2 additions & 2 deletions cli/cmd/testdata/scan/3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand Down
49 changes: 25 additions & 24 deletions lib/project/project/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit 908c04c

Please sign in to comment.