Configure Outputs in a Custom Github Action to Use Resulting Data in Other Actions

Colby Fayock
InstructorColby Fayock
Share this video with your friends

Social Share Links

Send Tweet
Published 4 years ago
Updated 3 years ago

In this lesson, we'll walk through configuring a custom Github Action to provide an output value when the action completes. We'll configure the output in our actions.yml and use the setOutput method from the Github Actions Toolkit core package that will allow us to log that value out in the following step.

Colby Fayock: [0:00] We're going to start off with a custom GitHub Action that logs a Futurama quote. In our code, we have an input set up where we can accept a character name. In the actual function, we make a request to the Futurama API and console.log it out.

[0:11] While we can see it's in our logs, maybe we want to use it in a downstream action. To do this, we can set up outputs with our action. This allows us to store the value so that we can access it in a later action.

[0:20] To do this, we want to first define our outputs in the action.yaml file. To do this, we write outputs, then the name which we'll use quote, and then a description, which we can say, "The resulting futurama quote."

[0:32] Now that is set that output value, we can use the same core toolkit as we did with the input. We can write core.setOutput, for the name we want to write quote, for the value let's add firstEntry. If we run this file using Node, we can see the debug log where it's getting set.

[0:48] Next, before we publish this, we want to make sure that we actually build this. Let's run yarn build.

[0:52] Then to test this, we can open up our test workflow, where we first want to set an id so that we can reference that output, where we can then run a script, where we can run an echo statement where we find the variable inside of the stack.

[1:03] This variable references the steps that we want to choose where here, we look for the id of Futurama which we'd set before, and then the outputs of that step which we set as quote.

[1:12] Once we push out those changes and the job completes, we'll be able to see our original output, as well as our test echo statement.

[1:18] In review, we wanted to configure some output data where we set up anew outputs of quote. Inside our code, we used the quotes where we setOutput of quote to the firstEntry.

[1:27] Now that we're setting that value, we're able to name our current step and then grab that value with an echo statement. Once the job finished building, we can see our original output and our new echo.

egghead
egghead
~ 36 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today