6

I have 2 workflows in my repository:

name: First

on:
  pull_request:
    branches: [ master ]

jobs:
  test:
    name: test
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
   
    - name: Set up Go
      uses: actions/setup-go@v2
      with:
        go-version: 1.16

    - name: Test
      run: go test -v ./...

and

name: Second

on:
  workflow_run:
    workflows: ["First"]
    types:
      - completed

jobs:
  golangci:
    if: ${{ github.event.workflow_run.conclusion == 'success' }}

    name: lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: golangci-lint
        uses: golangci/golangci-lint-action@v2
        with:
          version: latest

The second workflow is launched only when the first workflow successfully completes. This part works.

I have set branch rules so that any pull request on "master" must have these 2 workflows pass. When I make/update a PR both the workflows run as expected. However the PR never detects that the 2nd workflow has run.. it gets stuck in the "Expected — Waiting for status to be reported" state.

I assume this is because the 2nd workflow is not triggered by a pull request, but by the previous workflow. Is there a way I can make my 2nd workflow notify the correct pull request that it has completed?

(this is a trivial example that illustrates a problem that occurs on a much larger repository with multiple workflows, it would not be ideal to have all jobs in one workflow in the large repo).

Thanks

Kia Kaha
  • 1,128
  • 1
  • 13
  • 30
pigfrown
  • 63
  • 5
  • I have tried to point the checkout step like this: `with: ref: ${{ github.event.workflow_run.head_branch }}` or `${{ github.event.workflow_run.head_sha }}` but nothing seems to work either – Kia Kaha Sep 02 '21 at 07:26

2 Answers2

1

The workflow_run does not show the PR check list, but GitHub supports reusing workflow ^1

I wrote a small demo for your case https://github.com/bxb100/action-test/blob/main/.github/workflows/stackoverflow-68759990.yml

the config like this:

                       +---------------------------+
           +-----------+ event: pull_request[main] +----------+
           |           +---------------------------+          |
           |                                                  |
           |                                                  |
           v                                                  v
+------------------------+                        +--------------------------+
| stackoverflow-68759990 |                        | stackoverflow-68759990-1 |
+---+--------------------+                        +---+----------------------+
    |                                                 |
  jobs                                             workflow_run
    |       +------------------------------+          |       +--------------------------+
    +------>| reusable-workflow-A.yml@main |          +------>| stackoverflow-68759990-2 |
    |       +------------------------------+                  +--------------------------+
    |
    |       +------------------------------+
    +------>| reusable-workflow-C.yml@main |
            +------------------------------+

workflow_run: stackoverflow-68759990-1.yml trigger stackoverflow-68759990-2.yml

reusing: stackoverflow-68759990.yml trigger reusable-workflow-A.yml then reusable-workflow-C.yml

When you PR, you can see the stackoverflow-68759990-2 not showing below

enter image description here

you can echo the workflow payload to prove that had been triggered ^2

enter image description here

某某某
  • 146
  • 1
  • 4
  • Just to add a clarification to this answer: `68759990-1.yml` is followed by `68759990-2.yml` via `workflow_run`. The above screenshot doesn't prove whether `68759990-2.yml` actually ran, but assuming it did, it wasn't connected to the PR as otherwise we'd see an entry for `second / actions-tagger (workflow_run)`. The reusable workflows that are called by `68759990.yml` would be visible if you clicked into either of the two jobs and looked at the steps, but they're not their own workflows, they're just steps of `68759990.yml`. – snazzybouche Apr 08 '22 at 13:05
-1

I think the way you are specifying the master branch is not correct. I think you should try like this in your work flow:

on:
  # Trigger the workflow on pull request,
  # but only for the master branch
  pull_request:
    branches:
      - master

Ref: Github Docs

Pankaj
  • 591
  • 5
  • 19
  • Tried but no difference at all which is expected as both are correct yml syntax for arrays: https://stackoverflow.com/a/33136212/6355024. Plus the workflow does execute on the provided branch, the issue is with the PR – Kia Kaha Sep 09 '21 at 07:51