8

I have a GitHub action that essentially is a bash script. The javascript portion of my action executes a bash script:

const core = require("@actions/core");
const exec = require("@actions/exec");

async function run() {
  try {
    // Execute bash script
    await exec.exec(`${__dirname}/my-action-script.sh`);
  } catch (error) {
    core.setFailed(error.message);
  }
}

run();

For now, this action will communicate with other actions by leaving files on the file system. This is an "invisible" way of communication and I would like to fill my action.yml with outputs. How can I enable my-action-script.sh to return me outputs defined in my action.yml?

1

2 Answers 2

5

the output must first be added to the action.yml, ex:

name: some GitHub workflow yaml file
description: some workflow description
runs:
  using: node12
  main: dist/index.js
inputs:
  some_input:
    description: some input
    required: false
outputs:
  some_output:
    description: some output

and create the output from the bash script, ex:

echo ::set-output name=some_output::"$SOME_OUTPUT"

then you can use it in your workflow yaml, ex:

${{ steps.<step id>.outputs.some_output }}
Sign up to request clarification or add additional context in comments.

2 Comments

This answer doesn't make sense as you give an example of an action.yml using javascript, but then go on to talk about output from a bash script
I think the answer makes perfect sense... the action is using javascript and the sole purpose of the javascript is to execute a bash script..
0

Not totally clear if this is an action in a repo, or something you want to publish to the marketplace. At any rate, creating the output is done in the same way as indicated by the other answer, although you can run directly the shell if you use:

name: some GitHub workflow yaml file
description: some workflow description
runs:
  using: composite
  main: my-action-script.sh
inputs:
  some_input:
    description: some input
    required: false
outputs:
  some_output:
    description: some output

See this article on creating this kind of actions

2 Comments

This doesn't make sense as there's no "runs.main" for composite actions
@DanForever I bet this is conflating various pipeline tools and their directives. Possibly Azure?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.