schedules.yml 1.5 KB

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