Debugging Actions

Hi there,

I’m working on my first GitHub Action but I’m having a hard time making it work. Is there a way to debug it?

When I run it the error I get is the following

### STARTED test 08:43:16Z

Pulling image: gcr.io/github-actions-images/action-runner:latest
latest: Pulling from github-actions-images/action-runner
169185f82c45: Pulling fs layer
0ccde4b6b241: Pulling fs layer
d0372f57daa2: Pulling fs layer
165911d108d6: Pulling fs layer
54996bce1de5: Pulling fs layer
165911d108d6: Waiting
54996bce1de5: Waiting
d0372f57daa2: Verifying Checksum
d0372f57daa2: Download complete
0ccde4b6b241: Verifying Checksum
0ccde4b6b241: Download complete
169185f82c45: Verifying Checksum
169185f82c45: Download complete
165911d108d6: Verifying Checksum
165911d108d6: Download complete
54996bce1de5: Verifying Checksum
54996bce1de5: Download complete
169185f82c45: Pull complete
0ccde4b6b241: Pull complete
d0372f57daa2: Pull complete
165911d108d6: Pull complete
54996bce1de5: Pull complete
Digest: sha256:c9bb432ec5ec08ee08b040a9fccacebbbf8a91444dac4721600cf5dca9dae57e
Status: Downloaded newer image for gcr.io/github-actions-images/action-runner:latest

### FAILED test 08:43:27Z (10.526s)

The action is hosted in a public repo.
The workflow looks like

workflow "My workflow" {
  on = "release"
  resolves = ["test"]
}

action "test" {
  uses = "infrolife/test.action@master"
  secrets = ["GITHUB_TOKEN"]
}

Thank you.

2 Likes

Hi @sigfrid! Welcome to the world of GitHub Actions!

I’ll point you to an Action I made call smee-action - it will post the event details to a smee.io channel:

action "smee" {
  uses = "JasonEtco/smee-action@master"
  args = "--channel sigfrid"
}

Make sure you’ve opened https://smee.io/sigfrid in your browser before running your workflow - it’ll only show payloads that have been received while the tab is open (doesn’t have to be active, just open).

This should help you debug your payload, but you may still not be seeing any logs in your Action. I’d recommend adding a bunch of logs using echo, or whatever the standard logging utility is in the language you’re working with. If nothing is still showing up, it’s likely that the binary is failing to run - so far example, if I try to use a variable in Node.js that I haven’t defined, the node process will fail silently.

Hope that helps!

1 Like

Also, I’d like to point to actions/bin/debug@master which is made for a similar purpose but I have to double warn you about using it in actions with secrets exposed as the output is publically logged.

Thanks for the reply. I will give it a try.

As for your log, it seems that your docker container’s entrypoint/cmd just doesn’t print out anything and exits with an error return code (not 0 or 78).

Assuming you’re using a bash script, I highly recommend you putting the following at the beginning of your script for safety and predictability:

set -exuo pipefail

-x flag is optional, it enables tracing and actually outputs what’s going on in the script. I usually apply it separately with if-debug check (like checking for debug var to be present or so).

-e makes the script exit with an error if any of the command invocations inside returns error.

-u makes bash error out on access to uninitialized (unexisting) variables.

-o pipefail fails the script on any broken pipes

By default, bash would ignore those things.

Other than this, just check return codes of your commands and print out useful messages accordingly. Oh, and if you want to bypass execution to another process, use exec so that it will receive signals, otherwise you’d have to process them with traps in your script.

Yet, if you are using another interpreter (JS/Python), make sure to do appropriate logging, error processing, and return codes as per docs.

And the last thing to mention is this list of references:

‒ https://github.com/nektos/act — I haven’t tried it yet but they seem to enable you testing Actions locally

‒ https://github.com/sdras/awesome-actions — yet another awesome collection of Action-related stuff

3 Likes