β¨ What is GitHub Actions?
GitHub Actions is a powerful CI/CD tool built directly into GitHub that allows you to automate your software workflows, such as:
Building and testing code automatically when you push.
Deploying applications.
Running scheduled jobs.
Automating tasks like code linting, formatting, or tagging.
π Real-World Use Case: Automating Tests for a Node.js App
Letβs walk through a real-world example where we automatically:
Run tests on every push.
Lint code using ESLint.
Only allow merge if tests pass.
π Project Structure
Hereβs a simple Node.js app structure:
my-node-app/
βββ .github/
β βββ workflows/
β βββ nodejs.yml
βββ app.js
βββ package.json
βββ .eslintrc.json
βββ test/
βββ app.test.js
β
Step-by-Step: Creating Your First Workflow
π Step 1: Create Workflow File
Create a file in your repo:
.github/workflows/nodejs.yml
π§© Step 2: Add This Workflow YAML
name: Node.js CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm install
- name: Run Linter
run: npm run lint
- name: Run Tests
run: npm test
β This workflow is triggered on every push or pull request to the main branch.
πΌ Image: GitHub Actions UI
Once your workflow is pushed, go to the Actions tab in your repo to see it run:
π§ͺ Real-Time Output
If you include a test like this in test/app.test.js:
const assert = require('assert');
describe('Sample Test', () => {
it('should return true', () => {
assert.strictEqual(true, true);
});
});
Youβll see this in the Actions logs:
mocha
Sample Test
β should return true
1 passing (12ms)
π Now every push runs your tests!
π Deploy to GitHub Pages or AWS
You can deploy to:
GitHub Pages: Use peaceiris/actions-gh-pages
AWS S3: Use jakejarvis/s3-sync-action
Example:
- name: Deploy to S3 uses: jakejarvis/s3-sync-action@master with: args: --acl public-read --delete env: AWS_S3_BUCKET: ${{ secrets.AWS_BUCKET }} AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }} π Using Secrets Store sensitive info like AWS keys in Settings > Secrets and variables > Actions.
Then access them like:
env:
TOKEN: ${{ secrets.MY_SECRET_TOKEN }}
π Monitoring and Debugging
Use core.set-output to debug values.
Add continue-on-error: true to experiment safely.
Use matrix to test across different Node versions.
π Final Thoughts
GitHub Actions makes DevOps easier right inside your GitHub repo. Whether you're building apps, running tests, or deploying live, GitHub Actions provides a robust and scalable way to automate it all.

Top comments (0)