Workflow
Why learn about workflows
In the AI era of development, the less manual repetition the better. Workflow automation helps you:
- Automatically run tests and builds after code commits
- Automatically deploy websites or applications
- Automate routine tasks (data backups, scheduled reports)
Mastering workflow automation is an essential skill for modern developers and one of the capabilities Andrew Ng mentions for "AI engineers."
GitHub Actions
GitHub Actions is one of the most commonly used CI/CD tools, deeply integrated with GitHub. You can use it to automatically build, test, and deploy projects.
What is CI/CD
- CI (Continuous Integration): After every code commit, automatically run tests and builds to ensure code quality
- CD (Continuous Deployment): After tests pass, automatically deploy to production
Basic concepts
- Workflow: YAML files defined in the
.github/workflows/directory - Trigger: What event triggers the workflow (e.g., push, pull request)
- Job: A task unit within a workflow
- Step: A specific action within a job
Example: auto-build MkDocs site
# .github/workflows/deploy.yml
name: Deploy to GitHub Pages
on:
push:
branches:
- main
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Build site
run: mkdocs build --clean
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site
Common GitHub Actions
Auto-run tests
name: Run Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests
run: pytest
Code quality check
name: Lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install linter
run: pip install ruff
- name: Check code style
run: ruff check .
Other automation tools
Makefile
For simple local automation tasks, Makefile remains the most practical solution (see the [[Make]] section).
pre-commit
Automatically run checks before Git commits:
pip install pre-commit
# .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
Husky
Use Git Hooks in Node.js projects:
npx husky init
Other resources
- GitHub Actions Official Documentation
- awesome-actions — curated list of useful Actions
- CI/CD Tutorial by Ruanyifeng