-
Notifications
You must be signed in to change notification settings - Fork 19
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
Action fails on PRs that are not backported #127
Comments
I agree with this. Also when the PR hasn't been merged, the check will fail, which is also not great if you're requiring all checks to have passed to allow merging. Adding a simple condition to not run in those cases should suffice, like is done in tibdex/backport. |
Thanks for the link! I've already had a condition: But using the |
Consider making a PR since it's a good default 😉 If not, I can make one |
This should prevent users from experiencing sorenlouv#127 when simply following the README example.
* Prevent example from failing on unmerged PRs This should prevent users from experiencing #127 when simply following the README example. * Also don't run README example on backport PRs
Finally had time to get back to this. Basically Unfortunately there is no native to have a complex check for labels in GH Action expressions. The simple case works:
But the other cases don't really
tl;dr I have added a custom bash step to check labels jobs:
backport:
name: Backport PR
runs-on: ubuntu-latest
permissions: {}
if: github.event.pull_request.merged == true
steps:
- name: Check for backport labels
id: check_labels
run: |-
labels='\${{ toJSON(github.event.pull_request.labels.*.name) }}'
matched=$(echo $labels | jq '. | map(select(startswith("my-label-"))) | length')
echo "matched=$matched"
echo "matched=$matched" >> $GITHUB_OUTPUT
- name: Backport Action
if: fromJSON(steps.check_labels.outputs.matched) > 0
uses: sqren/backport-github-action@v9.5.1 |
@mrgrain I think there is a typo in your action file. There is a This workaround works fine for me: jobs:
backport:
name: Backport PR
if: github.event.pull_request.merged == true && !(contains(github.event.pull_request.labels.*.name, 'backport'))
runs-on: ubuntu-latest
steps:
# Workaround not to fail the workflow if the PR does not need a backport
# https://github.com/sorenlouv/backport-github-action/issues/127#issuecomment-2258561266
- name: Check for backport labels
id: check_labels
run: |-
labels='${{ toJSON(github.event.pull_request.labels.*.name) }}'
matched=$(echo "${labels}" | jq '. | map(select(startswith("backport-to-"))) | length')
echo "matched=$matched"
echo "matched=$matched" >> $GITHUB_OUTPUT
- name: Backport Action
if: fromJSON(steps.check_labels.outputs.matched) > 0
uses: sorenlouv/backport-github-action@v9.5.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
auto_backport_label_prefix: backport-to-
- name: Info log
if: ${{ success() && fromJSON(steps.check_labels.outputs.matched) > 0 }}
run: cat ~/.backport/backport.info.log
- name: Debug log
if: ${{ failure() && fromJSON(steps.check_labels.outputs.matched) > 0 }}
run: cat ~/.backport/backport.debug.log Thank you! |
Thanks for fixing the typo! Oh and I like the debug logging! @jfagoagas |
It's nothing! The debug logging wasn't my doing, all credits to @sorenlouv https://github.com/sorenlouv/backport-github-action?tab=readme-ov-file#getting-started |
I don't know if this is related but I have some failing jobs due to the fact that once the
Probably I'm doing something wrong but just wanted to double check if anyone has had this problem before. |
I think this issue can be resolved by use of https://github.com/marketplace/actions/label-checker-for-pull-requests (this also avoids reinventing the wheel in every workflow file just to be able to check some labels) |
That's perfect @Krzmbrzl 👏 Updated workflow: name: Automatic Backport
on:
pull_request_target:
branches: ['main']
types: ['labeled', 'closed']
jobs:
backport:
name: Backport PR
if: github.event.pull_request.merged == true && !(contains(github.event.pull_request.labels.*.name, 'backport'))
runs-on: ubuntu-latest
steps:
- name: Check labels
id: preview_label_check
uses: docker://agilepathway/pull-request-label-checker:v1.6.55
with:
allow_failure: true
prefix_mode: true
one_of: backport-to-v
none_of: was-backported
repo_token: ${{ secrets.GITHUB_TOKEN }}
- name: Backport Action
uses: sorenlouv/backport-github-action@v9.5.1
if: steps.preview_label_check.outputs.label_check == 'success'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
auto_backport_label_prefix: backport-to-
- name: Info log
if: ${{ success() && steps.preview_label_check.outputs.label_check == 'success' }}
run: cat ~/.backport/backport.info.log
- name: Debug log
if: ${{ failure() && steps.preview_label_check.outputs.label_check == 'success' }}
run: cat ~/.backport/backport.debug.log |
@jfagoagas do you want to create a PR updating the example in the README or shall I do it? :) |
I'll do that, also I'm wondering about adding the following to avoid running the action for the backport and backported PRs, what do you think? - if: github.event.pull_request.merged == true && !(contains(github.event.pull_request.labels.*.name, 'backport'))
+ if: github.event.pull_request.merged == true && !(contains(github.event.pull_request.labels.*.name, 'backport')) && !(contains(github.event.pull_request.labels.*.name, 'was-backported')) |
I think that requiring the presence of a In other words: I am not sure whether going this far with "negative label checks" is actually necessary 🤔 Finally, I am wondering whether a dedicated job for the label checking might make things more concise as that would only require a single (There are still some issues with how exactly this is being set up though, so it is not yet working) |
@Krzmbrzl The issue I'm having is that the PRs that needs to be backported, the ones having the So, the action needs to run when all of the following happens:
|
I don't think 2) is necessary as backport PRs should not get the |
Hi @Krzmbrzl you are right but with that you'll skip the execution of the whole action, removing that you will get to the label check where the action will stop. |
True. However the label check runs in like 2s or so so I wouldn't count that as an issue 🤷 |
Using the example workflow in the readme, the action will fail when a PR is merged that does not have a backport label.
This is functionally correct, but causes confusion because the PR is now displayed with a ❌ (red x) next to it.
Do you have any suggestion how this could be avoided?
To me it feels like the Action should succeed because the PR does not have any relevant labels attached. But I am open to other suggestions.
Here is the error:
Example Workflow run: https://github.com/aws/jsii-rosetta/actions/runs/9088130104/job/24977165701
Example PR: aws/jsii-rosetta#1359
The text was updated successfully, but these errors were encountered: