Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pull Request is not detecting action when run via workflow_run

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

like image 692
pigfrown Avatar asked Aug 12 '21 15:08

pigfrown


People also ask

How do I enable actions in Git?

On GitHub.com, navigate to the main page of the repository. Under your repository name, click Settings. In the left sidebar, click Actions, then click General. Under "Actions permissions", select Allow OWNER, and select non-OWNER, actions and reusable workflows and add your required actions to the list.

How do I run a pull action on GitHub?

Run Actions on Pull Requests When creating a new workflow in GitHub's action builder the default trigger is the push event. You want to extend this to push and pull request events. Search the line on: [push] in your GitHub Action workflow file. Extend it to on: [push, pull_request] and you're done.


1 Answers

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

like image 135
某某某 Avatar answered Oct 21 '22 11:10

某某某