Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 9

Path to action in the same repository as workflow

Solved! Go to Solution.

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:Selection_306.png

So, in the workflow's main.yml I set:

 

uses: ./.github/actions/automatic-tests@master

 

However, when the action was triggered, I got the following error:

 

Can't find 'action.yml' or 'Dockerfile' under 
'/home/runner/work/hello_world_github_actions/hello_world_github_actions/.github/actions/automatic-tests@master'. 
Did you forget to run actions/checkout before running your local action?

 

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):

uses: raquelhortab/hello_world_github_actions/.github/actions/automatic-tests@master

 

However, I'd like to know if this is the expected behaviour or whether I did something wrong.

8 Replies
Highlighted
Solution
GitHub Partner
Message 2 of 9

Re: Path to action in the same repository as workflow

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:

name: use my action
on: push

jobs:
  my_first_job:
     runs-on: ubuntu-latest
     steps: 
     - uses: actions/checkout@v1
     - name: My first step
       uses: ./.github/actions/my-action

>> 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 .

workspace.png

Please refer to this document: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/using-environment-va...

Highlighted
Copilot Lvl 3
Message 3 of 9

Re: Path to action in the same repository as workflow

This [issue](https://github.community/t5/GitHub-Actions/Local-Action-not-found-in-workflow/m-p/43576#M5434) seems to be related and was something I ran into. Is there any chance get the a real feature? 

Highlighted
Copilot Lvl 3
Message 4 of 9

Re: Path to action in the same repository as workflow

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):

 

 

name: CI

on:
  push:
    branches:
      - master

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@master
      name: Checkout
    - uses: ./.github/actions/automatic-tests@master
      name: Test

 

 

Meanwhile, this is working perfectly:

 

name: CI

on:
  push:
    branches:
      - master

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@master
      name: Checkout
    - uses: raquelhortab/hello_world_github_actions/.github/actions/automatic-tests@master
      name: Test

 

Highlighted
GitHub Partner
Message 5 of 9

Re: Path to action in the same repository as workflow

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: 

- uses: ./.github/actions/automatic-tests

When adding @master , it will look for a folder named automatic-tests@master.

 

Highlighted
Copilot Lvl 3
Message 6 of 9

Re: Path to action in the same repository as workflow

Thanks for replying, but what should I use instead of @master? If I don't add any tag it complains.

 

With the following code:

 

name: CI

on:
  push:
    branches:
      - master

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout
      name: Checkout
    - uses: ./.github/actions/automatic-tests@master
      name: Test

 

 

I get:

 

Your workflow file was invalid: The pipeline is not valid. .github/workflows/main.yml (Line: 14, Col: 13): Expected format {org}/{repo}[/path]@ref. Actual 'actions/checkout',Input string was not in a correct format.

 

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. 

 

Failed to download action 'https://api.github.com/repos/actions/checkout/tarball/v3'

 

 

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:

name: CI

on:
  push:
    branches:
      - master

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
      name: Checkout
    - uses: ./.github/actions/automatic-tests@master
      name: Test

 

The errror:

##[error]Can't find 'action.yml' or 'Dockerfile' under '/home/runner/work/hello_world_github_actions/hello_world_github_actions/.github/actions/automatic-tests@master'. Did you forget to run actions/checkout before running your local action?

Using your @v1 option but with the full path it works again.

 

 

Highlighted
Pilot Lvl 1
Message 7 of 9

Re: Path to action in the same repository as workflow

I think what @Yanjingzhu meant was not to use a tag in your action path, like so:

    steps:
    - uses: actions/checkout@v1
      name: Checkout
    - uses: ./.github/actions/automatic-tests
      name: Test
Highlighted
Copilot Lvl 3
Message 8 of 9

Re: Path to action in the same repository as workflow

**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 ?

Highlighted
GitHub Partner
Message 9 of 9

Re: Path to action in the same repository as workflow

If you want to checkout other branches, you could specify ref of checkout action:

- uses: actions/checkout@v1
  with:
    ref: my-branch

For more checkout scenarios , please refer to https://github.com/actions/checkout#scenarios