task icon indicating copy to clipboard operation
task copied to clipboard

misleading feature: "generates" and checksum checker

Open viktorasm opened this issue 8 months ago • 1 comments

Description

It's very misleading how task.generates feature works.

One would assume that the task will run if combined checksum of sources and outputs does not match sources/results of previous execution, e.g. having such definition

sources:
   - openapi.yaml
generates:
   - client/go/**/*.go

.. One would expect that if some generated files are missing, or are unintentionally changed, this will cause task to rerun.

How it actually works with checksum checker:

  • Checksum is calculated and checked for sources;
  • For generates list, it's only verified that glob matches any files.

This means that "generates" is only somewhat usable with absolute file names, as that would ensure the files existence at the very least. With globing, if some of the files are deleted, that's never detected.

The current checksum implementation handling of the "generates" :

	if len(t.Generates) > 0 {
		// For each specified 'generates' field, check whether the files actually exist
		for _, g := range t.Generates {
			if g.Negate {
				continue
			}
			generates, err := glob(t.Dir, g.Glob)
			if os.IsNotExist(err) {
				return false, nil
			}
			if err != nil {
				return false, err
			}
			if len(generates) == 0 {
				return false, nil
			}
		}
	}

we can see that the Task will be considered out of date with respect to "generates" only if glob value is invalid or it is returning no files.

Probably the best fix would be to actually include generated files into checksum calculation.

Version

main branch

Operating system

all

Experiments Enabled

No response

Example Taskfile


viktorasm avatar Apr 15 '25 12:04 viktorasm

This is really one of those features that is REALLY required. For us to live up to the "simpler than Make" statement. The basic feature of only executing when required needs to be supported.

My previous issue: #1741

My last statement: https://github.com/go-task/task/issues/1741#issuecomment-2437013900

Other related issues: #1945

Related PR: #1816

ameershira avatar Apr 22 '25 09:04 ameershira