Path to action in the same repository as workflow #26245
-
I’d like to explain something I went through as I think the documentation could maybe specify this case a bit more or it could even be a bug (not sure though). I have a repository with a rails app. The repository has its own action to run tests in a docker container. The workflow’s path would be /.github/workflows/main.yml while the action’s path would be /.github/actions/automatic-tests/action.yml. The thing is, I tried following the documentation, where it says: So, in the workflow’s main.yml I set:
However, when the action was triggered, I got the following error:
I fond it weird that the repository name got duplicated in the path (…/hello_world_github_actions/hello_world_github_actions/…). I also tried setting it to ./…/.github to workaround this second hello_world_github_actions directory but it still failed, I believe it was because there is no reference to raquelhortab, which is my github account name. I got it to work by setting the whole repository reference, as I would do if I wanted to use an action in another repository (with a previous checkout as well):
However, I’d like to know if this is the expected behaviour or whether I did something wrong. |
Beta Was this translation helpful? Give feedback.
Replies: 20 comments 6 replies
-
Hi raquelhortab, When use action in the same repository as workflow, we need to add actions/checkout before running your local action. And you don’t need to add @master behind your action path. Please see my example:
>> I fond it weird that the repository name got duplicated in the path (…/hello_world_github_actions/hello_world_github_actions/…). For this question, the path is as expected. It is the default directory path . Please refer to this document: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-variables |
Beta Was this translation helpful? Give feedback.
-
This issue seems to be related and was something I ran into. Is there any chance get the a real feature? |
Beta Was this translation helpful? Give feedback.
-
The thing is I did add actions/checkout, and it didn’t work. I tried it again today and it doesn’t work if I use a relative path (./.github/…), only when using the whole path (raquelhortab/hello_world_github_actions/.github/…). Here’s the code for .github/workflows/main.yml that I can’t get to work with your solution (I know that adding @master it’s not necessary but this is not the problem):
Meanwhile, this is working perfectly:
|
Beta Was this translation helpful? Give feedback.
-
When you use relative path, there is no need to specific branch. It will find the path in the Github workspace. Just use next code snippet:
When adding @master , it will look for a folder named automatic-tests@master. |
Beta Was this translation helpful? Give feedback.
-
Thanks for replying, but what should I use instead of @master? If I don’t add any tag it complains. With the following code:
I get:
In your first answer you used @v1. I created a release named v3 and used its tag (actions/checkout@v3) and it doesn’t work either.
It seemed like the tag was referent to the actions repo not to my repo so I tried your exact example (actions/checkout@v1) and got the original error as well… The code:
The errror:
Using your @v1 option but with the full path it works again. |
Beta Was this translation helpful? Give feedback.
-
I think what @yanjingzhu meant was not to use a tag in your action path, like so:
|
Beta Was this translation helpful? Give feedback.
-
**bleep**, you meant the tag in the tests step… I had really not seen it, thought you were talking about the one in actions/checkout@v1. It works now, thanks! However, what about if I wanted to use another branch different from master? where would I specify it? is that the “@v1” in actions/checkout@v1 ? |
Beta Was this translation helpful? Give feedback.
-
If you want to checkout other branches, you could specify ref of checkout action:
For more checkout scenarios , please refer to https://github.com/actions/checkout#scenarios |
Beta Was this translation helpful? Give feedback.
-
For everybody facing this issue, as the official documentation says here https:// docs . github . com/en/actions/using-workflows/reusing-workflows#calling-a-reusable-workflow:
This means that using the form ./.github/workflows/my-workflow.yml will not work if you use it with the structure:
You should use instead:
I know, this makes no sense, anyways… |
Beta Was this translation helpful? Give feedback.
-
The docs for this are utterly useless. |
Beta Was this translation helpful? Give feedback.
-
Unrecognized named-value: ‘github’. Located at position 1 within expression: github.event.inputs.stage .github/workflows/azure-build.yml (Line: 55, Col: 15): Unrecognized named-value: ‘github’. Located at position 1 within expression: github.event.inputs.stage how to give the dynamic path to the the uses attribute ? Any idea ? |
Beta Was this translation helpful? Give feedback.
-
Solution for me was to use a trailing slash:
instead of
Also if you aren't committing your build output directory, make sure you are building (tsc) your action in the workflow before you reference it if it's in typescript and you aren't using |
Beta Was this translation helpful? Give feedback.
-
Preview:-. Your actions yml is in here Key point:
Solution, I'm doing it in my local and tested it.
name: use my action
on: push
jobs:
my_first_job:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
ref: 'master'
- name: My first step
- uses: ./.github/actions/automatic-tests
name: "Hello My Actions"
description: "Greet someone"
author: "xxxxx@github.com"
runs:
using: "docker"
image: "Dockerfile"
branding:
icon: "mic"
color: "purple"
FROM debian:9.5-slim
RUN echo 'hello' |
Beta Was this translation helpful? Give feedback.
-
@ZhaoKunLong @josegpulido @Yanjingzhu Tagging you since all of you have given detailed answers which resembles closely with my issue. I am facing the same issue when trying to find a workaround for using a Reusable workflow between two private repos: Context: I am trying to use a central repo for all the Workflows and refer to that location from other repos. Legend: I executed a 'cat' command of the workflow and I can see that the workflow file exists and it is readable. But the 'uses' command does not identify the file. Caller Workflow from Calling repo: [There are some comments I added]
Note: In aboe scenario ./.github/workflows/workflow.yml is dynamically checked out to the Runner's workspace. Even though 'run' commands can see that file 'uses' command does not use it. [1] Error: Can't find 'action.yml', 'action.yaml' or 'Dockerfile' under '/home/runner/work/caller-repo/caller-repo/workflow.yml'. Did you forget to run actions/checkout before running your local action? [2] https://github.github.io/actions-cheat-sheet/actions-cheat-sheet.pdf |
Beta Was this translation helpful? Give feedback.
-
If you like me can't read long posts about For composite actions (not workflows):Checkout is mandatory. Only on step level. This works:
This doesn't work:
PS: Github actions documentation sucks! I wish in the era of AI layoffs those devs who designed github actions won't lose their jobs. Especially those who designed sharing across |
Beta Was this translation helpful? Give feedback.
-
Hi, Am facing same issue here, and opened an issue here https://github.com/orgs/community/discussions/59942. The issue was not there, until i have added the notification script to run and it gives me the issue even on the checkout? any ideas? |
Beta Was this translation helpful? Give feedback.
-
In case some does the same mistake getting the described error message but above answers do not help: My error was that my action was at |
Beta Was this translation helpful? Give feedback.
-
For anyone wanting to know how to run the action in the root (main repo is the action), use this:
|
Beta Was this translation helpful? Give feedback.
-
I got
and assumed that the path was wrong. However, there has been an issue inside the file. |
Beta Was this translation helpful? Give feedback.
-
in my case, i simply put the name the file as action.yml and put it in .github/actions/aws-credentials dir, then the error is gone. |
Beta Was this translation helpful? Give feedback.
Hi raquelhortab,
When use action in the same repository as workflow, we need to add actions/checkout before running your local action. And you don’t need to add @master behind your action path.
Please see my example:
>> I fond it weird that the repository name got duplicated in the path (…/hello_world_github_actions/hello_world_github_actions/…).
For this question, the path is as expected. It is the default directory path .
Please refer to this document: https://help.github.com/en/actions/automati…