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

Workflow doesn't trigger on labeled pull request #11

Open
jgonggrijp opened this issue Dec 14, 2020 · 4 comments
Open

Workflow doesn't trigger on labeled pull request #11

jgonggrijp opened this issue Dec 14, 2020 · 4 comments

Comments

@jgonggrijp
Copy link

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. Testing continuous deployment automation workflows documentcloud/underscore-contrib#235 (workflow wasn't on master yet)
  2. Testing continuous deployment, bis documentcloud/underscore-contrib#237 (branch was on my fork)
  3. Testing continuous deployment, bis, bis documentcloud/underscore-contrib#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
Copy link
Member

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/[email protected]
        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/[email protected]
        with:
          label_name: ready to launch
          target_branch: prepublish
          github_token: ${{ secrets.GITHUB_TOKEN }}

jgonggrijp added a commit to documentcloud/underscore-contrib that referenced this issue Dec 17, 2020
@jgonggrijp
Copy link
Author

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
Copy link
Member

MiguelSavignano commented Dec 17, 2020

@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 added a commit to documentcloud/underscore-contrib that referenced this issue Dec 17, 2020
@jgonggrijp
Copy link
Author

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

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

No branches or pull requests

2 participants