devmasx / merge-branch

A GitHub Action that merge PR branch to other branchs
161 stars 58 forks source link

Workflow doesn't trigger on labeled pull request #11

Open jgonggrijp opened 3 years ago

jgonggrijp commented 3 years ago

This may or may not be an issue with the merge-branch action; I thought I'd try here before contacting GitHub.

I'm trying to set up a workflow where, when the "ready to launch" label is set on a pull request for a release/* branch, the branch in question is merged into another branch called prepublish. This workflow is defined here. It was inspired on the documentation.

I have made three failed attempts at triggering this workflow:

  1. https://github.com/documentcloud/underscore-contrib/pull/235 (workflow wasn't on master yet)
  2. https://github.com/documentcloud/underscore-contrib/pull/237 (branch was on my fork)
  3. https://github.com/documentcloud/underscore-contrib/pull/238 (branch on upstream repo, can't explain failure to trigger)

Either I'm misunderstanding how to do this, or something doesn't work as advertised in merge-branch or in the GH Actions API. Can you help me? Thanks in advance!

MiguelSavignano commented 3 years ago

Hello @jgonggrijp, thanks for the issue.

I have done some tests, the event never fires the workflow, it seems that the labeled event in a pull request does not allow filtering branches. Without the branch filter should be work.

Example:

name: Prepublication staging

on:
  pull_request:
    types: [labeled]
    # branches:
    #   - release/*
    #  - hotfix/*

jobs:
  stage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Merge into prepublish
        uses: devmasx/merge-branch@v1.3.1
        with:
          label_name: ready to launch
          target_branch: prepublish
          github_token: ${{ secrets.GITHUB_TOKEN }}

I will try to investigate a little more because it does not work with the branch filter, However, using conditions in the job should be work.

Example:

name: Prepublication staging

on:
  pull_request:
    types: [labeled]

jobs:
  stage:
    if: contains(github.ref, 'refs/release/')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Merge into prepublish
        uses: devmasx/merge-branch@v1.3.1
        with:
          label_name: ready to launch
          target_branch: prepublish
          github_token: ${{ secrets.GITHUB_TOKEN }}
jgonggrijp commented 3 years ago

Thanks for taking up on this @MiguelSavignano! I adopted your helpful suggestion to use if instead of a branch filter. I now get one step further: the workflow is triggered, but then the job is immediately skipped. Unfortunately, that page doesn't mention why the job is skipped.

If you could shine your light on this again, that would be great.

MiguelSavignano commented 3 years ago

@jgonggrijp, I was wrong the value of github.ref in a pull request event is refs/pull/{{ PR_NUMBER }}/merge. Debugging with this run, I found we can fetch the branch name with github.event.pull_request.head.ref, because of this we can use:

if: contains(github.event.pull_request.head.ref, 'release/') || contains(github.event.pull_request.head.ref, 'hotfix/')

I think it is a very common use case and it would be good to add it to the README; If it works for you; can you make a Pull request with it?

jgonggrijp commented 3 years ago

Thanks again. The job is now being run, we're getting closer! But the action is failing. There is a lot of output, it appears that some GitHub API is running into an internal server error. Can you make sense of it?

https://github.com/documentcloud/underscore-contrib/pull/238/checks?check_run_id=1573771108