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