Search code examples
githubgithub-actionsgithub-pages

Trigger gh-actions workflow run if previous workflow run pushes any changes


I have a gh-action workflow that generates readme files and stores them in the repository's docs folder.

I have another workflow that deploys page-builds and should be triggered if any changes occur in any README files in the doc folder.

But the second workflow does not trigger even after the first workflow creates new README files and updates the previous ones.

build workflow

name: build

on:
  workflow_dispatch:

  schedule:
    - cron: "0 */6 * * *"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: checkout repo content
        uses: actions/checkout@v3

        ...

      - name: push changes
        uses: ad-m/[email protected]
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          branch: master

deploy workflow

name: deploy

on:
  push:
    branches:
      - master
    paths:
      - docs/**/*.md

  workflow_dispatch:
    ...

Solution

  • According to the Github Official documentation

    When you use the repository's GITHUB_TOKEN to perform tasks, events triggered by the GITHUB_TOKEN, with the exception of workflow_dispatch and repository_dispatch, will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs.

    The solution is the following recommendation:

    If you do want to trigger a workflow from within a workflow run, you can use a personal access token instead of GITHUB_TOKEN to trigger events that require a token. You'll need to create a personal access token and store it as a secret.

    Here is how to create a Personal Access Token (PAT)