Workflow
Workflow
An automated work flow. GitHub Actions workflows. Defined in YAML.
Workflow
An automated work flow. GitHub Actions workflows. Defined in YAML.
A workflow is an automated flow of tasks defined to achieve a specific goal. In DevOps, it mainly refers to CI/CD pipelines, data processing pipelines, and infrastructure automation scenarios. GitHub Actions, Argo Workflows, and Apache Airflow are representative workflow engines.
A workflow consists of triggers, jobs, and steps. A trigger is an event that starts the workflow (push, schedule, webhook), a job is a unit of work that runs independently, and a step is an individual command within a job. You can define dependencies between jobs and conditional execution.
Declarative definition is the key. When you define a workflow in YAML, JSON, or a DSL, the engine manages its execution. State management, retries, parallel execution, and logging are handled automatically, so you do not need to implement complex orchestration logic yourself.
In practice, workflows are used to automate build-test-deploy when code is pushed, to run regular data processing (ETL), and for infrastructure provisioning. Managing workflows as code (Workflow as Code) makes version control, review, and reuse possible.
# GitHub Actions CI/CD μν¬νλ‘μ° μμ
# .github/workflows/ci-cd.yml
name: CI/CD Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
# μλ μ€ν κ°λ₯
workflow_dispatch:
inputs:
environment:
description: 'λ°°ν¬ νκ²½'
required: true
default: 'staging'
type: choice
options:
- staging
- production
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
# 1λ¨κ³: λ¦°νΈ λ° νμ
체ν¬
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run ESLint
run: npm run lint
- name: Run TypeScript check
run: npm run type-check
# 2λ¨κ³: ν
μ€νΈ (λ¦°νΈμ λ³λ ¬ μ€ν)
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test -- --coverage
env:
DATABASE_URL: postgresql://postgres:test@localhost:5432/test
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
# 3λ¨κ³: λΉλ (λ¦°νΈ, ν
μ€νΈ μλ£ ν)
build:
needs: [lint, test]
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
image-tag: ${{ steps.meta.outputs.tags }}
steps:
- uses: actions/checkout@v4
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,prefix=
type=ref,event=branch
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
# 4λ¨κ³: λ°°ν¬ (main λΈλμΉλ§)
deploy:
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment:
name: production
url: https://myapp.example.com
steps:
- name: Deploy to Kubernetes
uses: azure/k8s-deploy@v4
with:
action: deploy
manifests: k8s/
images: ${{ needs.build.outputs.image-tag }}
- name: Notify Slack
uses: slackapi/slack-github-action@v1
with:
payload: |
{
"text": "Deployed ${{ github.sha }} to production"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
Senior: "We're running tests manually for every PR, but if you create a GitHub Actions workflow, it runs automatically on every push."
Junior: "Can we block merging if the tests don't pass?"
Senior: "Yes, if you set required status checks in the Branch Protection Rule, the merge button is enabled only when the workflow succeeds."
Interviewer: "Please describe your experience designing CI/CD pipelines."
Candidate: "I set up a build-test-deploy workflow with GitHub Actions. I ran the lint and test jobs in parallel to shorten the time, and I set up the dependency with needs so that the build job runs only when both succeed. The deploy job runs only on pushes to the main branch, and I used environment approval to require approval before production deployment."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free
Reviewer: "You used npm install instead of npm ci in the workflow, but ci is more stable because it is based on the lock file."
Developer: "I'll switch to npm ci and also add the cache option of actions/setup-node to reduce dependency installation time."