lfarci / github-actions

Preparation resources for the GitHub Actions certification
0 stars 0 forks source link

Implement workflow commands within an action to communicate with the runner (Note: this includes exit codes) #53

Closed lfarci closed 3 months ago

lfarci commented 3 months ago

GitHub Actions can communicate with the runner machine using workflow commands. These commands allow you to set environment variables, output values, create debug messages, among other things. They are invoked by writing to stdout in a specific format.

Here's an example of a JavaScript action that uses workflow commands:

const core = require('@actions/core');

try {
  // Set an output
  core.setOutput('output1', 'some value');

  // Set an environment variable
  core.exportVariable('ENV_VAR', 'some value');

  // Write a debug message
  core.debug('This is a debug message');

  // Write an error message
  core.error('This is an error message');

  // Fail the action
  core.setFailed('This is a failure message');
} catch (error) {
  core.setFailed(error.message);
}

In this script:

Remember to replace 'output1', 'some value', 'ENV_VAR', 'This is a debug message', 'This is an error message', and 'This is a failure message' with the output name, output value, environment variable name, environment variable value, debug message, error message, and failure message that are appropriate for your action.

lfarci commented 3 months ago

Using workflow commands to access toolkit functions

lfarci commented 3 months ago

Setting exit codes for actions