Automating Provisioning with GitHub Actions
This lesson explains how GitHub Actions workflows provision infrastructure, how environments add approvals, and how training and deployment workflows are separated.
Learning outcomes
After completing this lesson, you will be able to:
- Describe workflow triggers and their uses.
- Explain how what-if and deployment are split between pull requests and merges.
- Describe how GitHub environments gate production.
- Distinguish CI, continuous training and continuous deployment stages.
Workflow structure
A workflow is a YAML file in .github/workflows. It has triggers (on), one or more jobs that run on runners, and steps within each job that run actions or shell commands. Jobs run in parallel unless needs creates a dependency, and each job can use a GitHub environment.
| Trigger | Example | Typical MLOps use |
|---|---|---|
pull_request | Changes to infra/** | What-if previews, tests, prompt evaluations |
push | Merge to main | Provision infrastructure, register components, start training |
workflow_dispatch | Manual run with inputs | Ad hoc retraining or rollback |
schedule | Cron expression | Periodic retraining or evaluation |
repository_dispatch | An external webhook call | Retraining started by a monitoring alert |
Path filters such as paths: ["infra/**"] make a workflow run only when relevant files change, so editing a README does not redeploy infrastructure.
Environments and approvals
A GitHub environment, such as dev, test or production, holds variables and secrets for that stage and protection rules: required reviewers who must approve before the job starts, wait timers, and restrictions on which branches may deploy. A job that references environment: production pauses until a reviewer approves, and its OIDC token carries the environment subject, which a production-only federated credential can require.
This combination gives a controlled promotion path: automatic deployment to development, deployment to test after tests pass, and deployment to production only after a named person approves, with an audit trail in GitHub of who approved what and when.
A provisioning workflow
The following workflow previews infrastructure changes on pull requests and deploys them on merge. The what-if output in the pull request lets reviewers see exactly which resources would change before approving.
name: infrastructure
on:
pull_request:
paths: ["infra/**"]
push:
branches: [main]
paths: ["infra/**"]
permissions:
id-token: write
contents: read
jobs:
preview:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- run: az deployment group what-if -g rg-ml-dev -f infra/main.bicep -p infra/dev.bicepparam
deploy:
if: github.event_name == 'push'
runs-on: ubuntu-latest
environment: dev
steps:
- uses: actions/checkout@v4
- uses: azure/login@v2
with:
client-id: ${{ vars.AZURE_CLIENT_ID }}
tenant-id: ${{ vars.AZURE_TENANT_ID }}
subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- run: az deployment group create -g rg-ml-dev -f infra/main.bicep -p infra/dev.bicepparam
- run: |
az extension add --name ml --yes
az ml compute create --file compute/cpu-cluster.yml -g rg-ml-dev -w mlw-churn-devTraining and deployment workflows
A training workflow submits a pipeline job and, optionally, waits for it. az ml job create returns as soon as the job is submitted; adding --stream or polling az ml job show lets the workflow wait and fail if the job fails. Long training runs are often started by the workflow and followed by a separate workflow or event when they finish, so that a runner is not occupied for hours.
- Continuous integration: on pull requests, run unit tests, lint YAML, and run the pipeline on a small sample to catch errors early.
- Continuous training: on merge, on schedule or on a monitoring event, run the full training pipeline and register a candidate model.
- Continuous deployment: after evaluation and approval, share the model to a registry and deploy it to the next environment's endpoint with a gradual rollout.
Each stage uses its own GitHub environment and Azure identity, so a failure or compromise in one stage cannot affect the next.
Gating production
A company's workflow deploys models to production automatically whenever a pipeline registers a new model with an AUC above 0.85. After a model with a high AUC but a data leakage bug reached production, management required that a risk officer approve every production deployment, with a record of the approval, while keeping everything else automated.
Create a GitHub environment named production with the risk officer as a required reviewer, and make the production deployment job reference it. The job pauses until the officer approves, GitHub records the approval, and the job's OIDC token carries the environment subject, so its federated credential can be restricted to approved production runs.
Raising the AUC threshold would not catch problems such as data leakage. A manual deployment by the risk officer would add effort and remove automation. A pull request review of the workflow file approves the process once, not each deployment.
How can a team ensure that infrastructure changes are deployed to production only after a named person approves them?
Show answer
Run the production job in a GitHub environment with required reviewers, and give that environment its own Azure identity, so the job cannot run, or sign in, until approval.
Exam Tips
Remember for the exam
- Triggers: pull_request, push, workflow_dispatch, schedule, repository_dispatch.
- Run what-if on pull requests and deploy on merge, with path filters.
- GitHub environments add required reviewers and environment-specific identities.
- Separate CI, continuous training and continuous deployment stages with their own identities.