본문 바로가기
C.W.K.
Stream
Lesson 10 of 12 · published

컨텍스트와 표현식

~13 min · context, expressions, templating

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

${{ ... }} 가 템플릿 엔진

표현식 문법인 ${{ ... }}는 YAML 문자열 안에서 평가돼. 워크플로의 조건을 걸거나 값을 조회하고, 문자열을 조작할 때 쓰는 방법이야.

컨텍스트들

  • github — 저장소, ref, sha, actor, event, 워크플로 정보.
  • env — 현재 범위의 환경 변수.
  • vars — 저장소, 조직, 환경 변수.
  • secrets — 저장소, 조직, 환경 비밀값.
  • job — 현재 작업 정보.
  • steps — 이 작업에서 이전 단계의 출력값.
  • matrix — 현재 매트릭스 셀의 값.
  • needsneeds:에 지정한 작업의 출력값.
  • inputsworkflow_dispatchworkflow_call의 입력값.
  • runner — 러너 정보(OS, 아키텍처, 임시 디렉터리).

연산자와 함수

  • 비교: ==, !=, <, <=, >, >=.
  • 논리: &&, ||, !.
  • 자주 쓰는 함수: contains(haystack, needle), startsWith(s, prefix), endsWith(s, suffix), format('hello {0}', name), fromJSON(s), toJSON(obj), hashFiles('**/lockfile').
  • 상태 확인: success(), failure(), cancelled(), always().

Code

흔한 조건 표현식·yaml
      # Run only on main
      - if: github.ref == 'refs/heads/main'
        run: ./deploy.sh

      # Run only on tag pushes
      - if: startsWith(github.ref, 'refs/tags/v')
        run: ./release.sh

      # Run only when label 'deploy' is on the PR
      - if: github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'deploy')
        run: ./preview-deploy.sh

      # Always run cleanup, even on failure
      - if: always()
        run: ./cleanup.sh

      # Use a previous step's output
      - id: meta
        run: echo "sha=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
      - run: echo "Built ${{ steps.meta.outputs.sha }}"

External links

Exercise

배포 작업이 있는 워크플로를 하나 골라봐. github.ref == 'refs/heads/main' && github.event_name == 'push'일 때만 배포가 돌아가도록 if: 가드를 추가해. PR에서는 건너뛰는지도 확인해.

Progress

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

댓글 0

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

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