I am trying to store the scripts of my composite github actions in the directory of action. let me explain by an example
- Suppose I am in the myorg organization
- I create a repository named actions
- I create a directory named
mydemo
- I create a file
mydemo/action.yaml
- I create another file
mydemo/echo.sh
In mydemo/action.yaml
I have:
name: "mydemo"
description: ""
runs:
using: "composite"
steps:
- name: echo hello world
run: |
source ${{ github.action_path }}/echo.sh
shell: bash
and in mydemo/echo.sh
I have:
echo "Hello World"
Then I create a tag named v1
I also provide access in settings so that it can be used as a composite action
However I have an error
It tries to run source /apps/ghe-actions/_work/_actions/myorg/mydemo/v1/mydemo/echo.sh
And I see this error
/apps/ghe-actions/_work/_actions/myorg/mydemo/v1/mydemo/echo.sh: No such file or directory
How can I run the echo.sh in this example?
Use the
${{ github.action_path }}
magic variable:See: https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
This should work under "normal circumstances" - when not running in a container, but on a real machine or VM - but there are a number of situations where the runner assigns the wrong value. In that case, rely on the
GITHUB_ACTION_PATH
environment variable.