axel-op / dart-package-analyzer

GitHub Action that uses the Dart Package Analyzer to compute the Pub score of Dart/Flutter packages
MIT License
52 stars 9 forks source link

No report on pull requests from forks #2

Open axel-op opened 4 years ago

axel-op commented 4 years ago

Description

When the action is triggered by the pull_request event, if the pull request is from a different repository (a fork), the action fails with the error "Resource not accessible by integration".

EDIT: this behavior has changed. See the comment below.

Why is this happening

This action uses the GITHUB_TOKEN you provide to call the GitHub API and to post the result of its analysis. As explained here, here, or here, GitHub for now reduces the permissions of this token when the action is triggered by another repository. Therefore an error is thrown when this action tries to call the API in this situation.

Permissions for the GITHUB_TOKEN

Current workaround

A possible workaround is to edit your workflow to trigger this action only when pull requests come from the same repository. This can be done by adding an if-condition, as illustrated below:

name: Example workflow
on: [push, pull_request]

jobs:

  package-analysis:
    if: github.event_name != 'pull_request' || github.actor == '[username]' # Replace [username] by the username of your repo
    runs-on: ubuntu-latest
    steps:
      - ...

I will update this issue if there is new information on this.

axel-op commented 4 years ago

I edited the code so that this action won't fail anymore on this error. The report will now be skipped if it cannot be posted. This action will fail if a compilation error or a static error is detected by the analyzer. The outputs of this action will still be set.

vaind commented 3 years ago

The report will now be skipped if it cannot be posted.

Any chance the report could be printed directly to the standard ouptut in that case? Otherwise, if there's a failure later in the pipeline (e.g. our CI fails if the score decreases) we can't see what's wrong.

axel-op commented 3 years ago

Hello @vaind, you can still see the original raw JSON report in the logs, along with the values of the outputs. Is this what you want?

image image

vaind commented 3 years ago

Totally missed that, all good then

GroovinChip commented 3 years ago

For cases like this, is there any way the raw json from the job logs can be captured and turned into a report or downloadable job artifact? Having to hunt through the logs to see the analysis in these cases is a bit tedious.

axel-op commented 3 years ago

For cases like this, is there any way the raw json from the job logs can be captured and turned into a report or downloadable job artifact? Having to hunt through the logs to see the analysis in these cases is a bit tedious.

Hi @GroovinChip, could you please create a separate issue for this ? :)

GroovinChip commented 3 years ago

For cases like this, is there any way the raw json from the job logs can be captured and turned into a report or downloadable job artifact? Having to hunt through the logs to see the analysis in these cases is a bit tedious.

Hi @GroovinChip, could you please create a separate issue for this ? :)

Done