gitgithubgithub-actionsworkspacegit-checkout

How to get checked out remote repository directory in github actions


I have github actions in repo knowyrtech/repo1 where I check-out knowyrtech/repo2 like below:

- name: Checkout code from a specific repository and branch
  uses: actions/checkout@v3
  with:
    repository: knowyrtech/repo2 # Replace with the repository you want to checkout
    ref: release/valtech

I wish to get to the directory on the windows github runner where repo2 was checked out.

I used ${{ github.workspace }} but it takes me to the <runner work directory>/repo1/repo1 whereas I see that repo2's checkout folder may be here <runner work directory>/repo1/repo2.

Can you please suggest how can I get inside the folder where remote repo2 was checked out?


Solution

  • Since you are using multiple repositories within your runner (repo1/repo1 and repo1/repo2), you can use the path option from actions/checkout.

    path

    Relative path under $GITHUB_WORKSPACE to place the repository

    https://github.com/actions/checkout#usage

    - name: Checkout
      uses: actions/checkout@v4
      with:
        path: repo1
    
    - name: Checkout knowyrtech/repo2 repo
      uses: actions/checkout@v4
      with:
        repository: knowyrtech/repo2
        ref: release/valtech
        path: repo2
    

    This way you shall have the main repo under repo1 and second repo under repo2.