6

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?

jactor-rises
  • 2,395
  • 2
  • 22
  • 44

2 Answers2

4

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 }}
jactor-rises
  • 2,395
  • 2
  • 22
  • 44
  • 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 – Dan Forever Sep 09 '22 at 22:58
  • 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.. – jactor-rises Oct 12 '22 at 10:58
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

jjmerelo
  • 22,578
  • 8
  • 40
  • 86