8

When I push some code to master, one workflow file runs. This file builds the artifacts and pushes the code to another branch production.

Another workflow file, which looks like the following, is set to run when any push happens to production.

name: Deploy

on:
  push:
    branches:
      - production

jobs:

# Do something

  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@master

But this workflow file is never run. I expect that when the workflow file, listening to push event on master, is done, this file should run as the previous file pushes code to production branch. How do I make sure that this happens?

Rohan Singh
  • 463
  • 2
  • 5
  • 8
  • Possible duplicate of: https://stackoverflow.com/questions/60418323/triggering-a-new-workflow-from-another-workflow – riQQ Sep 27 '20 at 10:18

2 Answers2

8

You need to use a personal access token (PAT) for pushing the code in your workflow instead of the default GITHUB_TOKEN:

Note: You cannot trigger new workflow runs using the GITHUB_TOKEN

For example, if a workflow run pushes code using the repository's GITHUB_TOKEN, a new workflow will not run even when the repository contains a workflow configured to run when push events occur.

If you would like to trigger a workflow from a workflow run, you can trigger the event using a personal access token. You'll need to create a personal access token and store it as a secret.

https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token

name: Push to master

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    # the checkout action persists the passed credentials by default
    # subsequent git commands will pick them up automatically
    - uses: actions/checkout@v2
      with:
        token: ${{secrets.PAT}}
    - run: |
        # do something
        git push
riQQ
  • 9,878
  • 7
  • 49
  • 66
0

If anyone else stumbles upon this, it's actually git commit that is throwing an error. The '||' catches the error and then just prints to the log so the action doesn't even get to git push.

  - name: Scrape webpage and download file
    run: | 
      python ./python/scraper.py
      git config user.name github-actions
      git config user.email email@email.com
      git commit -am "Auto Generated" || echo "There is nothing to commit"
      git push
  • If you have a new question, please ask it by clicking the [Ask Question](https://stackoverflow.com/questions/ask) button. Include a link to this question if it helps provide context. - [From Review](/review/late-answers/34637469) – olegtaranenko Jul 10 '23 at 02:58
  • Take a look again at [answer]. This doesn't seem related to the question at hand, which is about an action not being triggered. There's no indication that the OP is even calling `git commit` – camille Jul 10 '23 at 18:23