Skip to content

Latest commit

 

History

History
66 lines (47 loc) · 3.63 KB

05.4.3_entrypoint.md

File metadata and controls

66 lines (47 loc) · 3.63 KB

Entrypoint {docsify-ignore-all}

The final required piece of any actions metadata is the entrypoint which is defined by the runs keyword. The main purpose of the entrypoint is to define which application the actions code will be executed with as well as the path to the actions source code. Other parameters are available for use in the runs block of the action.yml metadata file. These parameters vary depending on the type of action you are writing.

JavaScript Actions

When writing custom JavaScript actions the runs keyword has three parameters available to it:

  • using: A required parameter defining the application to be used to execute the code.
  • main: A required parameter defining the file, including path, containing the code to be executed.
  • env: An optional parameter defining a key/value map of environment variables to be set inside the runners virtual environment.

action.yml

runs:
  using: "node12"
  main: "build/index.js"
  env:
    somevar: "some value"

Docker Container Actions

Docker container actions have a different set of parameter available to the runs keyword.

  • using: A required parameter that must be set to docker
  • image: A required parameter specifying the docker images to create a container from. This value can either be the base image name to an existing Docker container or a Dockerfile located in the repository.
  • env: An optional parameter defining a key/value map of environment variables to be set inside the container environment.
  • entrypoint: An optional parameter to override the Docker ENTRYPOINT specified in a Dockerfile. This value also sets a value if one was not already specified. Dockerfile support for GitHub Actions.
  • args: An Optional parameter defining an array of strings that define the inputs for a Docker container. Inputs can include hardcoded strings. GitHub passes the args to the container's ENTRYPOINT when the container starts up.

The args are used in place of the CMD instruction in a Dockerfile. If you use CMD in your Dockerfile, use the guidelines ordered by preference:

  1. Document required arguments in the action's README and omit them from the CMD instruction.
  2. Use defaults that allow using the action without specifying any args.
  3. If the action exposes a - -help flag, or something similar, use that to make your action self-documenting.
  4. If you need to pass environment variables into an action, make sure your action runs a command shell to perform variable substitution. For example, if your ENTRYPOINT attribute is set to "sh -c", args will be run in a command shell. Alternatively, if your Dockerfile uses an ENTRYPOINT to run the same command ("sh -c"), args will execute in a command shell.

action.yml

runs:
  using: 'docker'
  image: 'Dockerfile'
  args:
    - 'foo'
    - 'bar'

OR

runs:
  using: 'docker'
  image: 'docker://nginx:latest'
  args:
    - ${{inputs.some_defined_input}}

Along with the keywords we covered, you can also supply branding to any actions you create. Branding an action is outside of our scope for detailed coverage, if you wish to learn more visit the documentation on branding.

👈Continue to learn more about the runner environment!