본문 바로가기
C.W.K.
Stream
Lesson 01 of 14 · published

Job 의존 — needs:

~11 min · needs, dag, ordering

Level 0견습생
0 XP0/101 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

needs:가 그리는 DAG

각 작업은 needs:로 0개 이상의 상위 작업을 선언할 수 있어. GitHub가 이 정보로 DAG를 만들고 위상 순서대로 작업을 실행하지. 서로 경로가 없는 작업들은 병렬로 돌아.

흔히 볼 수 있는 구조는 이렇게 생겼어:

  • 선형 — A → B → C. 각 작업이 이전 작업이 끝날 때까지 기다려.
  • Fan-out, 팬인 — A → [B, C, D] → E. B, C, D가 A 다음에 병렬로 실행되고, 그 다음 E가 셋 다 끝날 때까지 기다려.
  • 다이아몬드 — A → [B, C] → D. 빌드 후 (테스트, 린트) 후 배포하는 흐름에서 자주 써.
  • 분리된 체인 — 같은 워크플로 안에 있는 독립적인 파이프라인들이야.

실패 전파

기본적으로 needs:에 지정한 작업 중 하나라도 실패하거나 취소되면 그 작업은 건너뛰어(건너뛰기). 정리나 알림 작업이 상관없이 무조건 실행돼야 한다면 if: always()if: failure()로 재정의하면 돼.

Code

항상 실행되는 알림을 가진 다이아몬드 DAG·yaml
jobs:
  build:
    runs-on: ubuntu-latest
    steps: [{ uses: actions/checkout@v4 }, { run: ./build.sh }]

  test:
    needs: build
    runs-on: ubuntu-latest
    steps: [{ uses: actions/checkout@v4 }, { run: ./test.sh }]

  lint:
    needs: build
    runs-on: ubuntu-latest
    steps: [{ uses: actions/checkout@v4 }, { run: ./lint.sh }]

  deploy:
    needs: [test, lint]
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps: [{ uses: actions/checkout@v4 }, { run: ./deploy.sh }]

  notify:
    needs: [test, lint, deploy]
    if: always()       # runs even if upstream failed/skipped
    runs-on: ubuntu-latest
    steps:
      - run: ./notify-slack.sh "${{ needs.deploy.result }}"

External links

Exercise

직렬 단계를 가진 워크플로를 가져와서 다이아몬드 DAG으로 리팩토링해 봐: 빌드 → (테스트, 린트) → 배포. 실제 경과 시간이 얼마나 개선됐는지 재고 PR 설명에 문서화해.

Progress

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

댓글 0

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

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