labeler icon indicating copy to clipboard operation
labeler copied to clipboard

Labeler not triggering 'labeled' pull_request event type

Open mosherc opened this issue 3 years ago • 5 comments

I would like to perform some action when labeler labels my PR with a specific label. When I commit changes that trigger labeler, that is a pull_request synchronize type, but after the labeler runs, it does not trigger a labeled event so I can check what label is present and perform an action on that. I tried workflow_run but not getting anything working that way either, plus apparently there is no output from the action.

mosherc avatar Feb 03 '22 06:02 mosherc

This is affecting me as well.

We have a label for high impact "Breaking Changes" that we apply to any PR that touches API specs and shared contracts. In addition to this label, I want to add a PR comment with some polite reminders and resources for the development team.

Something like this:

on:
- pull_request_target

jobs:
  triage:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/labeler@v3
      with:
        repo-token: "${{ secrets.GITHUB_TOKEN }}"
        sync-labels: true
on:
  pull_request:
    types: [ labeled ]

jobs:
  breaking-changes:
    if: ${{ github.event.label.name == 'BREAKING CHANGES' }}
    runs-on: ubuntu-latest
    steps:
    - uses: actions/github-script@v6
      with:
        github-token: ${{secrets.GITHUB_TOKEN}}
        script: |  
          const message = `
            :fire: It looks like this PR contains **BREAKING CHANGES** to API docs, HTTP Clients or contracts.
          `
          github.rest.issues.createComment({
            issue_number: context.issue.number,
            owner: context.repo.owner,
            repo: context.repo.repo,
            body: message
          })

This works fine when the label is manually applied, but not when using the labeler action.

note: edited to add labeler workflow

bcowdery avatar Feb 24 '22 21:02 bcowdery

Hi folks, I've been facing a similar issue, this actually works, but you'll need to use a Personal access token instead of the GitHub token provided just for the current action.

like so:

  add-stage-label:
    runs-on: ubuntu-latest
    needs: remove-build-label
    steps:
    - name: Add 🚀 Label
      uses: actions/labeler@v3
      with:
        repo-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
        sync-labels: true
        configuration-path: .github/deploy-labeler.yml

irving-caamal avatar Feb 25 '22 03:02 irving-caamal

Hi folks, I've been facing a similar issue, this actually works, but you'll need to use a Personal access token instead of the GitHub token provided just for the current action.

@irvv17 Just to confirm, if you use a PAT then the labeler action does correctly trigger the pull_request labeled event in another workflow?

Also could you please share what permissions you used in your PAT?

I wonder if this is just a case of a missing permission on the GITHUB_TOKEN. We could potentially work around the issue by customizing the workflow permissions and adding the missing ones. My repo is configured with "permissive" workflow permissions (defaults to read/write for most scopes) - so im not sure what it could be missing...

Something like:

permissions:
  contents: read
  pull-requests: write

bcowdery avatar Feb 25 '22 18:02 bcowdery

Hi folks, I've been facing a similar issue, this actually works, but you'll need to use a Personal access token instead of the GitHub token provided just for the current action.

@irvv17 Just to confirm, if you use a PAT then the labeler action does correctly trigger the pull_request labeled event in another workflow?

Also could you please share what permissions you used in your PAT?

I wonder if this is just a case of a missing permission on the GITHUB_TOKEN. We could potentially work around the issue by customizing the workflow permissions and adding the missing ones. My repo is configured with "permissive" workflow permissions (defaults to read/write for most scopes) - so im not sure what it could be missing...

Something like:

permissions:
  contents: read
  pull-requests: write

Yeah, it does trigger the pull_request labeled event in another file/workflow

I set the permissions that Guthub suggest in the docs

Here is the example of the permissions give it by the docs:

image

Hope it can helps :D

irving-caamal avatar Feb 28 '22 03:02 irving-caamal

Apparently, this is intended behavior (to prevent recursive workflow runs), and is documented here: https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow

Relevant community issue: https://github.community/t/github-actions-bot-labeling-triggers-not-the-issue-labeled-event/16995

thomdixon avatar Jun 23 '22 18:06 thomdixon

Hello everyone! Thank you all for sharing the information and solution! I’m closing the issue. Please contact us if you have any concerns.

MaksimZhukov avatar Dec 12 '22 08:12 MaksimZhukov