GitHub Actions Day 12: Information about your Workflow

December 12, 2019

This is day 12 of my GitHub Actions Advent Calendar. If you want to see the whole list of tips as they're published, see the index.

Yesterday we saw that GitHub provides some information to GitHub Actions workflow runs -- namely, the GITHUB_TOKEN. But that's not all; what other information does GitHub Actions provide to you?

Actually, quite a lot.

GitHub Actions sets up a number of informational "contexts" that have data about your workflow runs. For example, the github context contains information like the name of the repository that your workflow is running in -- github.repository -- and the user that initiated the workflow run -- github.actor. You can reference these with the same double-curly-brace expansion syntax that we used for working with matrixes and secrets.

Use the Context

If you want to see all the information that GitHub Actions gives you in the contexts, you can actually use the handy toJson function to output the whole objects:

JSON data

If you do this, you'll notice that there's a lot of information in the GitHub context. In particular, the github.event object is itself a huge piece of json data. It contains - basically - the webhook payload that corresponds to the trigger.

That same event payload is saved to disk, at github.event_path. So you can get all that information in your workflow by examining that json blob. Fortunately, the very handy jq tool is installed on the runners. You can use it to take apart json data on the command-line.

For example, if I want to get the number of stars that my repository has, and the number of forks, I can use jq to unpack the json data that's saved at github.event_path.

Stars and Forks

GitHub Actions provides a lot of data about your repository, the action that triggered the run, and the environment -- all to enable you to create workflows to build your application, deploy it, or automate some task in your repository.