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

Issue: Only first step is able to set output variables #758

Closed
domenix opened this issue Jul 20, 2021 · 8 comments · Fixed by #894
Closed

Issue: Only first step is able to set output variables #758

domenix opened this issue Jul 20, 2021 · 8 comments · Fixed by #894
Labels
kind/bug Something isn't working needs-work Extra attention is needed stale-exempt Exempt from stale

Comments

@domenix
Copy link

domenix commented Jul 20, 2021

System information

  • Operating System: Windows 10
  • Architecture: x64 (64-bit)
  • Apple M1: no
  • Docker version: 20.10.7
  • act version: c865a56 (current commit on master at the time of submission)

Expected behaviour

Output variables should be able to be defined in multiple steps under the same job

Actual behaviour

Currently, output variables can only be successfully defined in the first step inside a job (see official documentation for reference).

Workflow and/or repository

workflow
name: Test
on:
  workflow_dispatch:

jobs:
  set_vars:
    name: Set variables
    runs-on: ubuntu-latest
    steps:
    - id: set_1
      run: |
        echo "::set-output name=var_1::$(echo hello)"
        echo "::set-output name=var_2::$(echo world)"
    - id: set_2
      run: echo "::set-output name=var_3::$(echo 1234)"
    outputs:
      variable_1: ${{ steps.set_1.outputs.var_1 }}
      variable_2: ${{ steps.set_1.outputs.var_2 }}
      variable_3: ${{ steps.set_2.outputs.var_3 }}
  printing:
    name: Printing
    needs: set_vars
    runs-on: ubuntu-latest
    steps:
      - name: Print variables from another job
        run: |
          echo "${{ needs.set_vars.outputs.variable_1 }}" # Gets printed
          echo "${{ needs.set_vars.outputs.variable_2 }}" # As well
          echo "${{ needs.set_vars.outputs.variable_3 }}" # Empty space in logs, variable not resolved

Steps to reproduce

Run: act workflow_dispatch -W <path to the workflow file with content above>

act output

Log
[Test/Set variables] 🚀  Start image=catthehacker/ubuntu:act-latest
[Test/Set variables]   🐳  docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[Test/Set variables]   🐳  docker exec cmd=[mkdir -m 0777 -p /var/run/act] user=root
[Test/Set variables] ⭐  Run echo "::set-output name=var_1::$(echo hello)"
echo "::set-output name=var_2::$(echo world)"
[Test/Set variables]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /mnt/c/testrepo/workflow/set_1] user=
[Test/Set variables]   ⚙  ::set-output:: var_1=hello
[Test/Set variables]   ⚙  ::set-output:: var_2=world
time="2021-07-20T21:21:08+02:00" level=error msg="Unable to interpolate string '${{ steps.set_2.outputs.var_3 }}' - [TypeError: Cannot access member 'outputs' of undefined]"
[Test/Set variables]   ✅  Success - echo "::set-output name=var_1::$(echo hello)"
echo "::set-output name=var_2::$(echo world)"
[Test/Set variables] ⭐  Run echo "::set-output name=var_3::$(echo 1234)"
[Test/Set variables]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /mnt/c/testrepo/workflow/set_2] user=
[Test/Set variables]   ⚙  ::set-output:: var_3=1234
[Test/Set variables]   ✅  Success - echo "::set-output name=var_3::$(echo 1234)"
[Test/Printing     ] 🚀  Start image=catthehacker/ubuntu:act-latest
[Test/Printing     ]   🐳  docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[Test/Printing     ]   🐳  docker exec cmd=[mkdir -m 0777 -p /var/run/act] user=root
[Test/Printing     ] ⭐  Run Print variables from another job
[Test/Printing     ]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /mnt/c/testrepo/workflow/0] user=
| hello
| world
| 
[Test/Printing     ]   ✅  Success - Print variables from another job

Comments

May relate to issue 295 based on the comments at the end, but this one is a different issue as needs now work on the master branch, although not released yet.

This can affect workflows where the first step pulls in an action, e.g. using the digitalocean/action-doctl@v2 as the first step in order to execute doctl commands that gets the IP address of a Droplet and sets it as the output in the second step will not be possible due to this issue.

@domenix domenix added the kind/bug Something isn't working label Jul 20, 2021
@thejpanganiban

This comment has been minimized.

@catthehacker catthehacker added needs-work Extra attention is needed stale-exempt Exempt from stale labels Aug 13, 2021
@catthehacker catthehacker added this to Needs triage in Bug squashing via automation Aug 13, 2021
@BlackDex

This comment has been minimized.

@pcfighter
Copy link

I've debugged it a bit, used workflow from issue content. When you check step value here:
https://github.com/nektos/act/blob/master/pkg/runner/step_context.go#L64

you will see that while still being on step set_1 runner is trying to interpolate values from other step set_2, which sounds wrong.

@BlackDex
Copy link
Contributor

I tested the fix from @ChristopherHX ChristopherHX@fd9f40c that seems to work perfectly.

@chaoedu
Copy link

chaoedu commented Oct 15, 2021

I tested the fix from @ChristopherHX ChristopherHX@fd9f40c that seems to work perfectly.

So did I.

ChristopherHX referenced this issue in ChristopherHX/act Nov 2, 2021
aboutte pushed a commit to aboutte/act that referenced this issue Nov 10, 2021
aboutte pushed a commit to aboutte/act that referenced this issue Nov 10, 2021
aboutte pushed a commit to aboutte/act that referenced this issue Nov 10, 2021
lovesegfault added a commit to lovesegfault/nix-config that referenced this issue Nov 15, 2021
@BlackDex
Copy link
Contributor

BlackDex commented Nov 20, 2021

@catthehacker any chance of this being fixed via the changes @ChristopherHX made being implemented into the this branch?
What is needed for this to be fixed/tested further?

@catthehacker
Copy link
Member

What is needed for this to be fixed/tested further?

Pull request.

BlackDex added a commit to BlackDex/act that referenced this issue Nov 20, 2021
All credits go to @ChristopherHX which fixed this issue.
I only created a PR for this so it will be fixed in the upstream binary.

This fixes nektos#758
@BlackDex
Copy link
Contributor

@catthehacker ok, PR created.
I tested this on my own workflow files, and it seems to work.
The make test isn't working for me on the master branch so i can't really test it using the go-tests locally for some reason on my PR either.

@mergify mergify bot closed this as completed in #894 Nov 24, 2021
Bug squashing automation moved this from Needs triage to Closed Nov 24, 2021
mergify bot pushed a commit that referenced this issue Nov 24, 2021
* Don't interpolate joboutputs, before job is donei

All credits go to @ChristopherHX which fixed this issue.
I only created a PR for this so it will be fixed in the upstream binary.

This fixes #758

* Added output test

* Fix typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working needs-work Extra attention is needed stale-exempt Exempt from stale
Projects
Bug squashing
  
Closed
Development

Successfully merging a pull request may close this issue.

6 participants