월루를 꿈꾸는 대학생

[ Github Action] 이해 및 개념 정리 1 본문

Programing/Github-Action

[ Github Action] 이해 및 개념 정리 1

하즈시 2023. 5. 22. 19:42
728x90

깃허브 액션의 이해 

- ci / cd 플랫폼 

- 리포지토리에 이벤트 발생시 워크플로우를 실행시켜서 배포가능 

 

깃허브 액션의 컴포넌트 

- 리포지토리에서 어떤 이벤트가 발생하면 워크플로우 실행됨

- 순차적 혹은 병렬로 실행가능 

https://docs.github.com/ko/actions/learn-github-actions/understanding-github-actions

워크플로

- 하나 이상 작업을 실행하는 프로세스 

- YAML 

- 이벤트에 의해서 수동 혹은 자동으로 실행 

- .github/workflows 디렉토리에 정의 

 

이벤트

- 리포지토리의 특정 활동 (트리거) ex_ 풀리퀘스트 , 이슈 열기 , 커밋

 

- 워크플로의 집합

-  같은 러너에서 실행하기 때문에 각 단계끼리는 데이터 공유 가능 

-  디폴트로는 종속성 없음 

- 종속성 있는 작업의 경우 동기적으로 실행 

 

액션

-  복잡하지만 자주 반복되는 작업 수행 

- 워크플로 파일에 중복을 제거 가능 

- 레포지토리 가져오기 , 도구 체인 설정 , 인증 설정 가능 

 

러너

- 워크플로를 실행시키는 서버 

- 한 번에 하나의 작업만 가능 

 


1. 리포지토리에 .github/workflows/ 만들기 

2. learn-github-actions.yml 파일 만들기 

name: learn-github-actions
run-name: ${{ github.actor }} is learning GitHub Actions
on: [push]
jobs:
  check-bats-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: "14"
      - run: npm install -g bats
      - run: bats -v

3. 커밋이랑 푸쉬 실행 

 

레포지토리에 변경사항 푸시할 때 마다 워크플로 실행 됨 

 

 

 


작업 찾기 및 사용자 지정 

 

작업 : 워크플로를 구성하는 요소 

동일 리포지토리에서 작업 추가하는 경우 경로 설정

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # This step checks out a copy of your repository.
      - uses: actions/checkout@v3
      # This step references the directory that contains the action.
      - uses: ./.github/actions/hello-world-action

 

다른 리포지토리 작업 추가

jobs:
  my_first_job:
    steps:
      - name: My first step
        uses: actions/setup-node@v3

 

작업에서 입출력 사용

- input : 값 입력 

- output : 값 출력

name: "Example"
description: "Receives file and generates output"
inputs:
  file-path: # id of input
    description: "Path to test script"
    required: true
    default: "test-file.js"
outputs:
  results-file: # id of output
    description: "Path to results file"

 


필수 기능 

 

변수 사용 

- env: 환경 변수 설정 

jobs:
  example-job:
      steps:
        - name: Connect to PostgreSQL
          run: node client.js
          env:
            POSTGRES_HOST: postgres
            POSTGRES_PORT: 5432

 

스크립트 추가 

- 쉘 명령어 실행 가능 

jobs:
  example-job:
    steps:
      - name: Run build script
        run: ./.github/scripts/build.sh
        shell: bash

 

작업 간 데이터 공유

- 동일 워크플로의 다른 작업과 공유하는 파일 생성 혹은 참조 파일 저장하는 경우 

 

아티팩트 

- 코드 빌드 후 테스트 할 때 생성되는 파일  ex_ 이진파일, 로그 , 스샷 등등 

- 실행 내 모든 작업은 아티팩트 쓰기 액세스 권한 있음

 

아티펙트로 만든 output-log-file 을 뒤에 있는 워크플로에서 참조 가능 

jobs:
  example-job:
    name: Save output
    steps:
      - shell: bash
        run: |
          expr 1 + 1 > output.log
      - name: Upload output file
        uses: actions/upload-artifact@v3
        with:
          name: output-log-file
          path: output.log
jobs:
  example-job:
    steps:
      - name: Download a single artifact
        uses: actions/download-artifact@v3
        with:
          name: output-log-file

 

 

https://tech.kakaoenterprise.com/180

 

워크서버개발팀의 GitHub Actions 적용기

시작하며 안녕하세요. 카카오엔터프라이즈에서 카카오워크의 서버 개발을 담당하고 있는 워크서버개발파트의 Dori(김동환)입니다. 제가 소속된 워크서버개발파트는 작년 상반기 까지 CI(Continuous

tech.kakaoenterprise.com

https://docs.github.com/ko/actions

 

728x90