Search code examples
githubyamlgithub-actionsbuilding-github-actions

How can I set command line arugment in github action?


My aim is to create github workflow for publishing the plugin. Here I have to enter some command line arguments after executing some command. Can someone please tell me, whether there is a way to set the command line arguments in github action ?


Solution

  • If I understand you correctly - you're trying to build your GitHub Action and don't know how to pass arguments to it, correct? If so, you can use inputs mechanism to pass arguments to your action. For example:

    JavaScript Action

    action.yml
    ...
    inputs:
      version:
        description: Plugin version
        required: true
    runs:
      using: 'node12'
      main: index.js
    ...
    
    index.js
    const core = require('@actions/core');
    const version = core.getInput('version');
    

    Docker Action

    action.yml
    ...
    inputs:
      version:
        description: Plugin version
        required: true
    runs:
      using: 'docker'
      args:
        - ${{ inputs.version }}
    ...
    
    docker-entrypoint.sh
    #!/bin/sh -l
    echo $1 # your version
    

    Usage:

    workflow.yml
    ...
    steps:
      name: Your action usage
      uses: mysuperaction@master
      with:
        version: 1
    ...