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.