GitHub Actions Tutorial — Introduction Exercises
Practice Exercises — Introduction
Test your understanding of GitHub Actions fundamentals with these hands-on exercises.
Exercise 1 — Name the Building Blocks
Task: A workflow file is triggered when you push code. It runs two parallel jobs — one for linting and one for testing. Each job uses actions/checkout@v4 and then runs a shell command. Both jobs run on GitHub-hosted Ubuntu runners.
Identify all six building blocks in this scenario:
- Event = ?
- Workflow = ?
- Jobs = ?
- Steps = ?
- Actions = ?
- Runner = ?
Show Solution
- Event:
push - Workflow: The YAML file in
.github/workflows/ - Jobs: Two —
lintandtest(running in parallel) - Steps: Each job has two steps — one
uses:(checkout) and onerun:(shell command) - Actions:
actions/checkout@v4(the reusable pre-built action) - Runner:
ubuntu-latest(GitHub-hosted)
Exercise 2 — Calculate the Cost
Task: You have a private repository on the GitHub Free plan (2,000 minutes/month). Your CI workflow runs for 8 minutes on every push. Your team pushes an average of 15 times per day, 5 days a week.
Calculate:
- How many minutes per week?
- How many minutes per month (4 weeks)?
- Will you exceed the free tier?
- If you switched to macOS runners, how would the cost change?
Show Solution
- Per week: 8 min × 15 pushes × 5 days = 600 minutes/week (Linux, 1× multiplier)
- Per month: 600 × 4 = 2,400 minutes/month
- Yes — 2,400 exceeds the free tier of 2,000 minutes. You’d need to optimize or pay for overages.
- macOS: 8 min × 10 multiplier = 80 effective minutes per run. 80 × 15 × 5 × 4 = 24,000 minutes/month — far exceeding the free tier.
Optimization: Use path filters to skip CI on documentation-only pushes, or add concurrency cancellation to avoid running stale builds.
Exercise 3 — Match the Tool
Task: Match each scenario to the best CI/CD tool choice:
| Scenario | Best Tool |
|---|---|
| A. Open-source project on GitHub, needs free CI | ? |
| B. Enterprise with 500+ Jenkins pipelines and custom shared libraries | ? |
| C. Team using GitLab for code, issues, and CI in one platform | ? |
| D. Startup on GitHub, wants simple deploy-on-merge | ? |
| E. Company needing on-premises CI with no cloud access | ? |
Show Solution
| Scenario | Best Tool | Why |
|---|---|---|
| A | GitHub Actions | Unlimited free minutes for public repos |
| B | Jenkins | Existing investment, complex shared libraries |
| C | GitLab CI | Already on GitLab, integrated platform |
| D | GitHub Actions | Simple YAML, native GitHub integration |
| E | Jenkins | Self-hosted with no cloud dependency |
Exercise 4 — Find the Right Action
Task: Visit the GitHub Actions Marketplace (or answer from memory) and find actions for these tasks:
- Set up a Python 3.12 environment
- Build and push a Docker image to a registry
- Send a Slack notification
- Scan code for security vulnerabilities
- Cache pip dependencies
Show Solution
- Python setup:
actions/setup-python@v5withpython-version: '3.12' - Docker build & push:
docker/build-push-action@v5 - Slack notification:
slackapi/slack-github-action@v1(official Slack action) - Security scanning:
github/codeql-action/analyze@v3oraquasecurity/trivy-action@master - Cache pip:
actions/cache@v4withpath: ~/.cache/pipand a hash key based onrequirements.txt
Exercise 5 — Version Pinning
Task: Explain the security implications of each version reference:
# Option A
- uses: actions/checkout@v4
# Option B
- uses: actions/checkout@main
# Option C
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
Which would you use for: (a) a typical project, (b) a production deployment touching secrets?
Show Solution
| Option | Risk | Use Case |
|---|---|---|
A — @v4 |
Low risk. Points to the latest patch of v4. Author could update it, but major version changes are unlikely to be breaking. | ✅ Typical projects — good balance of security and convenience |
B — @main |
High risk. Points to whatever is currently on main. Could change at any time, potentially introducing malicious code. |
❌ Never use in production |
C — @sha |
Lowest risk. Points to an exact commit. Cannot change. You control when to update. | ✅ Production deployments touching secrets |
Best practice for production: Use SHA pinning (@sha) and periodically update to newer verified commits. Use tools like Dependabot to automate SHA updates.
← Back to: Chapter 1: Introduction
Next Chapter: Chapter 2: Getting Started →