Search code examples
cypressgithub-actionsprivate-repository

Trying to call a workflow in a private repo under same organization but getting error


We are trying to call a workflow from a private repo under our organization. Both repos are private repos under the same organization.

Organisation A --> private - repo-1 / .github\workflows\qatest.yml
Organisation A --> private - repo-2 / .github\workflows\test.yml 

But while running we are getting error like :

Error details:

 RequestError [HttpError]: Not Found
    at /home/runner/work/_actions/actions/github-script/v6/dist/index.js:6172:21
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  status: 404

repository 'https://github.com/somebookingtest/e2e-cypress/' not found

Could someone please advise on how to fix this issue here ?

Below is the action from //repo2/ test.yml

name: end to end testing
on:
  pull_request:
    types: [opened, synchronize, reopened]
jobs:
  first:
    name: end to end testing
    uses: somebookingtest/e2e-cypres/.github/workflows/maintest.yml@main-fixes
    permissions: read-all
    with:
      environment: qastaging
      tag: "@e2etests"
  second:
    runs-on: ubuntu-latest
    steps:
      - name: Trigger Workflow
        uses: actions/github-script@v6
        with:
          script: |
            github.rest.actions.createWorkflowDispatch({
              owner: 'booking',
              repo: 'e2e-cypres',
              workflow_id: 'maintest.yml',
              ref: 'main-fixes',
            }) 

Solution

  • You have to use PAT - Personal Access Token instead of the default one - the default one only allows reading the active repository.

    1. Create a personal access token
    2. Add it to your secrets
    3. add: github-token: ${{ secrets.MY_PAT }} to your second job as documented here
    name: end to end testing
    on:
      pull_request:
        types: [opened, synchronize, reopened]
    jobs:
      first:
        name: end to end testing
        uses: somebookingtest/e2e-cypres/.github/workflows/maintest.yml@main-fixes
        permissions: read-all
        with:
          environment: qastaging
          tag: "@e2etests"
      second:
        runs-on: ubuntu-latest
        steps:
          - name: Trigger Workflow
            uses: actions/github-script@v6
            with:
              github-token: ${{ secrets.MY_PAT }}
              script: |
                github.rest.actions.createWorkflowDispatch({
                  owner: 'booking',
                  repo: 'e2e-cypres',
                  workflow_id: 'maintest.yml',
                  ref: 'main-fixes',
                })