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

run: once not working for a task included multiple times #1498

Closed
maxmzkrcensys opened this issue Feb 6, 2024 · 4 comments · May be fixed by #1804
Closed

run: once not working for a task included multiple times #1498

maxmzkrcensys opened this issue Feb 6, 2024 · 4 comments · May be fixed by #1804
Labels
type: bug Something not working as intended.

Comments

@maxmzkrcensys
Copy link

maxmzkrcensys commented Feb 6, 2024

  • Task version:
task --version    
Task version: v3.34.1 (h1:yAAxUM54zoaHv+OtDnGgkWSVeiRuaOCn1lPUXPQQA0o=)
  • Operating system:
lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: Fedora
Description:    Fedora release 38 (Thirty Eight)
Release:        38
Codename:       ThirtyEight
  • Experiments enabled: none

When multiple task files include the same file and then depend on the same task, the depended on task gets executed twice even when run: once is set.

./tools/input

./tools/taskfile.yml
version: "3"

tasks:
  exe:
    run: once
    sources:
      - ./input
    generates:
      - ./output
    cmds:
      - touch output

./lib/a/taskfile.yml
version: "3"

includes:
  tools:
    taskfile: ../../tools
    dir: ../../tools
    internal: true

tasks:
  lib:
    deps:
      - tools:exe
    cmds:
      - touch a

./lib/b/taskfile.yml
version: "3"

includes:
  tools:
    taskfile: ../../tools
    dir: ../../tools
    internal: true

tasks:
  lib:
    deps:
      - tools:exe
    cmds:
      - touch b

./taskfile.yml
version: "3"

tasks:
  all:
    deps:
      - a:lib
      - b:lib

includes:
  a:
    taskfile: ./lib/a
    dir: ./lib/a

  b:
    taskfile: ./lib/b
    dir: ./lib/b
task all
task: [a:tools:exe] touch output
task: [b:tools:exe] touch output
task: [b:lib] touch b
task: [a:lib] touch a

In the setup I have 4 taskfiles. tools/taskfile.yml defines building a tool that is needed to build the a and b lib. lib/a/taskfile.yml and lib/b/taskfile.yml both include tools/taskfile.yml and depend on the building of the tool. The root taskfile.yml includes lib/a and lib/b and defines an all task to build both lib/a and lib/b.

Even with run: once set in the task that builds the tool, the task gets run twice.

Note that if the taskfiles are collapsed into a single task file, this issue is not present.

version: "3"

tasks:
  tools:exe:
    run: once
    sources:
      - ./tools/input
    generates:
      - ./tools/output
    cmds:
      - touch ./tools/output

  a:lib:
    deps:
      - tools:exe
    cmds:
      - touch lib/a

  b:lib:
    deps:
      - tools:exe
    cmds:
      - touch lib/b

  all:
    deps:
      - a:lib
      - b:lib
task all
task: [tools:exe] touch ./tools/output
task: [a:lib] touch lib/a
task: [b:lib] touch lib/b
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Feb 6, 2024
@andreynering andreynering changed the title Run included dep only once run: once not working for a task included multiple times Feb 6, 2024
@andreynering andreynering added type: bug Something not working as intended. and removed state: needs triage Waiting to be triaged by a maintainer. labels Feb 6, 2024
@maxmzkrcensys
Copy link
Author

Would it make sense to use the hash of location instead of the Task.Task? Looking at what fields are available in Task, that looks like the quickest way to get a unique id for the task no matter how it's included.

Additionally, would it make sense to add a new value to the run enum to differentiate once per include vs once across all includes?

Happy to put up a PR if I'm going down the right track for this

@libre-man
Copy link

libre-man commented Sep 12, 2024

This bug is biting us too at the moment. We can't really work around this, because it also means that of some tasks we will have multiple running at the same time.

@libre-man
Copy link

The issue is that LocalName() of a Task only tries to strip it's own namespace, not namespaces of other taskfiles too.

@pd93
Copy link
Member

pd93 commented Sep 13, 2024

This bug was fixed in #1655. The example given by @maxmzkrcensys now works as intended (since v3.38.0).
@libre-man If you're still seeing issues, please open a new issue with a reproducible example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something not working as intended.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants