|
| 1 | +# Schedule It to Run Every Day |
| 2 | + |
| 3 | +> _Automating the trigger is what turns a one-off script into a true workflow — after this step your report will arrive without you lifting a finger._ |
| 4 | +
|
| 5 | +## 🎯 What You'll Do |
| 6 | + |
| 7 | +You'll update the `schedule` trigger in your workflow using gh-aw's fuzzy schedule syntax so GitHub Actions runs it at exactly the cadence you want. By the end, you'll know how to express any recurring schedule in plain English. |
| 8 | + |
| 9 | +## 📋 Before You Start |
| 10 | + |
| 11 | +- You have a working, manually tested workflow from [Test and Improve Your Workflow](12-test-and-iterate.md). |
| 12 | +- Your workflow file lives at `.github/workflows/daily-status.md`. |
| 13 | + |
| 14 | +## Steps |
| 15 | + |
| 16 | +### 1. Open your workflow file |
| 17 | + |
| 18 | +In your editor (or Codespace), open `.github/workflows/daily-status.md`. |
| 19 | + |
| 20 | +### 2. Locate the `on:` block |
| 21 | + |
| 22 | +You should already have a `schedule: daily` trigger and a `workflow_dispatch` trigger: |
| 23 | + |
| 24 | +```yaml |
| 25 | +on: |
| 26 | + schedule: daily |
| 27 | + workflow_dispatch: {} |
| 28 | +``` |
| 29 | +
|
| 30 | +### 3. Choose your schedule |
| 31 | +
|
| 32 | +gh-aw accepts natural-language schedule expressions — no cron syntax needed. The `gh aw compile` command expands them into the correct cron expression automatically. |
| 33 | + |
| 34 | +| What you want | Fuzzy expression | |
| 35 | +|---------------|-----------------| |
| 36 | +| Once a day (midnight UTC) | `schedule: daily` | |
| 37 | +| Weekdays only | `schedule: daily on weekdays` | |
| 38 | +| Once a week | `schedule: weekly` | |
| 39 | +| Every hour | `schedule: hourly` | |
| 40 | +| Every six hours | `schedule: every 6 hours` | |
| 41 | + |
| 42 | +Pick the cadence that fits your team and update the `schedule:` line accordingly. For example, to run only on weekdays: |
| 43 | + |
| 44 | +```yaml |
| 45 | +on: |
| 46 | + schedule: daily on weekdays |
| 47 | + workflow_dispatch: {} |
| 48 | +``` |
| 49 | + |
| 50 | +> [!TIP] |
| 51 | +> Keep `workflow_dispatch` in the file even after you go to production. It lets you re-run the report on demand without changing the schedule. |
| 52 | + |
| 53 | +### 4. Compile and validate |
| 54 | + |
| 55 | +After editing, compile the file to make sure the expression is recognised: |
| 56 | + |
| 57 | +```bash |
| 58 | +gh aw compile .github/workflows/daily-status.md --validate |
| 59 | +``` |
| 60 | + |
| 61 | +You should see `✅ Compiled successfully`. The compiled `.yml` will contain the expanded cron expression — you don't need to write or maintain it by hand. |
| 62 | + |
| 63 | +### 5. Commit and push |
| 64 | + |
| 65 | +```bash |
| 66 | +git add .github/workflows/daily-status.md |
| 67 | +git commit -m "chore: schedule daily status workflow" |
| 68 | +git push |
| 69 | +``` |
| 70 | + |
| 71 | +### 6. Confirm the schedule is registered |
| 72 | + |
| 73 | +Navigate to your repository on GitHub, then **Actions → daily-status**. On the right-hand sidebar you'll see a **This workflow has a schedule trigger** badge. |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +> [!WARNING] |
| 78 | +> GitHub may delay the very first scheduled run by up to 15 minutes after you push. If the workflow doesn't fire at the expected time, check **Actions** for queued runs before assuming something is broken. |
| 79 | + |
| 80 | +### 7. Wait for or trigger a run |
| 81 | + |
| 82 | +You can wait for the next scheduled time, or click **Run workflow** → **Run workflow** to trigger it immediately and confirm everything still works. |
| 83 | + |
| 84 | +## ✅ Checkpoint |
| 85 | + |
| 86 | +- [ ] Your `on:` block contains both `workflow_dispatch` and a `schedule` fuzzy expression |
| 87 | +- [ ] The schedule expression reflects the cadence you actually want |
| 88 | +- [ ] `gh aw compile .github/workflows/daily-status.md --validate` reports no errors |
| 89 | +- [ ] You have pushed the change and can see the schedule badge in the Actions UI |
| 90 | +- [ ] At least one scheduled (or manual) run has completed successfully after the change |
| 91 | + |
| 92 | +**Next:** [What's Next? Keep Exploring](14-next-steps.md) |
0 commit comments