C.W.K.
Stream
Lesson 03 of 08 · published

GitHub Actions — workflow, job, step

~12 min · yaml, github-actions, ci

Level 0평문
0 XP0/64 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

CI 가 되는 YAML

GitHub Actions workflow 가 .github/workflows/<name>.yaml 에 살아. 언제 (event), 어디서 (runner), 무엇을 (step) 실행 선언. 세 중첩 단계: workflow → jobs → steps.

골격

  • on: — 트리거 event. push, pull_request, workflow_dispatch (수동), schedule (cron), workflow_call (재사용).
  • jobs: — 기본으로 병렬 실행되는 이름 붙은 job. 각 job 이 runs-on: runner 고름.
  • steps: — job 안 순서 있는 리스트. 각 step 은 uses: (게시된 액션) 또는 run: (shell 명령).

Secret 과 권한

Secret 은 리포 또는 org 단계; ${{ secrets.NAME }} 로 참조. 기본 GITHUB_TOKEN 이 2023 년부터 contents 권한 read-only; write 필요하면 (tag push, release 생성) job 에 permissions: contents: write 선언.

'액션을 SHA 로 pin' 규칙: uses: actions/checkout@v4 가 v4 의 움직이는 tag 추적. compromise 된 maintainer 가 v4 아래 악성 코드 출시할 수 있고 CI 가 실행. 공급망 안전을 위해 SHA 로 pin: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11. Dependabot 이 자동 업데이트.

Code

최소 CI workflow·yaml
name: ci
on:
  push:
    branches: [main]
  pull_request:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.12'
      - run: pip install -e '.[dev]'
      - run: pytest -q
Matrix 빌드 (다른 param 으로 같은 job N 번)·yaml
jobs:
  test:
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest]
        python: ['3.10', '3.11', '3.12']
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python }}
      - run: pip install -e .
      - run: pytest
다른 job 에 의존 + artifact 업로드·yaml
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm run build
      - uses: actions/upload-artifact@v4
        with:
          name: dist
          path: dist/

  deploy:
    needs: build           # build 기다림
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v4
        with:
          name: dist
          path: dist/
      - run: echo deploying...
        env:
          API_TOKEN: ${{ secrets.API_TOKEN }}

External links

Exercise

리포의 workflow 하나 골라. 로컬에서 actionlint 실행 — 모든 에러 수정. 그 다음 uses: vendor/action@v3 적어도 하나를 SHA pin 으로 변환 (Dependabot 이 업데이트 유지). before/after diff, 공급망 footprint 줄어든 거 봐.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.