OpenSource

GitHub Actions 활용해보기

아르비스 2021. 7. 6. 15:51

Jenkins만 쓰다가 간단한 web build tool을 다보니. 

Github에서 Build tool을 제공해줌.

 

장점: 간단함.

단점: 디버깅은 어렵다..

 

사용방법

# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Checkout code
        uses: actions/checkout@v2
        
      # 실행 속도를 빠르게 하기 위해 설치된 Node 모듈을 캐시하도록 설정합니다.
      - name: Cache node modules
        uses: actions/cache@v2
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-
            
      # Node 15.x를 사용합니다.
      - name: Use Node.js
        uses: actions/setup-node@v1
        with:
          node-version: '15.x'
          
      # 모듈을 설치합니다.
      - name: Install packages
        run: npm install
        
      # 모듈 빌드
      - name: Install build
        run: npm run build

      # Runs a single command using the runners shell
      - name: Run a one-line script
        run: echo Build success!
        
      # Runs package dist
      - name: Run tar package 
        run: tar -zcvf order-front-wd.tar ./dist
        
      # CP /dist to /Docs
      - name: Run a one-line script
        run: cp -R ./dist/ ./docs/

      # Push binary to git
      - name: Commit binary to git
        run: |
          date > generated.txt
          git config user.name sncap
          git config user.email sncap7@gmail.com
          git add ./dist/
          git add ./docs/
          git add ./order-front-wd.tar
          git commit -m "add generated binary"
          git push
          echo Commit Binary to git