GitHub Actions allows you to create reusable actions. One of the easiest ways to do this is to use Composite Actions, which let you combine multiple steps into a single action. This reduces code duplication across your workflows.
When creating a composite action, you may need to reference files stored in the action repository, such as a PowerShell or Bash script.
By default, when an action runs, the working directory is the root of the repository that uses the action. This means relative paths resolve to the caller's repository, not the action repository.
To access files from the action repository, use the github.action_path context variable, which contains the path to the directory where your action is located.
Here's an example of how to use it in your action.yml file:
YAML
name: 'My Composite Action'
description: 'An example'
runs:
using: "composite"
steps:
- name: Run script
run: ${{ github.action_path }}/script.sh
shell: bash
In this example, script.sh is located at the root of the action repository. Using ${{ github.action_path }}/script.sh ensures the runner executes the script from the correct location.
#Additional resources
Do you have a question or a suggestion about this post? Contact me!