Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource not accessible by integration #76

Closed
staabm opened this issue Mar 15, 2021 · 7 comments · Fixed by #80
Closed

Resource not accessible by integration #76

staabm opened this issue Mar 15, 2021 · 7 comments · Fixed by #80
Labels
enhancement New feature or request

Comments

@staabm
Copy link

staabm commented Mar 15, 2021

I try to post a string to create a comment, but getting a Resource not accessible by integration error

see action logs https://github.com/parsica-php/parsica/pull/37/checks?check_run_id=2113059121

grafik

maybe one of the ansi special chars is a problem?

@staabm
Copy link
Author

staabm commented Mar 15, 2021

the workflow in question is pretty simple / the comment part was more or less copied from the actions readme:

name: Benchmark

on: [push, pull_request]

jobs:
  build:

    runs-on: ubuntu-20.04

    steps:
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
          php-version: '7.4'

    - uses: actions/checkout@v2
      with:
        fetch-depth: 0
        
    - name: create perf comparison
      id: perf-compare
      run: |
        # create baseline
        git checkout cc0808fd2ecd30a563bbe20e5d4e989d7071aa03
        composer install --prefer-dist --no-progress --no-suggest
        composer benchmark-baseline
        
        # cleanup
        rm composer.lock
        
        # compare against current commit
        git checkout ${{ github.event.pull_request.head.sha }}
        composer install --prefer-dist --no-progress --no-suggest
        comparison=$(composer benchmark-compare-baseline)

        # prepare multi line message
        comparison="${comparison//'%'/'%25'}"
        comparison="${comparison//$'\n'/'%0A'}"
        comparison="${comparison//$'\r'/'%0D'}"
        
        echo "::set-output name=comparison::$comparison"

    - name: Find Comment
      uses: peter-evans/find-comment@v1
      id: fc
      with:
        issue-number: ${{ github.event.pull_request.number }}
        comment-author: 'github-actions[bot]'
        body-includes: running benchmarks...

    - name: Create comment
      if: steps.fc.outputs.comment-id == ''
      uses: peter-evans/create-or-update-comment@v1
      with:
        issue-number: ${{ github.event.pull_request.number }}
        body: |
            ```
            ${{ steps.perf-compare.outputs.comparison }}
            ```

    - name: Update comment
      if: steps.fc.outputs.comment-id != ''
      uses: peter-evans/create-or-update-comment@v1
      with:
        comment-id: ${{ steps.fc.outputs.comment-id }}
        body: |
            ```
            ${{ steps.perf-compare.outputs.comparison }}
            ```

https://github.com/staabm/parsica/blob/c1ed7e515430bdb028eb4eeffafce2c731ac52ca/.github/workflows/benchmark.yml

@peter-evans
Copy link
Owner

This is because the pull_request event has been triggered by a fork. There is a note in the readme about this scenario.

Note: In public repositories this action does not work in pull_request workflows when triggered by forks.
This is due to token restrictions put in place by GitHub Actions. Private repositories can be configured to enable workflows from forks to run without restriction. See here for further explanation. Alternatively, use the pull_request_target event to comment on pull requests.

@staabm
Copy link
Author

staabm commented Mar 16, 2021

Thanks for noticing.

UX wise it would be great to reflect the underlying problem in the error message of the GithubAction at runtime

@peter-evans
Copy link
Owner

Yes, it's not very clear from GitHub's error message what the problem is. I'll see if I can catch this particular error and display something more meaningful.

@staabm
Copy link
Author

staabm commented Apr 10, 2021

Thanks!

@yasirroni
Copy link

yasirroni commented Apr 29, 2022

EDIT: SOLVED in #76 (comment)


This is because the pull_request event has been triggered by a fork. There is a note in the readme about this scenario.

Note: In public repositories this action does not work in pull_request workflows when triggered by forks.
This is due to token restrictions put in place by GitHub Actions. Private repositories can be configured to enable workflows from forks to run without restriction. See here for further explanation. Alternatively, use the pull_request_target event to comment on pull requests.

I'm still not understanding this.

Here is my case:

  1. Someone have a repo.

  2. I make a fork.

  3. I add this piece of code in CI .yml:

    - name: Create comment
      uses: peter-evans/create-or-update-comment@v2
      with:
        issue-number: ${{ github.event.pull_request.number }}
        body: ${{ steps.template.outputs.result }}
  1. A make a PR. Error with message Resource not accessible by integration

How and where to set pull_request_target to make the github action able to comment on PR made by public fork without asking the developer to configured enable workflows?

@yasirroni
Copy link

yasirroni commented Apr 29, 2022

Based on this asnwer, pull_request_target will work after pull_request_target event exist in the targeted branch. Thus (example for master branch), first, use:

on:
  on:
  pull_request_target:
    branches: [ master ]

Then merge first to master.

If any fork push to the master branch, the pull_request_target will be triggered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants