Github Actions

Github Actions

νŠΉμ • μ΄λ²€νŠΈκ°€ λ°œμƒν–ˆμ„ λ•Œ μ›ν•˜λŠ” μž‘μ—…μ„ μžλ™μœΌλ‘œ μˆ˜ν–‰ν•˜κ²Œ λ§Œλ“€μ–΄μ£ΌλŠ” 도ꡬ

  • ν”„λ‘œμ νŠΈ 루트 κ²½λ‘œμ— .github/workflows/ 디렉토리λ₯Ό μƒμ„±ν•˜κ³  .yml νŒŒμΌμ„ λ§Œλ“€μ–΄ μ›Œν¬ν”Œλ‘œμš°λ₯Ό μ •μ˜ν•œλ‹€.

// workflows 이름
name: CI

// workflowsλ₯Ό μ‹€ν–‰μ‹œν‚¬ 트리거
// 각 이벀트 ν•˜μœ„μ— μ§€μ •ν•˜λŠ” 상세 섀정은 AND μ—°μ‚°μžλ₯Ό μ‚¬μš©ν•˜μ—¬ 쑰건이 μΆ©μ‘±λ˜μ–΄μ•Ό 싀행됨
on:
  push:
    branches:
      - main
  pull_request:
      types: [opened, synchronize, reopened]

jobs:
  build:
   // job을 μ‹€ν–‰μ‹œν‚¬ ν™˜κ²½μ„ μ§€μ •
    runs-on: ubuntu-latest 
    steps:
      // usesλŠ” 이미 λ§Œλ“€μ–΄λ‘” Action을 μ‚¬μš©ν•˜κ² λ‹€λŠ” 것
      // checkout은 'runs-on'에 λͺ…μ‹œν•œ μ›Œν¬ν”Œλ‘œμš° μ‹€ν–‰ ν™˜κ²½μ—μ„œ ν•΄λ‹Ή ν”„λ‘œμ νŠΈλ₯Ό λΆˆλŸ¬μ˜€λŠ” λ™μž‘μ„ 의미
      // μ›Œν¬ν”Œλ‘œμš°μ˜ 첫 번째 λ‹¨κ³„μ—μ„œ μ‚¬μš©λ˜λ©° κΌ­ ν•„μš”ν•˜λ‹€.
      - name: Checkout
        uses: actions/checkout@v3
     // node.js ν™˜κ²½ μ„ΈνŒ…
      - name: Set up Node.js
        uses: actions/setup-node@v3
        // with을 μ‚¬μš©ν•˜μ—¬ μ•‘μ…˜μ— κ°’ 전달
        with:
          node-version: '16'
          // 쒅속성을 κ΄€λ¦¬ν•˜κ³  캐싱할 νŒ¨ν‚€μ§€λ§€λ‹ˆμ € μ§€μ •
          cache: npm
      // 쒅속성 μ„€μΉ˜
      - name: Install dependencies
      // run은 package.json에 μ •μ˜ν•œ 슀크립트 λͺ…λ Ήμ–΄λ₯Ό μ‹€ν–‰μ‹œν‚€κΈ° μœ„ν•΄ μ‚¬μš©λ¨
        run: npm ci
      - name: Lint
        run: npx eslint --ext .js,.jsx,.ts,.tsx .
      - name: Compile to check syntax
        run: npx tsc --noEmit
      - name: Run tests
        run: npx jest --verbose --coverage
      - name: Build
        run: npm run build
      - name: Run E2E test
        run: HEADLESS=true npm run ci

Events

When - μˆ˜ν–‰ν•  μž‘μ—…μ΄ νŠΈλ¦¬κ±°λ˜λŠ” 상황

  • githubμ—μ„œ λ°œμƒλ˜λŠ” λŒ€λΆ€λΆ„μ˜ 이벀트λ₯Ό μ§€μ •ν•  수 μžˆλ‹€.

    • ex) push, merge, pr 생성 λ“±

  • μ΄λ²€νŠΈκ°€ 호좜되면 μ›Œν¬ν”Œλ‘œμš°κ°€ μ‹€ν–‰λœλ‹€.

Workflow

νŠΉμ • μ΄λ²€νŠΈκ°€ λ°œμƒν–ˆμ„ λ•Œ μ‹€ν–‰λ˜λŠ” μž‘μ—…λ“€μ˜ μ§‘ν•©

  • ν•˜λ‚˜μ˜ workflowsλŠ” ν•˜λ‚˜ λ˜λŠ” λ‹€μˆ˜μ˜ job을 κ°–λŠ”λ‹€.

Job

μ›Œν¬ν”Œλ‘œμš° λ‚΄μ—μ„œ μ‹€ν–‰λ˜λŠ” 독립적인 μž‘μ—…

  • 기본적으둜 λ³‘λ ¬λ‘œ μ‹€ν–‰λœλ‹€.

  • job은 ν•˜λ‚˜ μ΄μƒμ˜ step으둜 κ΅¬μ„±λœλ‹€.

  • shell script λ˜λŠ” npm λͺ…λ Ήμ–΄ μž‘μ„± κ°€λŠ₯

Actions

νŠΉμ • μž‘μ—…, λͺ…λ Ήμ–΄λ₯Ό μ‹€ν–‰ν•˜λŠ” λ‹¨μœ„

  • 자주 μˆ˜ν–‰λ˜λŠ” μž‘μ—…μ„ μ•‘μ…˜μœΌλ‘œ μ •μ˜ν•˜μ—¬ μž¬μ‚¬μš©μ„±μ„ λ†’νžŒλ‹€.

  • Github actions μ—λŠ” 사전에 μ •μ˜λœ λ‹€μ–‘ν•œ μ•‘μ…˜λ“€μ„ μ œκ³΅ν•œλ‹€.

Composite Action

μ—¬λŸ¬ 개의 단일 μ•‘μ…˜μœΌλ‘œ κ΅¬μ„±λ˜μ–΄ 더 λ³΅μž‘ν•œ μž‘μ—…μ„ μˆ˜ν–‰ν•˜κΈ° μœ„ν•΄ μ‚¬μš©λœλ‹€.

  • Composite Action은 μ›Œν¬ν”Œλ‘œμš°μ™€ λ…λ¦½μ μœΌλ‘œ κ΄€λ¦¬ν•˜κΈ° μœ„ν•΄ λ³„λ„μ˜ 디렉토리λ₯Ό μƒμ„±ν•˜μ—¬ κ΄€λ¦¬ν•˜μž.

  • Composit Actionλ§ˆλ‹€ κ°œλ³„ 폴더λ₯Ό λ§Œλ“€κ³  action.yml νŒŒμΌμ„ μƒμ„±ν•˜μ—¬ μ •μ˜ν•œλ‹€.

  • using: 'composite' 둜 μ„ μ–Έν•΄μ•Ό ν•œλ‹€.

  • ν•΄λ‹Ή μ•‘μ…˜μ„ μ‚¬μš©ν•˜λŠ” κ³³μ—μ„œ usesλ₯Ό 톡해 μ•‘μ…˜μ˜ μƒλŒ€ 경둜λ₯Ό μ§€μ •ν•˜μ—¬ μ‚¬μš©ν•œλ‹€.

    • uses: ./.github/actions/yarn-install
.github/actions/yarn-install/action.yml
name: 'Monorepo install (yarn)'
description: 'Run yarn install'

runs:
  using: 'composite'

  steps:
    - name: Expose yarn config as "$GITHUB_OUTPUT"
      id: yarn-config
      shell: bash
      // λ’€μ—μ„œ μ‚¬μš©ν•˜κΈ° μœ„ν•΄ 캐쉬폴더λ₯Ό λ³€μˆ˜μ— λ‹΄μ•„ output에 값을 내보낸닀
      run: |
        echo "CACHE_FOLDER=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT

    - name: Restore yarn cache
      uses: actions/cache@v3
      id: yarn-download-cache
      with:
        path: ${{ steps.yarn-config.outputs.CACHE_FOLDER }}
        key: yarn-download-cache-${{ hashFiles('yarn.lock') }}
        restore-keys: |
          yarn-download-cache-

    - name: Restore yarn install state
      id: yarn-install-state-cache
      uses: actions/cache@v3
      with:
        path: .yarn/ci-cache/
        key: ${{ runner.os }}-yarn-install-state-cache-${{ hashFiles('yarn.lock', '.yarnrc.yml') }}

    - name: Install dependencies
      shell: bash
      run: |
        yarn install --immutable --inline-builds
      env:
        YARN_ENABLE_GLOBAL_CACHE: 'false'
        YARN_INSTALL_STATE_PATH: .yarn/ci-cache/install-state.gz # Very small speedup when lock does not change

Runner

μž‘μ—…μ„ μˆ˜ν–‰ν•  μ‹€ν–‰ ν™˜κ²½μœΌλ‘œ githubμ—μ„œ ν˜ΈμŠ€νŒ…ν•˜μ—¬ μ›Œν¬ν”Œλ‘œμš°λ₯Ό μ‹€ν–‰μ‹œν‚€κΈ° μœ„ν•΄ μ‚¬μš©λœλ‹€.

  • job을 μ‹€ν–‰ν•˜λŠ” 것이 λ°”λ‘œ Runner,

  • job은 독립적인 Runner Containerμ—μ„œ μ‹€ν–‰λœλ‹€.

Last updated