Git Notes
GitHub Actions is a powerful automation platform built directly into GitHub that lets you create custom workflows triggered by events in your repository....
GitHub Actions is a powerful automation platform built directly into GitHub that lets you create custom workflows triggered by events in your repository. Whether you want to run tests on every push, deploy code when a release is published, or automate repetitive tasks like labeling issues, GitHub Actions handles it all without requiring external CI/CD services.
What Are GitHub Actions
At its core, GitHub Actions is an event-driven automation system. When something happens in your repository (a push, a pull request, a new issue, a scheduled time), GitHub Actions can execute a series of commands in response. These automated processes are called workflows.
Think of it as hiring a robot assistant that watches your repository 24/7 and performs tasks whenever specific events occur — running tests, building applications, sending notifications, or deploying to servers.
Core Concepts
Workflows
A workflow is an automated process defined in a YAML file. It lives in .github/workflows/ in your repository. A repository can have multiple workflows, each handling different automation needs.
Events
Events are triggers that start a workflow. Common events include:
push— Code is pushed to a branchpull_request— A PR is opened, updated, or mergedschedule— Run at specific times (cron syntax)release— A release is publishedissues— An issue is created or modifiedworkflow_dispatch— Manually triggered from the UI
Jobs
A workflow contains one or more jobs. Each job runs on a virtual machine (runner) and contains a series of steps. Jobs run in parallel by default but can be configured to run sequentially.
Steps
Steps are individual tasks within a job. Each step is either a shell command or a reusable action.
Actions
Actions are reusable units of code that perform common tasks. The GitHub marketplace has thousands of community-created actions for everything from setting up programming languages to deploying applications.
Your First Workflow
Create .github/workflows/hello.yml:
Push this file, and GitHub Actions immediately runs the workflow. Check the "Actions" tab in your repository to see the output.
A Practical CI Workflow
Here is a realistic workflow for a JavaScript project:
Understanding Workflow Syntax
Triggers (on)
Runners
jobs:
linux-job:
runs-on: ubuntu-latest
windows-job:
runs-on: windows-latest
mac-job:
runs-on: macos-latestUsing Actions from Marketplace
steps:
- uses: actions/checkout@v4 # Official checkout action
- uses: actions/setup-python@v5 # Set up Python
- uses: actions/cache@v4 # Cache dependencies
- uses: peaceiris/actions-gh-pages@v4 # Community action for GitHub PagesEnvironment Variables and Secrets
env:
NODE_ENV: production
jobs:
deploy:
env:
API_URL: https://api.example.com
steps:
- name: Deploy
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
run: deploy.shConditional Execution
Run steps or jobs only when certain conditions are met:
steps:
- name: Deploy to production
if: github.ref == 'refs/heads/main'
run: npm run deploy:prod
- name: Deploy to staging
if: github.ref == 'refs/heads/develop'
run: npm run deploy:staging
- name: Notify on failure
if: failure()
run: echo "Something went wrong!"Job Dependencies
Control the order of job execution:
Viewing Workflow Results
After a workflow runs:
- Go to the "Actions" tab in your repository
- Click on the workflow run to see job details
- Expand each step to see its output
- Check status badges in PRs for pass/fail indication
Key Takeaways
GitHub Actions brings automation directly into your development workflow. Workflows are event-driven YAML files that define jobs and steps. Actions from the marketplace handle common tasks, while shell commands cover custom logic. Start with a simple test workflow and expand as your automation needs grow. The platform scales from individual projects to enterprise organizations, making it the natural choice for CI/CD when your code already lives on GitHub.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Introduction to GitHub Actions.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Git & GitHub topic.
Search Terms
git-github, git & github, git, github, actions, introduction, introduction to github actions
Related Git & GitHub Topics