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

Does not expand variables during first iteration #287

Closed
kovetskiy opened this issue Jan 25, 2020 · 2 comments · Fixed by #311
Closed

Does not expand variables during first iteration #287

kovetskiy opened this issue Jan 25, 2020 · 2 comments · Fixed by #311
Labels
area: variables Changes related to variables.
Milestone

Comments

@kovetskiy
Copy link
Contributor

kovetskiy commented Jan 25, 2020

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
@andreynering andreynering added type: bug Something not working as intended. v3 labels Feb 2, 2020
@andreynering
Copy link
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.

@andreynering andreynering added the area: variables Changes related to variables. label Mar 22, 2020
@andreynering andreynering linked a pull request May 17, 2020 that will close this issue
@andreynering
Copy link
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.

@pd93 pd93 added this to the v3 milestone Sep 19, 2023
@pd93 pd93 removed the type: bug Something not working as intended. label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: variables Changes related to variables.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants