Skip to content

fix: refresh for-loop commands after deps#2802

Open
lawrence3699 wants to merge 1 commit intogo-task:mainfrom
lawrence3699:fix/refresh-for-loop-cmds-after-deps
Open

fix: refresh for-loop commands after deps#2802
lawrence3699 wants to merge 1 commit intogo-task:mainfrom
lawrence3699:fix/refresh-for-loop-cmds-after-deps

Conversation

@lawrence3699
Copy link
Copy Markdown

Fixes #1494

When a task uses for: sources and the matching files are created by a dependency, the first run can skip the task because the command list is compiled before the deps materialize those sources.

The issue in #1494 looks like a fingerprint ordering bug at first, but the stale piece is actually the compiled cmds list. deps already run before fingerprinting; the missing step is refreshing commands that loop over sources or generates after those deps finish.

This patch keeps the fix scoped to that command-refresh step. It rebuilds the compiled command list after deps complete, so for: sources / for: generates loops see newly created files without re-running dynamic sh: vars.

Reproduction

version: '3'

tasks:
  create_deps:
    cmds:
      - touch a.dep b.dep c.dep

  use_deps:
    deps:
      - create_deps
    sources:
      - '*.dep'
    cmds:
      - for: sources
        cmd: echo {{.ITEM}}

Before this change, a clean run only executed create_deps, and use_deps could then be treated as up to date because its compiled command list was still empty.

After this change, the same first run executes the expanded use_deps commands and prints all three generated files.

Testing

  • go test ./... -run '^TestForCmdsRecompileAfterDeps$'
  • go test ./...
  • go run ./cmd/task -d /tmp/task1494-repro use_deps

Copilot AI review requested due to automatic review settings April 19, 2026 09:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an execution-order bug where tasks using cmds: - for: sources / for: generates could compile to an empty command list on the first run when those files are produced by dependencies. The PR refreshes the compiled command list after deps complete so loop expansion sees newly created files before fingerprinting/up-to-date checks.

Changes:

  • Refactors command compilation into a reusable compileCmds helper.
  • Recompiles t.Cmds after runDeps to refresh for: loop expansion over sources/generates.
  • Adds a regression test covering “deps create sources used by for: sources”.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
variables.go Extracts compileCmds and reuses it during task compilation.
task.go Rebuilds compiled command list after dependencies finish running.
executor_test.go Adds regression test to ensure for: sources expands after deps materialize files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

Bug: sources are checked before running deps

2 participants