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

Computed environment variables have started happening in the task directory. #1536

Closed
PaulPopat opened this issue Mar 5, 2024 · 4 comments
Closed
Labels
area: variables Changes related to variables. type: bug Something not working as intended.

Comments

@PaulPopat
Copy link

  • Task version: v3.35.1
  • Operating system: Ubuntu Server
  • Experiments enabled: None
  • Last working version: v3.34.1

When running a computed environment at the top of a task file, the working directory used to be the task file directory. Now it is the directory specified in the specific task. This means that referencing setup files is breaking.

version: '3'

env:
  ACCESS_KEY:
    sh: ./scripts/login.sh

tasks:
  broken-task:
    # Looks for "{{.TASKFILE_DIR}}/test/scripts/login.sh" for the value of "ACCESS_KEY" as opposed to "{{.TASKFILE_DIR}}/scripts/login.sh"
    dir: "{{.TASKFILE_DIR}}/test"
    cmds:
      - echo "$ACCESS_KEY"

  working-task:
    cmds:
      - echo "$ACCESS_KEY"
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Mar 5, 2024
@pd93
Copy link
Member

pd93 commented Mar 5, 2024

@PaulPopat I'm not able to reproduce this. Results on my machine with the following content in ./scripts/login.sh:

#!/bin/bash
pwd

v3.34.1

❯ task --version                   
Task version: v3.34.1 (h1:yAAxUM54zoaHv+OtDnGgkWSVeiRuaOCn1lPUXPQQA0o=)
❯ task working-task
task: [working-task] echo "$ACCESS_KEY"
/home/pete/dev/github.com/go-task/task/tmp/1536
❯ task broken-task 
task: [broken-task] echo "$ACCESS_KEY"
/home/pete/dev/github.com/go-task/task/tmp/1536

v3.35.1

❯ task --version                                        
Task version: v3.35.1 (h1:zjQ3tLv+LIStDDTzOQx8F97NE/8FSTanjZuwgy/hwro=)
❯ task working-task                                     
task: [working-task] echo "$ACCESS_KEY"
/home/pete/dev/github.com/go-task/task/tmp/1536
❯ task broken-task                                      
task: [broken-task] echo "$ACCESS_KEY"
/home/pete/dev/github.com/go-task/task/tmp/1536

What is inside your ./scripts/login.sh? and what directory/command are you using to run the task?

@PaulPopat
Copy link
Author

Hi @pd93 Sorry it appears I miss a critical step in trying to make a minimal reproduction. It must be a sub task and it must be called without the - task: task:name syntax. We are doing this in our live example because we are running a task as background and piping it into a log file for running integration tests.

In Taskfile.yml

version: '3'

env:
  TEST_STRING:
    sh: ./scripts/get-data.sh

tasks:
  test:working:
    cmds:
      - echo "$TEST_STRING"

  test:broken:
    cmds:
      - task test:working
    dir: "{{.TASKFILE_DIR}}/test/other"

In scripts/get-data.sh

#!/bin/bash

echo "TEST: $(pwd)"

Console output

ubuntu in 🌐 ip-10-200-9-185 in ~/task-file-test via  v18.19.0 on ☁️  (eu-west-2) 
❯ npm install -g @go-task/cli@v3.34.1

changed 2 packages in 1s

ubuntu in 🌐 ip-10-200-9-185 in ~/task-file-test via  v18.19.0 on ☁️  (eu-west-2) 
❯ task test:broken
task: [test:broken] task test:working
task: [test:working] echo "$TEST_STRING"
TEST: /workspace/ubuntu/task-file-test

ubuntu in 🌐 ip-10-200-9-185 in ~/task-file-test via  v18.19.0 on ☁️  (eu-west-2) 
❯ npm install -g @go-task/cli@v3.35.0

changed 2 packages in 1s

ubuntu in 🌐 ip-10-200-9-185 in ~/task-file-test via  v18.19.0 on ☁️  (eu-west-2) 
❯ task test:broken
task: [test:broken] task test:working
stat /workspace/ubuntu/task-file-test/test/other/scripts/get-data.sh: no such file or directory
task: Command "./scripts/get-data.sh" failed: exit status 127
task: Failed to run task "test:broken": exit status 1

A snippet to better demonstrate our use case

version: '3'

env:
  AWS_ACCESS_KEY_ID:
    sh: ./utilities/assume.sh AWS_ACCESS_KEY_ID
  AWS_SECRET_ACCESS_KEY:
    sh: ./utilities/assume.sh AWS_SECRET_ACCESS_KEY
  AWS_SESSION_TOKEN:
    sh: ./utilities/assume.sh AWS_SESSION_TOKEN

tasks:
  test:browser:project:
    dir: "{{.TASKFILE_DIR}}/packages/tests"
    cmds:
      - rm -f ../../artifacts/ui-tests-app.log
      - task launch:app > ../../artifacts/ui-tests-app.log && sleep 2 &
      - task: utils:wait-for-ports
        vars:
          PORTS: '8888,7654,5432'
      - yarn run test --all=true

@pd93
Copy link
Member

pd93 commented Mar 7, 2024

@PaulPopat that issue was fixed in 3.35.1. From your console output, I can see that you're still running 3.35.0. I've just published the patch to npm, so you should be able to update and try again. Please let me know if this fixes the issue for you.

@pd93 pd93 added type: bug Something not working as intended. area: variables Changes related to variables. state: awaiting response Waiting for issue author to respond. and removed state: needs triage Waiting to be triaged by a maintainer. labels Mar 7, 2024
@PaulPopat
Copy link
Author

That has done it. Thank you very much!

@task-bot task-bot removed the state: awaiting response Waiting for issue author to respond. label Mar 7, 2024
@pd93 pd93 closed this as completed Mar 7, 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. type: bug Something not working as intended.
Projects
None yet
Development

No branches or pull requests

3 participants