toolkit: Possible bug with expressions and steps..outputs
I’m not sure where I should be posting this, or how I can report bugs, so I’m starting here. Please point me in the right direction if this isn’t the forum
My goal is to eloquently handle running (or NOT running) a step based on the value of an output from a previous step. In this case i want to do custom things IF my semantic-release step actually cut a new version.
-
According to the docs it says the steps context is directly accessible via property name “steps”. However when you want to use this in an
jobs.<job_id>.steps.if
expression, you need to access likejob.steps...
, i.e.if: job.steps.<step id>.status == failure
-
However the actual
steps
context as documented (with outputs) is NOT accessible inside anif
expression -
Everywhere else, ${{ steps.<step id>.outputs }} works fine. In
env
it works, inrun
it works. Everything here works as expected:
- run: |
printenv
echo ${{ steps.semantic.outputs.semantic_release_version }}
echo $VERSION
echo "$OUTPUTS"
env:
VERSION: ${{ steps.semantic.outputs.semantic_release_version }}
OUTPUTS: ${{ toJson(steps.semantic.outputs) }}
- However, in an if expression
if: steps.<step id>.outputs.someOutput == 'foo'
, it throws an error:
- Your workflow file was invalid: .github/workflows/test.yml (Line: 42, Col: 13): Unrecognized named-value: 'steps'. Located at position 1 within expression: steps.semantic.outputs.semantic_release_version
Here’s a full example
name: testing outputs
on: push
jobs:
tester:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/setup-node@v1
- uses: codfish/semantic-release-action@testing
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: test outputs
# printenv shows OUTPUTS object but NOT JOB_OUTPUTS
# echo ${{ steps.semantic.outputs.semantic_release_version }} works as expected
# echo $VERSION works as expected
run: |
printenv
echo ${{ steps.semantic.outputs.semantic_release_version }}
echo $VERSION # this works
env:
VERSION: ${{ steps.semantic.outputs.semantic_release_version }}
OUTPUTS: ${{ toJson(steps.semantic.outputs) }}
JOB_OUTPUTS: ${{ toJson(job.steps.semantic.outputs) }}
# this does NOT work, whether using true or 'true'
- if: job.steps.semantic.outputs.semantic_release_bool == 'true'
run: |
echo "steps.semantic.outputs.semantic_release_bool is true"
# this actually throws the above error
- if: steps.semantic.outputs.semantic_release_bool == 'true'
run: |
echo "steps.semantic.outputs.semantic_release_bool is true"
# this does NOT work
- if: contains(job.steps.semantic.outputs.semantic_release_version, '.')
run: |
echo "steps.semantic.outputs.semantic_release_bool is true"
I’m using https://github.com/codfish/semantic-release-action/compare/testing-outputs?expand=1 for testing (tagged with testing
).
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (4 by maintainers)
Commits related to this issue
- docs: update usage documentation to show if property Reference: https://github.com/actions/toolkit/issues/96 — committed to codfish/semantic-release-action by codfish 5 years ago
- docs: update usage documentation to show if property Reference: https://github.com/actions/toolkit/issues/96 — committed to virgoone/semantic-release-action by codfish 5 years ago
@damccorm thanks for the quick reply!
I’ve confirmed
if: job.steps.semantic.outputs.semantic_release_bool == 'true'
does not work. Let me know if you want me to set up another test for you guys. You should also be able to use the full snippet in the issue description to recreate.IMO, it would make sense to be able to access the
steps
context normally in anif
expression, same way we’re able to accessgithub
context for instance. Maybe there’s a reason this isn’t possible at the moment though.That being said if I have to workaround that by accessing via the
job
context that’s not bad at all, but it seems as though only the status is made available to us, i.e.if: job.steps.<step id>.status == failure
and not the outputs.FYI @ericsciple @thboop
Hey everyone, I have been watching this thread real-time and tested these changes and I can confirm it all works as of right now. Below is an example yaml file:
This will give you the following output:
@codfish I actually have a PR to doc this right now - https://github.com/actions/toolkit/pull/105
To persist an output variable you can do
echo ::set-output name=FOO::BAR
, to persist an env variable you can doecho ::set-env name=FOO::BAR
Thanks @damccorm @thboop @ericsciple @dakale
Can confirm this is now working for me as well. https://github.com/codfish/actions-playground/blob/master/.github/workflows/release.yml#L48
much appreciated! You can close if you want
later this week or really next week.
@codfish the pr is merged for the outputs issue. the fix will roll out with the next runner update. @TingluoHuang do you know when?
@hamelsmu steps.foo.status is not a thing today. i’ll open a pr to remove that from the docs.
Thanks for the write-up and detailed example @codfish!
We are working on making the steps context and their associated outputs(accessible via
steps.<step id>.outputs.<output name>
) available inside a step’s if statement. We’ll make sure the docs reflect this as well, but this behavior isn’t currently available.@dakale, FYI, this is related to the steps context if statement behavior you were looking into.