π Day 11 of 30 Days of DevOps Interview Preparation β GitHub Actions: Basic Workflow YAML

Series: 30 Days DevOps Interview Preparation
Author: Tathagat Gaikwad
In this post, we dive into GitHub Actions β a native CI/CD tool that allows developers to automate, customize, and execute workflows right from their GitHub repositories.
By the end, youβll know:
How to write a basic workflow YAML.
How to trigger pipelines based on Git events.
How to integrate with AWS for real deployments.
Common interview questions & answers on GitHub Actions.
π 1. What is GitHub Actions?
GitHub Actions is a CI/CD and automation service tightly integrated with GitHub. It helps you automate tasks like:
Running tests on every commit.
Deploying applications to cloud environments.
Building Docker images.
Running scheduled maintenance scripts.
Key Components:
Workflow: Defined in
.github/workflows/*.yml
β contains automation rules.Event: Triggers the workflow (
push
,pull_request
,workflow_dispatch
,schedule
).Job: A group of steps executed in the same environment.
Step: An individual task (command or prebuilt action).
π 2. Basic GitHub Actions Workflow YAML
Letβs create a Node.js CI workflow that runs tests on every push to the main
branch.
name: Node.js CI
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
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 tests
run: npm test
β 3. Practical AWS Deployment with GitHub Actions
Hereβs a real-world workflow for deploying to AWS EC2 after tests pass.
name: Deploy to AWS EC2
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
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 tests
run: npm test
- name: Deploy to AWS EC2
env:
HOST: ${{ secrets.AWS_HOST }}
USER: ${{ secrets.AWS_USER }}
KEY: ${{ secrets.AWS_SSH_KEY }}
run: |
echo "$KEY" > key.pem
chmod 400 key.pem
scp -i key.pem -o StrictHostKeyChecking=no ./build.zip $USER@$HOST:/home/ec2-user/
ssh -i key.pem -o StrictHostKeyChecking=no $USER@$HOST "unzip -o build.zip && pm2 restart app"
How to set secrets in GitHub:
Go to your repository β Settings β Secrets and variables β Actions.
Add:
AWS_HOST
β EC2 public IPAWS_USER
βec2-user
(Amazon Linux) orubuntu
(Ubuntu)AWS_SSH_KEY
β Private SSH key for EC2
π‘ 4. Why This Matters in Interviews
Interviewers expect you to know:
How workflows are structured (
on
,jobs
,steps
).The difference between self-hosted runners and GitHub-hosted runners.
How to handle secrets securely in GitHub Actions.
How to integrate GitHub Actions with cloud providers.
π 5. Common GitHub Actions Interview Questions
Q1: How do you trigger a GitHub Action only for a specific branch?
A: Use on: push: branches: [branch-name]
.
Q2: Where do you store sensitive credentials?
A: In GitHub Secrets (Settings β Secrets and variables β Actions
).
Q3: How do you run multiple jobs in parallel?
A: Define multiple jobs under jobs:
without dependencies.
Q4: Whatβs the difference between workflow_dispatch
and push
?
A: push
runs automatically when code is pushed; workflow_dispatch
triggers manually via GitHub UI or API.
Q5: How do you reuse workflows across repositories?
A: Use the workflow_call
event to define reusable workflows.
π 6. Key Takeaways
YAML is your automation recipe.
Always store sensitive values in Secrets.
Separate build, test, and deploy steps.
Integrate GitHub Actions with AWS, Docker, or Kubernetes for real deployments.
π» GitHub Repository: DevOps Interview Preparation
π Previous Post: Day 10 β Jenkins Git Trigger Pipeline
#DevOps #GitHubActions #CI_CD #Automation #YAML #InterviewPreparation #LearningInPublic #90DaysOfDevOps #GitHub
Subscribe to my newsletter
Read articles from Tathagat Gaikwad directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
