Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub action workflow schedule not working on non-default branch

I am trying to setup a workflow on a branch called workflow-test. It has to run on a schedule and run every 24 hours. This workflow has to run a python script and commit and push the changes made by the python script. I got it to work on pushes, but it doesn't seem to work on schedules. I have looked at every question regarding this topic and tried all solutions, but to no avail.

This is my code:

name: update-state
on: 
  schedule:
    - cron: '0 0 * * *'

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Git checkout
        uses: actions/checkout@v2
        with:
          ref: workflow-test

      - name: Setup python
        uses: actions/setup-python@v1
        with:
          python-version: '3.x'
      - name: Execute script
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
          python scripts/script.py
        
      - name: Commit files
        run: |
          git config --local user.email "[email protected]"
          git config --local user.name "GitHub Action"
          git add -A
          git commit -m "update data" -a
      - name: Push changes
        uses: ad-m/[email protected]
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          branch: workflow-test

This is what I have tried:

  • Run a schedule on the master branch, which should trigger the schedule to work on the other branch, according to a stack overflow answer;
  • Add the with: ref: branch-part.

I have also tried just triggering this workflow on a push, which did work. Everything ran and worked. This was without the with: ref: branch-part. But from what I understand that is necessary when working with a schedule because schedule checks out to the last commit of the default branch, thus it has to be changed to the branch you are working on.

It doesn't seem to even attempt to run this workflow. It gives no record of attempting to run this workflow under the "actions" tab. Thus, I believe the problem lies with the schedule part, since it works on push and doesn't even run when working on a schedule.

I have also tried adding a simple workflow on schedule to my master branch, which does run. But when I add this simple workflow on schedule to my workflow-test branch, it doesn't run anymore.

I can't find anymore fixes on stack overflow, documentation or anywhere else. Thus I decided to open my own question. I hope someone can help me. Thanks in advance :).

Edit: this workflow updates the data used by a website.

like image 664
Cristian Perez Avatar asked Aug 16 '20 11:08

Cristian Perez


1 Answers

Scheduled GitHub Actions run on the default or base branch, as specified by the documentation:

Scheduled workflows run on the latest commit on the default or base branch.

Which means that your workflow file must be committed to the master branch. It then can check out code from other branches, but the workflow file itself must reside in master.

Here is the most minimal example that demonstrates how it works.

name: Experiment
on: 
  schedule:
  - cron: '*/5 * * * *'

jobs:
  job1:
    name: Debug
    runs-on: ubuntu-latest

    steps:
    - name: Git checkout
      uses: actions/checkout@v2
      with: { ref: debug }
    - name: List files
      run: ls

This action runs every 5 minutes (*/5) and lists the files in the debug branch.

like image 131
DannyB Avatar answered Oct 11 '22 02:10

DannyB