Search code examples
githubgithub-actionscicd

Trying to refer a Reusbale Workflow from a Private repo


I am trying to find a workaround for using a Reusable workflow between two private repos: (It is not supported natively)

Context: I am trying to use a central repo (private) to contain all the Workflows and refer to that location from other repos (private).

Legend: Central Repo: Contains all the Reusable Workflows. (If we edit a file in here we should not have to edit each and every repo's workflow files) Calling Repo: A repo which runs Workflows, This repo will try to refer the workflows from the Central repo.

name: Calling Reusable Workflows

on: [ push ]

jobs:
  download-remote-repo:
    runs-on: ubuntu-latest
    steps:
    - name: Get private repo with action
      uses: actions/checkout@v2
      with:
        repository: kalanatd/central-repo
        ref: main
        token: ${{ secrets.PAT_TOKEN }}
    - name: List Files After remote Checkout
      run: |
        pwd
        ls -a                 // I can see the checked out remote repo files in here
        ls -al .github/workflows
        cat ./.github/workflows/workflow.yml             // Can read the file without any issue
    - name: Run a workflow file
      uses: ./.github/workflows/workflow.yml 

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

Note:

I learned that RWs can not be called under steps which means there is no way to download a RW from another place and use that workflow, right?


Solution

  • I am trying to find a workaround for using a Reusable workflow between two private repos: (It is not supported natively)

    Actually... it is, at least on GitHub (and later on a private GHE instance)

    GitHub Actions – Sharing actions and reusable workflows from private repositories is now GA (Dec. 2022)

    The actions and reusable workflows from private repositories can now be shared with other private repositories within the same organization, user account, or enterprise.

    See managing the repository settings and managing the enterprise repository settings to allow access to workflows in other repositories.

    We have also added the API support to configure Actions share policy.
    Refer to API support or API support for Enterprise for more details.

    Learn more about Sharing actions and workflows from your private repository, Sharing actions and workflows with your organization, and Sharing Actions and workflows with your enterprise.