Skip to content

misleading feature: "generates" and checksum checker #2181

@viktorasm

Description

@viktorasm

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: fingerprintingChanges related to checksums and caching.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions