noonenine
noonenine

Reputation: 99

How to access files of GitHub Action repo when using that action in another repo?

I have created a JavaScript automation and in that script I have created couple of YML files and I'm importing them using fs and js-yaml libraries. I have hosted this code in repo A.

I want to convert my repo A into a GitHub action. I have followed the documentation from GitHub to create JavaScript action. I have used the vercel/ncc to create one file with all my libraries as suggested by GitHub.

But when I use this action in repo B, I get an error saying the yml files are not available at the mentioned path.

Does GitHub workflow download the action's repo during execution? if yes, how can I pass these yml files into the script?

If not, what are the options to pass these files into script?

Upvotes: 4

Views: 5669

Answers (1)

GuiFalourd
GuiFalourd

Reputation: 22900

You can access an action repository files in a composite action from the action.yml file by using the ${{ github.action_path }} context variable.

The path where an action is located. This property is only supported in composite actions. You can use this path to access files located in the same repository as the action. Blockquote

Source: Github Documentation about Context

For example, if you need to execute a python script script.py located in the action repository from a run step in a composite action, you would have to use something like this:

run: python "${{ github.action_path }}/script.py"
shell: bash

Note: I suggest to inform the shell to avoid problem as composite actions can be used on any OS runner.

I've created a small action as reference which uses this concept if you want to have a look.

Upvotes: 9

Related Questions