GithubHelp home page GithubHelp logo

Comments (15)

codfish avatar codfish commented on July 17, 2024 3

@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 an if expression, same way we're able to access github 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

from toolkit.

damccorm avatar damccorm commented on July 17, 2024 2

@codfish I actually have a PR to doc this right now - #105

To persist an output variable you can do echo ::set-output name=FOO::BAR, to persist an env variable you can do echo ::set-env name=FOO::BAR

from toolkit.

hamelsmu avatar hamelsmu commented on July 17, 2024 2

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:

name: test

on: push

jobs:

  build:
    runs-on: ubuntu-latest
 
    steps:
    - name: Step 1
      id: step1
      run: echo "::set-output name=VAR1::Hamel"

    - name: Step 2
      id: step2
      run: echo "::set-env name=VAR2::Husain"

    - name: emit env
      run: |
       echo $VAR2
       echo $VAR1
        
      env:
        VAR1: ${{ steps.step1.outputs.VAR1 }}

    - name: this should not run
      run: echo "This should not run"
      if: steps.step1.outputs.VAR1 == 'Lucy'

This will give you the following output:

image

from toolkit.

thboop avatar thboop commented on July 17, 2024 1

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.

from toolkit.

ericsciple avatar ericsciple commented on July 17, 2024 1

@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.

from toolkit.

TingluoHuang avatar TingluoHuang commented on July 17, 2024 1

later this week or really next week.

from toolkit.

codfish avatar codfish commented on July 17, 2024 1

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

from toolkit.

damccorm avatar damccorm commented on July 17, 2024

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

This isn't super well defined right now, we're working on clarifying that. Since this isn't an issue with the toolkit, it probably belongs here for now - with that said, we should have better avenues for feedback like this soon. For now, we can take this here.

Concerning the issue itself, I think that if: job.steps.semantic.outputs.semantic_release_bool == 'true' should work, but I'm not totally sure. @ericsciple or @thboop do you know what the correct syntax is here? Are we plumbing all of this through yet?

from toolkit.

codfish avatar codfish commented on July 17, 2024

@thboop awesome, thanks for the update!

from toolkit.

hamelsmu avatar hamelsmu commented on July 17, 2024

Just to give some more context, the step with id second step in the below yaml doesn't run even though it should, so I think there is a bug

on: push

jobs:
  test-outputs:
    name: Test Outputs Actions
    runs-on: ubuntu-latest
    steps:
 
    - id: first_step
      name: "This step will run no matter what."
      run: echo 'the first step'
      
    - name: Only run this step if another step succeeds
      id: second_step
      if: job.steps.first_step.status == success()
      run: echo "Hello"

Also, I don't think the status is made available either as job.steps.<id>.status consistently returns an empty/null value for me

from toolkit.

codfish avatar codfish commented on July 17, 2024

from toolkit.

codfish avatar codfish commented on July 17, 2024

@TingluoHuang @thboop @ericsciple wondering if you could answer a related question I have.

The only way I've found to properly set an environment variable (and an output var) is via @actions/core library. I cannot figure out how to set one outside of js and have it persist. For instance, appending export SOME_VAR=foo; to the runners' .bashrc doesn't work.

I see you're using commands, i.e. set-env here, but I'm not sure how that's working under the hood.

So is there a way to set and persist an env/output var from a host action or any other way without using the core package?

from toolkit.

codfish avatar codfish commented on July 17, 2024

@damccorm awesome, thank you!

@ericsciple

@codfish the pr is merged for the outputs issue. the fix will roll out with the next runner update.

To clarify, will this PR include the ability to reference steps context & outputs in the if property as well?

from toolkit.

dakale avatar dakale commented on July 17, 2024

@codfish That functionality is fixed in a separate PR, as mentioned above by Eric:

@codfish the pr is merged for the outputs issue. the fix will roll out with the next runner update. @TingluoHuang do you know when?

And should be released by end of week, maybe trickling into next week if there are issues duringthe release/rollout, per Ting:

later this week or really next week.

from toolkit.

thatbeardo avatar thatbeardo commented on July 17, 2024

I am trying to do something similar but instead of using constants 'Hamel' and 'Hussain' for var1 and var2, I want an expression to be evaluated. Concretely, the line looks as such -
echo "::set-env name=WEBSITE_BUCKET_ARN::$(terraform output website_bucket_arn)"

And when I echo the env variable in another step, I get "$WEBSITE_BUCKET_ARN" as a result. Any idea, leads or direction on how to store the result of an expression in an output/env variable. I have not been able to find anything related to this

When I try to access the environment variable WEBSITE_BUCKET, and just echo it in another step, it does not work!

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:

name: test

on: push

jobs:

  build:
    runs-on: ubuntu-latest
 
    steps:
    - name: Step 1
      id: step1
      run: echo "::set-output name=VAR1::Hamel"

    - name: Step 2
      id: step2
      run: echo "::set-env name=VAR2::Husain"

    - name: emit env
      run: |
       echo $VAR2
       echo $VAR1
        
      env:
        VAR1: ${{ steps.step1.outputs.VAR1 }}

    - name: this should not run
      run: echo "This should not run"
      if: steps.step1.outputs.VAR1 == 'Lucy'

This will give you the following output:

image

from toolkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.