How to Schedule a Retraining Pipeline in GitHub Actions
A cron-scheduled workflow pulls fresh data, retrains, checks an evaluation gate, and publishes the model only when the gate passes.
Use on.schedule with a cron expression to trigger retraining, chain data pull to train to evaluate with needs:, and gate the publish step on an accuracy threshold so a worse model is never released.
Steps
- Trigger with
on.schedule(UTC cron) plusworkflow_dispatch. - Chain pull, train, and evaluate jobs with
needs:. - Publish only when the eval gate passes.
Workflow
.github/workflows/retrain.yml
on:
schedule:
- cron: '0 4 * * 1' # 04:00 UTC every Monday
workflow_dispatch:
jobs:
retrain:
runs-on: [self-hosted, gpu]
steps:
- uses: actions/checkout@v4
- run: dvc pull -j 4
- run: python train.py --epochs 3
- name: Eval gate
run: python evaluate.py --min-accuracy 0.90
- name: Publish if gate passed
run: python publish.py
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}Gotchas
- Scheduled runs use the default branch and can be delayed under platform load.
- Fail the eval gate before publish so a regression never ships automatically.
Related guides
How to Keep Full Training Out of CI to Control Cost in GitHub ActionsDecide what training runs in GitHub Actions versus an external trainer, keeping smoke tests in CI and dispatc…
How to Publish a Model to a Registry in GitHub ActionsPush a trained model to the Hugging Face Hub or an MLflow registry from GitHub Actions using a token secret,…