How do you use another action from a custom GitHub node action?

722 Views Asked by At

I'm writing a JavaScript-based GitHub action (using https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action) and now I want to checkout a repository using, for example, actions/checkout@v3. I already know how to do this in a YAML workflow (and I don't want to do it this way). How do I call it from the JavaScript?

2

There are 2 best solutions below

0
CortexCompiler On

The way I achieved this was by creating a composite Action and then calling the node action located in the same repo. The code would look something like this:

name: 'Composite action with embedded node action'
description: 'Approach to using other actions with a node action'
author: 'cortexcompiler'
inputs:
  input1:
    required: false
    description: 'Example of passing through an input'
runs:
  using: "composite"
  steps:
    - name: Check out Git repository
      uses: actions/checkout@v3

    - name: Now Calling the Node action in directory ./actions/node-action
      uses: ./actions/node-action
      with:
        input1: ${{ inputs.input1 }}

Directory structure:

├── action.yaml
├── actions
│   └── node-action
│       └── action.yaml
0
sffortytwo On

Well, ChatGPT to the rescue. It seems there's no way to directly call an action from the code of another action (e.g. in the JavaScript). But what you could do is create a repository_dispatch action that calls the action you want and then to use an HTTP POST in your code to call your repository_dispatch action. It's a messy workaround, but it seems to be the only way for now.