2

I'm trying to write a file in my GitHub repo with GitHub Actions. When reading the docs, I stumbled across this:

Actions can communicate with the runner machine to set environment variables, output values used by other actions, add debug messages to the output logs, and other tasks.

Most workflow commands use the echo command in a specific format, while others are invoked by writing to a file. For more information, see "Environment files".

echo "::workflow-command parameter1={data},parameter2={data}::{command value}"

I don't know Ansible so I don't understand if this is YAML syntax or Ansible syntax.

I've tried to search Google and Stack Overflow but no results for double colon or ::

Can someone give me the link to the appropriate doc for :: or explain what this command does?

in other words, what does the example in my post throws in the shell? where are data and parameter1 and parameter2 defined if they are (in the yml, in the shell/env)? is command value a value i can reuse in the yml or in the shell?

  • It's the syntax _for workflow commands_. That _is_ the appropriate doc. – jonrsharpe Mar 18 '22 at 10:18
  • ok well i dont understand it, can someone explain me what it does? –  Mar 18 '22 at 10:40
  • I don't know what else to say - it lets you invoke workflow commands and pass parameters to them, exactly as the example in your quote shows. – jonrsharpe Mar 18 '22 at 10:41
  • What is the reason you are asking this question? Are you trying to accomplish something else than your question first states? The double colon is just a syntax of the output of commands. EG if you are running `debug: msg="foobar"` then the syntax output of that command would be something like `:: debug msg="foobar"::foobar` – Leroy Mar 18 '22 at 15:33
  • in other words, what does the example in my post throws in the shell? where are data and parameter1 and parameter2 defined if they are (in the yml, in the shell/env)? is command value a value i can reuse in the yml or in the shell? –  Mar 19 '22 at 09:19

1 Answers1

1

The ::command can be logged to the console by any script or executable. They are special strings the GitHub runner will detect, interpret and then take the appropriate action on.

They are essentially the communication mechanism between the runner and the thing it's currently running. Anything that can write to the console can issue these strings.

It's totally up to you to build these stings, to inject any parameters these 'magic strings' require to function.

The docs you've found are the right docs on these to understand how to log there strings and what commands there are available to you.

If you're building a GitHub action using the JavaScript/Typescript toolkit, then it provides nice wrapper functions for these commands. The JavaScript SDK also gives you a sneak peak into how to composekthese strings.

If you're building a composite action, container task or are directly issueing commands from a script block in the workflow, then it's up to you to build the correct strings and log these to the console.

More details:

Communicating through the console is the lowest common denominator between any tools running on just about any platform and requires no interprocess communication if any kind. It's the simplest way to communicate from a child process to it's parent.

You'd use the command to set an output variable.

echo "::set-output name=name::value"

To be able to reference the value cross at you'd reference any output variable from any action.

Or set an environment variable which will be set for the next job: echo "action_state=yellow" >> $GITHUB_ENV

See: https://stackoverflow.com/a/57989070/736079

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • thank you for this explanation. could you provide an example and what it does? –  Mar 27 '22 at 10:18
  • Not sure what more to add... Your custom action or script can log these magic strings to the console to do a number of things, all explained in the docs you already referenced. They can signal the runner to set a variable for which will be made available to other steps in the same job. It can signal the runner to group log messages together. It can signal the runner that certain values must be treated as secrets and never be logged to the console. – jessehouwing Mar 27 '22 at 17:41
  • for example ::debug msg="foobar"::cmdresult launches the command debug msg="foobar" in the console or debug "foobar" in the console? cmdresult is the result of the command right? where the cmdresult variable is assigned? in the github runner where i can reuse it later or in the console? –  Mar 27 '22 at 20:39
  • `::debug msg=abc` will log the message `abc` to the logs of the job if the job is running in dubug mode.. there is no cmdresult for debug messages. – jessehouwing Mar 28 '22 at 11:18
  • ok that was a bad example, but if it was ::echo "test"::cmdresult , where and how can i reuse cmdresult which has a value of test i guess? –  Mar 28 '22 at 14:03
  • See: https://stackoverflow.com/a/57989070/736079 – jessehouwing Mar 28 '22 at 15:52
  • ok thanks, i get it now –  Mar 28 '22 at 16:30