Skip to content

Unable to upload test execution results for a PR from a forked repo: Upload failed: {"message":"Token required because branch is protected"} #104

@kkovaletp

Description

@kkovaletp

I run this action in a public repo and in PRs from forked repos. The main repo's GitHub secrets are not accessible from PRs, created from forked repos, as this is the default GitHub security setting and we don't want to change it.
Here is the action definition in the workflow:

  • API job:
    - name: Upload test execution results
      uses: codecov/test-results-action@v1
      if: ${{ steps.test.conclusion == 'success' || steps.test.conclusion == 'failure' }}
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        flags: api-${{ matrix.database }}
        files: ./api/test-api-coverage-report.xml
  • UI job:
    - name: Upload test execution results
      uses: codecov/test-results-action@v1
      if: ${{ steps.test.conclusion == 'success' || steps.test.conclusion == 'failure' }}
      with:
        token: ${{ secrets.CODECOV_TOKEN }}
        flags: ui
        directory: ./ui

When it is run from the master or any other branch of the main repo, upload is done successfully. However, once it is run for a PR from a forked repo, the upload fails with the error: Upload failed: {"message":"Token required because branch is protected"}.
It is expected that the token value is empty, as it is stored in the secret and not accessible from such PRs. But the PR's ref is not a protected branch, so the token should not be required. Also, the codecov/codecov-action@v5, defined right before this one in the workflow, runs fine for the same PRs and uploads results successfully in the tokenless mode.

Examples of the runs:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions