mheap / github-action-required-labels

Fail the build if/unless a certain combination of labels are applied to a pull request
MIT License
93 stars 22 forks source link

Action fails with "Not Found" when run in a merge queue #66

Open twyatt opened 7 months ago

twyatt commented 7 months ago

To reproduce, created a sample project repo at: https://github.com/JuulLabs/merge-queue-test

Without merge queue enabled, github-action-required-labels works (https://github.com/JuulLabs/merge-queue-test/pull/13) as expected:

GitHub Action run w/o merge queue ``` Run mheap/github-action-required-labels@v5 with: mode: exactly count: 1 labels: patch, minor, major, maintenance token: *** message: Label error. Requires {{errorString}} {{count}} of: {{ provided }}. Found: {{ applied }} add_comment: false ``` — https://github.com/JuulLabs/merge-queue-test/actions/runs/7154600875/job/19482310003

When merge queue is enabled, and github-action-required-labels runs from the queue, it fails (https://github.com/JuulLabs/merge-queue-test/pull/14) with:

Run mheap/github-action-required-labels@v5
  with:
    mode: exactly
    count: 1
    labels: patch, minor, major, maintenance
    token: ***
    message: Label error. Requires {{errorString}} {{count}} of: {{ provided }}. Found: {{ applied }}
    add_comment: false
Error: Not Found

https://github.com/JuulLabs/merge-queue-test/actions/runs/7154628159/job/19482369364

EugeneWImprint commented 2 months ago

+1! The action seems to fail when in GitHub Merge-Queue

mheap commented 1 month ago

Thanks both. I'll try to find some time to reproduce + fix

mheap commented 1 month ago

Alright, I've managed to reproduce (merge queues are not easy if you've not used them before).

The issue is that the merge_queue event does not contain any context from the PR that was being merged. That means when we try to fetch the applied labels via the API it returns a 404 as there's no PR number available.

It looks as though a failing pull_request check will cause the PR not to be added to a merge queue. Is the issue that if you set label to be a required check for PR, it also becomes required for merge_queue?

twyatt commented 1 month ago

Is the issue that if you set label to be a required check for PR, it also becomes required for merge_queue?

It has been a while since I have given merged queues a try, but that is my recollection.

From what I remember, we were using label as a required check for PR merges and wanted to leverage merge queues. When enabling merge queues, label check began failing, blocking any ability to merge PRs with merge queues. We ultimately valued having a label check over being able to use merge queues, so we abandoned the merge queues feature in the hopes that the two would one day play nice together.

mheap commented 1 month ago

It should work if you keep the label check on pull_request and split the merge_queue workflow in to a separate file. This would allow you to use the action with merge queues as it will only run on pull_request events

twyatt commented 1 month ago

It should work if you keep the label check on pull_request and split the merge_queue workflow in to a separate file.

Thanks for the tips! I'll give it a try soon.

twyatt commented 1 week ago

It should work if you keep the label check on pull_request and split the merge_queue workflow in to a separate file. This would allow you to use the action with merge queues as it will only run on pull_request events

If I'm understanding correctly, this did not work, unfortunately.

I tried with https://github.com/JuulLabs/merge-queue-test/pull/16, whereas I removed merge_group from the labels check, but in doing so: the merge queue never allows the PR to run in the merge queue:

Screenshot 2024-07-15 at 11 43 27 PM

It seems I'd have to remove the label check as a required check for merging to main, but I do want to make sure labels are assigned to PRs; so I'm not sure what the best option would be here?

twyatt commented 1 week ago

I believe the github.ref context variable is available in a merge queue. When I echoed it for https://github.com/JuulLabs/merge-queue-test/pull/17, github.ref evaluated to:

refs/heads/gh-readonly-queue/main/pr-17-a3c310584587d4b97c2df0cb46fe050cc46a15d6

Perhaps a bit clunky, but couldn't the PR number be parsed out of that variable?