The on keyword
The on keyword says what triggers the workflow. You can trigger on push, pull request, or a schedule.
Jobs and steps
A workflow has one or more jobs. Each job runs steps. Jobs can run in parallel. Steps run one after another.
GitHub Actions is the most popular CI tool. It runs workflows stored in your repo. Learn how to write a workflow file by hand.
About 2 min of reading
Before this new lesson, one small question about the lesson you just finished. Recall it, do not look it up.
A workflow is a YAML file in the repo that says what triggers it and lists a job of steps. On every push it checks out code, installs dependencies, and runs tests, then reports a single green or red result that reviewers see before merging.
I run a workflow by hand on a push: check out the code, install requirements, run the test suite, and print the single result so it is clear the pipeline passed end to end.
Before you run it, say out loud what it will print. Then open the answer.
I add a second trigger so the pipeline runs on pull requests as well, and print that reviewers get a green check before merging.
Before you run it, say out loud what it will print. Then open the answer.
I add a deploy step that points at the production environment and injects a secret from the vault instead of writing it in the file, and print that the secret never appears in the log.
Before you run it, say out loud what it will print. Then open the answer.
Before you write anything, put these lines back in the right order. Click a line to move it up one step. This support step is easier than writing code from scratch, and it is here to make the last example stick.
The on keyword says what triggers the workflow. You can trigger on push, pull request, or a schedule.
A workflow has one or more jobs. Each job runs steps. Jobs can run in parallel. Steps run one after another.
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pip install -r requirements.txt
- run: pytest
This file runs on every push. It checks out your code, installs dependencies, and runs tests. That is a complete pipeline in a few lines.
name: PR check
on:
pull_request:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pytest
Now the pipeline runs on a push and on every pull request. Reviewers see a green check before merging. That is how teams keep the main branch clean.
- name: Deploy
run: npm run deploy
env:
API_TOKEN: ${{ secrets.API_TOKEN }}
environment: production
The environment links the job to a named deployment. It can require approval and expose secrets safely. The secret never appears in the log.
Each one is defined here on this site. Open the entry for the full definition and the other words it points at.