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: ROOT_TASKFILE when Entrypoint is not set #1708

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

vmaerten
Copy link
Member

@vmaerten vmaerten commented Jul 3, 2024

fixes #1706

@vmaerten vmaerten requested review from andreynering and pd93 July 3, 2024 11:46
@vmaerten
Copy link
Member Author

vmaerten commented Jul 3, 2024

I thought put a default value here

	entrypoint := flags.Entrypoint
	if entrypoint == "" {
		entrypoint = "Taskfile.yml"
	}

but it would break

func getDefaultDir(entrypoint, dir string) string {
	// If the entrypoint and dir are empty, we default the directory to the current working directory
	if dir == "" {
		if entrypoint == "" {
			wd, err := os.Getwd()
			if err != nil {
				return ""
			}
			dir = wd
		}
		return dir
	}

	// If the directory is set, ensure it is an absolute path
	var err error
	dir, err = filepath.Abs(dir)
	if err != nil {
		return ""
	}

	return dir
}

I don't know which solution do you prefer

@@ -180,10 +180,14 @@ func (c *Compiler) ResetCache() {
}

func (c *Compiler) getSpecialVars(t *ast.Task) (map[string]string, error) {
entrypoint := c.Entrypoint
if entrypoint == "" {
entrypoint = "Taskfile.yml"
Copy link
Member

@andreynering andreynering Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the default is not necessarily Taskfile.yml. We have a list of 8 possible file names that are detected and work by default:

defaultTaskfiles = []string{
"Taskfile.yml",
"taskfile.yml",
"Taskfile.yaml",
"taskfile.yaml",
"Taskfile.dist.yml",
"taskfile.dist.yml",
"Taskfile.dist.yaml",
"taskfile.dist.yaml",
}

In the taskfile package we have code that will try to detect it. It may be a bit tricky, but in order to be reliable we need to reuse that code somehow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree I missed that part
What I did here, export taskfile.go in a new package in order to have access to DefaultTaskfiles
Then I check (as it's done on Exists func) if the file exist. I did not reuse the Exist function because we do not want to log smth

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and it works with Taskfile.dist.yml

@vmaerten vmaerten force-pushed the fix/root_taskfile branch from 4a8c79c to 0246192 Compare July 5, 2024 14:28
@vmaerten vmaerten force-pushed the fix/root_taskfile branch from 0246192 to 2914609 Compare July 5, 2024 14:29
@andreynering andreynering self-requested a review July 5, 2024 14:32
internal/compiler/compiler.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.ROOT_TASKFILE returns the root directory instead of the file
2 participants