C.W.K.
Stream
Lesson 10 of 12 · published

Context 와 expression

~13 min · context, expressions, templating

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

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

Expression syntax ${{ ... }} 는 YAML 문자열 안에서 평가되고, workflow 의 조건/조회/문자열 조작 방법이야.

Context 들

  • github — repo, ref, sha, actor, event, workflow 정보.
  • env — 현재 scope 의 env var.
  • vars — repo/org/env 변수.
  • secrets — repo/org/env secret.
  • job — 현재 job 정보.
  • steps — 이 job 의 이전 step 출력.
  • matrix — 현재 matrix cell 의 값.
  • needsneeds: job 의 출력.
  • inputsworkflow_dispatchworkflow_call 의 입력.
  • runner — runner 정보 (OS, arch, temp dir).

연산자와 함수

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

Code

흔한 조건 expression·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

Deploy job 가진 workflow 골라. github.ref == 'refs/heads/main' && github.event_name == 'push' 일 때만 deploy 도는 if: 가드 추가. PR 에선 skip 되는지 확인.

Progress

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

댓글 0

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

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