Push event doesn't trigger workflow on push paths (github actions)

Viewed 2487

I'm currently testing Github Actions workflows on this repository.

Context

I'm trying to use this workflow (1st):

 on: 
   workflow_dispatch:
 
 jobs:
   job:
   runs-on: ubuntu-latest
     steps:
       - uses: actions/checkout@v2
       - run: |
           date > report.txt
           git config user.name github-actions
           git config user.email github-actions@github.com
           git add .
           git commit -m "generate or update report.txt file"
           git push

To trigger this workflow (2nd):

on:
  push:
    paths:
      - '**/report.txt'

  pull_request:
    paths:
      - '**/report.txt'

jobs:
  job:
    runs-on: ubuntu-latest
    steps:
      - run: echo "Report .txt file has been updated"

What I tried

I followed the Github Action Documentation to implement the 2nd workflow with a Filter Pattern.

When I update the report.txt file locally, then commit and push the code to the repository, the 2nd workflow triggers.

However, I don't understand why the 2nd workflow doesn't trigger when the 1st workflow is completed, even with the report.txt file being updated on the default branch.

EDIT: I know I could trigger the 2nd workflow using others trigger event types (examples: repository_dispatch or workflow_run). But I'm trying to do it from a git push command on another workflow.

Question

Did I miss something on the 1st workflow to make it trigger the 2nd, or should I add something on the 2nd workflow to make it being triggered by the 1st one?

1 Answers

No, you didn't miss anything in your workflows.

You just need a different token.

When you use actions/checkout, it uses the GITHUB_TOKEN for authentication, and according to the documentation it doesn't trigger a new workflow run:

When you use the repository's GITHUB_TOKEN to perform tasks on behalf of the GitHub Actions app, events triggered by the GITHUB_TOKEN will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs.

To make it work, you need to generate a PAT (Personal Access Token), store it in your repository secrets, and use it in your checkout step:

- uses: actions/checkout@v2
  with:
    token: ${{ secrets.YOUR_PAT_TOKEN }}
Related