본문으로 건너뛰기
김신건의 로그

[CI/CD] GitHub Actions: workflow, action, runner

· 수정 · 📖 약 1분 · 229자/단어 #github-actions #ci-cd #devops #automation
GitHub Actions, GHA, workflow, self-hosted runner, matrix build, reusable workflow, composite action

정의

GitHub Actions = GitHub 내장 CI/CD. YAML workflow + marketplace action. 2018 출시 → Travis CI 대체.

구조

flowchart TB
    Trigger[Trigger<br/>push, PR, schedule, ...] --> WF[Workflow]
    WF --> Job1["Job 1<br/>(runner)"]
    WF --> Job2[Job 2]
    Job1 --> Step1["Step 1 (action 또는 script)"]
    Job1 --> Step2[Step 2]

Workflow YAML

name: CI
on:
  push:
    branches: [main]
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node: [20, 22]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
          cache: npm
      - run: npm ci
      - run: npm run lint
      - run: npm test
      - run: npm run build

  deploy:
    needs: test
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read
    steps:
      - uses: actions/checkout@v4
      - uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: arn:aws:iam::123:role/gh-deploy
          aws-region: us-east-1
      - run: aws s3 sync ./dist s3://my-bucket

Trigger 종류

Trigger의미
pushbranch / tag push
pull_requestPR open / sync
schedulecron
workflow_dispatch수동 실행
workflow_call다른 workflow 가 호출
repository_dispatch외부 API
releaserelease published
issue_commentcomment

Runner

종류의미
GitHub-hostedUbuntu/Windows/macOS, 매번 fresh
Self-hosted자체 VM, 빠름, 보안 책임
Larger runnersGitHub-hosted 의 강한 사양
ARC (Actions Runner Controller)K8s 위 self-hosted

Marketplace Action

- uses: actions/checkout@v4
- uses: actions/setup-python@v5
  with: { python-version: '3.13' }
- uses: docker/build-push-action@v6
- uses: actions/cache@v4
- uses: aws-actions/configure-aws-credentials@v4

OIDC + AWS (long-term key 없이)

자세한 건 aws-sts-assume-role 의 OIDC.

permissions:
  id-token: write
steps:
  - uses: aws-actions/configure-aws-credentials@v4
    with:
      role-to-assume: arn:aws:iam::123:role/gh-deploy
      aws-region: us-east-1

Matrix Build

strategy:
  fail-fast: false
  matrix:
    os: [ubuntu-latest, macos-latest]
    node: [20, 22]
    include:
      - os: ubuntu-latest
        node: 22
        coverage: true
    exclude:
      - os: macos-latest
        node: 20

N × M 조합 자동 실행.

Reusable Workflow

# .github/workflows/reusable-deploy.yml
on:
  workflow_call:
    inputs:
      env:
        required: true
        type: string

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps: [...]
# 호출
jobs:
  call:
    uses: ./.github/workflows/reusable-deploy.yml
    with: { env: prod }

Composite Action

action.yml:

name: 'Setup Node + cache'
runs:
  using: 'composite'
  steps:
    - uses: actions/setup-node@v4
    - uses: actions/cache@v4
    - run: npm ci
      shell: bash

보안

✓ PR fork 의 secret 노출 방지 (pull_request_target 주의)
✓ Action SHA pinning (uses: actions/checkout@<sha>)
✓ OIDC (long-term key 회피)
✓ Permissions 최소화 (permissions: 명시)
✓ Secrets 환경 분리 (environment)

흔한 함정

WARNING

  1. pull_request_target + checkout PR code = 코드 인젝션 가능. PR 의 코드는 pull_request 만.
  2. Long-term AWS key = 누출 위험. OIDC 권장.
  3. uses: action@main = action 변경에 영향 받음. SHA pinning.
  4. Self-hosted runner 의 fork PR = 임의 코드 실행. fork 차단 또는 GitHub-hosted.

관련 위키

이 글의 용어 (4개)
[AWS] STS / AssumeRole: 임시 자격, cross-accountcloud
정의 STS (Security Token Service) = 임시 자격 증명 발급. short-lived (15분-12시간) credentials. 5가지 API | API | …
[Container] Docker: image, layer, registryvirtualization
정의 Docker = 컨테이너 빌드 + 실행 + 배포 의 표준 도구. 2013 출시 → 컨테이너 시대 의 시작. 현재는 OCI 표준 으로 진화 ( , , 등 호환). Layere…
[GitOps] 패턴: 단일 vs 다중 repo, environment promotiondevops
GitOps 4가지 원칙 (OpenGitOps) 1. Declarative: 시스템 원하는 상태 가 선언적 (YAML). 2. Versioned and Immutable: Git…
[GitOps] ArgoCD: Kubernetes GitOpsdevops
정의 ArgoCD = Kubernetes 의 GitOps 컨트롤러. Git 리포지토리의 manifest 가 source of truth → cluster 가 자동 동기화. Git…

💬 댓글

사이트 검색 / 명령어

검색

스크롤 = 확대/축소 · 드래그 = 이동 · 0 = 원래 크기 · ESC = 닫기