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

조건 실행 — if:

~11 min · if, conditional, expressions

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

건너뛸 작업 처리하기

작업과 단계 모두 if: 표현식을 지원해. 이 표현식을 참거짓으로 평가해서 거짓이면 해당 작업이나 단계를 건너뛴다.

자주 쓰는 패턴들을 살펴보자:

  • 브랜치별: if: github.ref == 'refs/heads/main'
  • 태그별: if: startsWith(github.ref, 'refs/tags/v')
  • 이벤트별: if: github.event_name == 'push'
  • 레이블별: if: contains(github.event.pull_request.labels.*.name, 'deploy')
  • 경로별: 대신 워크플로 수준에서 paths: 필터를 써.
  • 상태별: if: failure(), if: cancelled(), if: always()

건너뛴 상태와 실패 상태 구분하기

if:가 거짓으로 평가되면 실패가 아니라 건너뜀 상태가 돼. 건너뛴 작업은 워크플로를 실패로 만들지 않아. 하지만 브랜치 보호를 켜두면 필수 상태 확인도 만족시키지 못해. 필수 확인을 조건 뒤에 배치하지 마. 그러면 기능 브랜치 풀 리퀘스트가 멈춰버려.

Code

흔한 조건문·yaml
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: pytest -q

  deploy-staging:
    needs: test
    if: github.ref == 'refs/heads/main' && github.event_name == 'push'
    runs-on: ubuntu-latest
    environment: staging
    steps:
      - run: ./deploy.sh staging

  deploy-prod:
    needs: deploy-staging
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    environment: production
    steps:
      - run: ./deploy.sh prod

  cleanup:
    needs: [test, deploy-staging, deploy-prod]
    if: always()
    runs-on: ubuntu-latest
    steps:
      - run: ./cleanup.sh

External links

Exercise

저장소의 필수 상태 확인을 점검해봐. 각 하위 워크플로가 흔한 브랜치 유형에서 건너뛰지 않는지 확인해. if:가 있더라도 새 브랜치의 풀 리퀘스트도 확인이 켜져야 해.

Progress

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

댓글 0

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

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