1. name: Schedule
    
  2. 
    
  3. on:
    
  4.   schedule:
    
  5.     - cron: '42 2 * * *'
    
  6.   workflow_dispatch:
    
  7. 
    
  8. jobs:
    
  9.   trigger-runs:
    
  10.     runs-on: ubuntu-latest
    
  11.     environment: schedules
    
  12.     name: Trigger Full Build
    
  13.     # Only trigger on the main Django repository
    
  14.     if: (github.event_name == 'schedule' && github.repository == 'django/django') || (github.event_name != 'schedule')
    
  15.     strategy:
    
  16.       matrix:
    
  17.         branch:
    
  18.           - main
    
  19.     steps:
    
  20.       - uses: actions/github-script@v6
    
  21.         with:
    
  22.           github-token: ${{secrets.SCHEDULE_WORKFLOW_TOKEN}}
    
  23.           script: |
    
  24.             const yesterday = new Date(new Date() - (1000 * 3600 * 24)).toISOString();
    
  25.             const { data: commits } = await github.rest.repos.listCommits({
    
  26.               owner: context.repo.owner,
    
  27.               repo: context.repo.repo,
    
  28.               sha: '${{ matrix.branch }}',
    
  29.               since: yesterday,
    
  30.               per_page: 1
    
  31.             });
    
  32.             if (commits.length) {
    
  33.               console.log(`Found new commit with SHA ${commits[0].sha} on branch ${{ matrix.branch }}`)
    
  34.               await github.rest.actions.createWorkflowDispatch({
    
  35.                 owner: context.repo.owner,
    
  36.                 repo: context.repo.repo,
    
  37.                 workflow_id: '.github/workflows/schedule_tests.yml',
    
  38.                 ref: '${{ matrix.branch }}',
    
  39.               })
    
  40.             } else {
    
  41.               console.log(`No commits found since ${yesterday} on brach ${{ matrix.branch }}`)
    
  42.             }