GitHub Actions allows you to create workflows that are triggered by events in your repository, like a push, a pull_request, or even a manual trigger.
1. The Workflow File
Workflows are defined in YAML files inside the .github/workflows/ directory.
example-workflow.yaml:
name: CI Pipeline
on:
push:
branches: [ main ]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests
run: pytest2. Running the Workflow
Trigger the Action
Action:
git add .
git commit -m "feat: add ci pipeline"
git push origin mainCheck the Result
Result: Go to the Actions tab in your GitHub repository. You will see a live log:
✓ Checkout code
✓ Set up Python
✓ Install dependencies
✓ Run tests
- pytest results: 12 passed, 0 failed
Workflow Status: Success3. GitHub Actions Terminology
| Term | Description |
|---|---|
| Workflow | The automated process (the YAML file). |
| Event | What triggers the workflow (e.g., push). |
| Job | A set of steps that run on the same runner. |
| Step | An individual task (running a script or an Action). |
| Action | A reusable application (e.g., actions/checkout). |
| Runner | The server that executes the workflow (e.g., ubuntu-latest). |
4. Using Secrets
You should never put passwords or API keys in your YAML. Use GitHub Secrets.
Action (Manifest snippet):
- name: Deploy to Production
env:
API_KEY: ${{ secrets.PROD_API_KEY }}
run: ./deploy.shSummary
- YAML based: Workflows live in your repo.
- Event driven: Push, PR, or Cron.
- Reusable: Use community actions from the GitHub Marketplace.
- Free for Public Repos: Great for open source and small teams.