C.W.K.
Stream
Lesson 02 of 14 · published

조건 실행 — if:

~11 min · if, conditional, expressions

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

해당 안 되는 작업 skip

Job 과 step 둘 다 if: expression 지원. Expression 이 truthy / falsy 평가; falsy 면 skip.

흔한 패턴:

  • Branch 별: if: github.ref == 'refs/heads/main'
  • Tag 별: if: startsWith(github.ref, 'refs/tags/v')
  • Event 별: if: github.event_name == 'push'
  • Label 별: if: contains(github.event.pull_request.labels.*.name, 'deploy')
  • Path 별: 대신 workflow level paths: 필터 써.
  • 상태 별: if: failure(), if: cancelled(), if: always()

Skipped vs failed

False 평가되는 if:failed 아니라 skipped 생성. Skipped job 은 workflow 실패 안 시켜. Branch protection 활성화면 required status check 도 만족 안 시킴 — required check 를 조건 뒤에 gate 하지 마, 안 그러면 feature branch PR 이 hang.

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

Repo 의 required status check audit. 각각, 하위 workflow 가 흔한 branch 유형에 skip 하지 않는지 검증. if: 있어도 새 branch 의 PR 도 check 가 점등돼야 함.

Progress

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

댓글 0

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

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