GitHub Actions

Hyun·2024년 10월 29일

frontend 필요 지식

목록 보기
6/9
post-thumbnail

GitHub Actions

github에서 제공하는 자동화된 작업 관리도구

코드를 빌드하거나 테스트하고 배포하는 등의 작업을 자동으로 수행할 수 있게 해준다.
(반복적인 작업을 자동화해서 작업의 효율성을높이고 오류를 줄이는데 크게 도움이 된다.)

GitHub Actions 의 역할과 중요성

  • 자동화된 workflow : github actions에서는 특정 조건(commit, push 등등) 이 충족되면 자동으로 워크플로우가 실행된다.

  • CI/CD 통합 : 지속적인 통합 (Continuous integration) / 지속적인 배포 (Continuous Deployment) 를 쉽게 구현이 가능하다. 코드가 변경될 때 마다 테스트와 빌드 과정을 자동으로 실행한다.

  • 시간과 인력 오류 감소: 개발자들이 수동으로 해야하는 작업들을 줄여줘서 일관성을 유지하고 작업 효율성이 높아진다.

Github Action Quick Start

공식문서에서 제공하는 QuickStart 를 보고 따라해봤다.

  1. github action을 실행할 repository에 workflow 폴더를 만들고 그 안에 yaml 또는 yml 형식의 파일을 작성.
name: GitHub Actions Demo
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
on: [push]
jobs:
  Explore-GitHub-Actions:
    runs-on: ubuntu-latest
    steps:
      - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
      - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
      - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
      - name: Check out repository code
        uses: actions/checkout@v4
      - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
      - run: echo "🖥️ The workflow is now ready to test your code on the runner."
      - name: List files in the repository
        run: |
          ls ${{ github.workspace }}
      - run: echo "🍏 This job's status is ${{ job.status }}."

기본으로 제공하는 github action yml 형식이다.

  • runs-on : 해당 job을 어떤 OS에서 실행할 것인지
  • steps : job이 가질 수 있는 동작 나열. 각각의 step은 독립적인 프로세스를 가진다.
    • uses: 해당 step에서 사용할 액션.
    • name: step 이름
    • run: job에 할당된 컴퓨팅 자원의 shell을 이용해 커맨드 라인을 실행
      (node.js의 경우 npm pakaage의 script를 구동)

추가로

  • env: 해당 job에서 사용할 환경변수를 key/value의 형태로 설정
  • strategy : 여러 환경에서의 테스트/배포를 위해서 빌드 matrix를 구성
  • with : 해당 action에 의해 정의되는 input 파라미터. key/value 쌍으로 구성.

간단한 예시

# .github/workflows/test.yml
name: Run Tests

on: 
  pull_request:
    branches: [ main ]

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout repository
      uses: actions/checkout@v2

    - name: Set up Node.js
      uses: actions/setup-node@v2
      with:
        node-version: '14'

    - name: Install dependencies
      run: npm install

    - name: Run tests
      run: npm test

GitHub Action의 장점

  • 쉽고 직관적인 설정 : GitHub 리포지토리에서 바로 설정 가능하며, YAML 파일로 직관적으로 구성

  • 커뮤니티 액션 활용 : GitHub Actions는 다양한 오픈소스 액션을 제공합니다. 예를 들어, 테스트 실행, 배포, 코드 분석 등 다양한 액션을 쉽게 찾아 사용

  • 빠른 피드백 루프 : 코드 변경 시마다 자동으로 작업이 실행되기 때문에, 코드 품질 유지에 유리

0개의 댓글