Skip to content

Does not expand variables during first iteration #287

Closed

Description

@kovetskiy

Hi

I wanted to generate a sort of semantic version using the following scheme: tag is major.minor and use number of commits on top of tag as patch part of sem ver.

So I did something like this:

version: '2'

vars:
  tag:
    sh: 'git describe --tags --abbrev=0'
  commits_on_top_of_branch:
    sh: "git rev-list '{{.tag}}'.. --count"

tasks:
  default:
    cmds:
      - echo '{{.tag}}'.'{{.commits_on_top_of_branch}}'

But this taskfile will generate an error

fatal: ambiguous argument '<no value>..': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
task: Command "git rev-list '<no value>'.. --count" in taskvars file failed: exit status 128

That's because the iteration (expansion) of merge doesn't respect variables resolved in the same expansion cycle because templater doesn't reset its a sort of cache:

merge cycle:
https://github.com/go-task/task/blob/master/internal/compiler/v2/compiler_v2.go#L55-L73

here strMap is like a cache which is never reseted
https://github.com/go-task/task/blob/master/internal/templater/templater.go#L32-L34

Is there any workaround for it except these two:

  • git rev-list $(git describe --tags --abbrev=0).. --count because it means git describe is called two times (one for tag)
  • git rev-list '{{.tag}}'.. --count || true

Activity

  1. andreynering commented on Feb 2, 2020

    @andreynering
    Member

    Hi @kovetskiy, thanks for opening this issue!

    Somewhat related to #218.

    I want to rewrite how vars work on v3 to avoid this kind of bugs, but I'm been struggling to find the time to do so.

  2. linked a pull request that will close this issuev3: Variables refactoring #311on May 17, 2020
  3. andreynering commented on May 17, 2020

    @andreynering
    Member

    After #311 some of the confusion with variables should have been fixed. Task will now respect the order of declaration of variables.

    If possible, give the v3 branch a try and give some feedback before the final release.

  4. added this to the v3 milestone on Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Fields

    No fields configured for bug.

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions