Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allows scanning of root Earthfile #86

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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