Pull Request is not detecting action when run via workflow_run
Asked Answered
L

3

9

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

Labial answered 12/8, 2021 at 15:9 Comment(1)
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 eitherTurnabout
S
2

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

I wrote a small demo for your case

name: stackoverflow-68759990

on:
  pull_request:
    branches: [ main ]

jobs:
  first:
    name: pretend the First workflow
    uses: bxb100/action-test/.github/workflows/reusable-workflow-A.yml@main
   
  second:
    name: pretend the Second workflow
    needs: first
    uses: bxb100/action-test/.github/workflows/reusable-workflow-C.yml@main

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

Striation answered 11/1, 2022 at 17:19 Comment(1)
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.Oculomotor
I
-1

My issue was referring to the main branch's workflow in a 'uses' statement. The following code got the action seen and triggered:

jobs: 
  MyJob:
    uses: my-org/my-app/.github/workflows/deploy-workflow-dry-run.yml@my-feature-branch

If I didn't have the @my-feature-branch specified or if I had @main, it would not show up in running actions. I only put 'my-feature-branch' above to sanity check that it works, as we obviously can't keep using the name of a specific branch. Before I merge it, I will have it point to main, so I suppose we'll have to force merge it in the first time.

Intellectuality answered 13/9, 2022 at 21:47 Comment(0)
T
-2

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

Traci answered 8/9, 2021 at 13:11 Comment(1)
Tried but no difference at all which is expected as both are correct yml syntax for arrays: https://mcmap.net/q/116556/-yaml-multi-line-arrays. Plus the workflow does execute on the provided branch, the issue is with the PRTurnabout

© 2022 - 2024 — McMap. All rights reserved.