Dump Context Action

21 May 2021 in Tech

This week's Action Spotlight introduces a new kind of action. It's the first time we're featuring a composite action, which allows you to include multiple workflow steps as a single uses statement.

Fact Sheet
Authorcrazy-max
Contributors1
Stars9
Repohttps://github.com/crazy-max/ghaction-dump-context
Marketplacehttps://github.com/marketplace/actions/dump-context

What does it do?

This action outputs the following items from the runner environment:

  • env
  • runner
  • github
  • job
  • steps
  • strategy
  • matrix

This allows you to see things like github.event in the output to debug the data available to your actions.

How does it work?

This is a composite action, which means that the whole thing is in a single action.yml file. It contains the fields that we'd expect to see, such as name, author and branding. However, it also has a value that we've not seen before; runs.using: composite.

This tells Actions that the action provides steps that should be run as though they were provided in the workflow itself.

There are seven steps, each dumping a different aspect of the environment. Each step uses the toJson function to convert the input to a string that can be rendered in the output and stores that in the environment. Storing it in the environment prevents quoting issues when echoing out the value later.

The characters before each heading (e.g. \033[31;1;4m) are ANSI escape codes, which tells the output to make that text red, bold and underlined.

Finally, each step has the shell set to bash. This makes the action usable on all operating systems. Without this, the action would default to Powershell on Windows and fail.

That's all there is to it - seven steps, all following the same pattern to output useful data in the logs.

Common use cases

There's only one use case - dump the current context to for debugging purposes:

yaml
name: Dump Context
on: [push, pull_request]
jobs:
dump:
runs-on: ubuntu-latest
steps:
- name: Dump context
uses: crazy-max/ghaction-dump-context@v1