GitHub Actions is GitHubβs built-in system for automating tasks in your repoβlike testing code, building apps, and deploying projects.
Itβs a core part of CI/CD (Continuous Integration / Continuous Deployment) used in real software companies.
π GitHub Actions (CI/CD Automation Basics)
π§ What is CI/CD?
CI = Continuous Integration
Automatically tests your code every time you push changes.
CD = Continuous Deployment
Automatically deploys your app when code is ready.
π In simple terms:
Push code β GitHub runs checks β If everything passes β deploy or approve
βοΈ What are GitHub Actions?
GitHub Actions lets you create workflows that run automatically when something happens in your repo.
Examples:
- Push code β run tests
- Open Pull Request β check code quality
- Merge to main β deploy website
- Schedule task β run every day
π§© Key Concepts
π‘ Workflow
A full automation process (YAML file)
Example:
βRun tests and deploy appβ
π’ Event
What triggers the workflow
Examples:
- push
- pull_request
- schedule
π΅ Job
A group of steps that run on a machine
π£ Step
Individual command or action
π₯οΈ Runner
The machine that executes your workflow (Linux, Windows, Mac)
π 3. Where GitHub Actions live
They are stored in:
```plaintext id="g7m3tq"
.github/workflows/
Example file:
```plaintext id="2kqz91"
.github/workflows/nodejs.yml
π οΈ First Simple GitHub Action (Hello World CI)
Create this file:
```yaml id="7xkq1p"
name: Basic CI
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Say Hello
run: echo "Hello, GitHub Actions!"
### What happens?
Every time you push to `main`, GitHub prints:
```plaintext
Hello, GitHub Actions!
π§ͺ Real CI Example (Node.js project)
This is what real developers use:
```yaml id="k3n8dj"
name: Node.js CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
---
# π Simple CD (Deployment Example)
Example: Deploy to server or hosting after push
```yaml id="8v2q9m"
name: Deploy App
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: npm install
- name: Build project
run: npm run build
- name: Deploy
run: echo "Deploying app..."
(Real deployments would connect to Vercel, AWS, etc.)
π₯ Common GitHub Actions Use Cases
π§ͺ Testing
- Run unit tests
- Run lint checks
ποΈ Build automation
- Compile code
- Build React/Next.js apps
π Deployment
- Deploy to Vercel, AWS, Firebase, Netlify
π Security checks
- Scan dependencies
- Check vulnerabilities
π€ Automation
- Auto-label PRs
- Auto-comment on issues
- Run scheduled jobs
π§ GitHub Actions in real life
A real workflow looks like:
- Developer pushes code
- GitHub runs tests automatically
- If tests pass β PR allowed
- Merge to main
- App is automatically deployed
π This removes manual work completely.
β οΈ Common beginner mistakes
β Wrong YAML spacing
YAML is sensitiveβindentation matters.
β Missing checkout step
You must include:
```yaml id="f1p9sl"
uses: actions/checkout@v4
### β Not specifying trigger (on:)
Without it, workflow wonβt run.
### β Overcomplicating workflows
Start simple β add complexity later.
---
# π§ Basic GitHub Actions structure
```plaintext id="c7m2kf"
on: (trigger event)
jobs:
job-name:
runs-on: machine-type
steps:
- action
- run command
π‘ Final Summary
GitHub Actions = automation for your GitHub repo
You use it to:
- Test code automatically
- Build projects
- Deploy apps
- Save time
- Prevent bugs
Top comments (0)