설치&설정 관련

github action으로 jekyll 빌드와 배포 하기

lahuman 2024. 6. 12. 16:11
728x90

github action으로 jekyll 빌드와 배포 하기

다음의 단계로 배포 처리를 합니다.

설정 > 개인 토큰 발급

  1. 프로필 사진을 클릭 후 Settings 선택
  2. 아래 메뉴에 Developer settings 선택
  3. Personal access tokens 선택
  4. Create New tokens 선택 후 tokens (classic) 선택

  1. 이름을 설정하고, Expiration을 No Expiration으로 설정
    • 만료일을 설정 시 추후 변경 필요함
  2. Select scopes에서 repo 선택
    • repository에 읽고 쓰고 등의 처리를 위해 필요
  3. Generated Token 버튼 클릭으로 토큰 생성

  1. 토큰 복사
    • 토큰 값은 다시 확인이 불가하니 꼭 잘 저장 해야 함

  1. 원천 소스가 되는 Repository로 이동
  2. Secrets and variables 선택
  3. Secrets 탭에 New Repository Secret 선택
  4. Name을 JEKYLL_MOON로 만들고 Secret에 생성된 토큰 값을 붙여 넣음

  1. root에 .github/workflows 디렉토리를 생성후 jekyll_build-and_push.yml 파일을 생성
name: Jekyll build and deploy

on:
  push:
    branches:
      - master

jobs:
  build_and_deploy:
    runs-on: ubuntu-latest

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

    - name: Set up Node
      uses: actions/setup-node@v3
      with:
        node-version: 16.14.2
        
    - name: Set up Ruby
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: 2.7 # 3.x 로 설정시 오류 발생하여 2.7로 고정

    - name: Cache Ruby gems
      uses: actions/cache@v2
      with:
        path: vendor/bundle
        key: $-gems-$
        restore-keys: |
          $-gems-
    - name: Install dependencies
      run: |
        bundle config path vendor/bundle
        bundle install --jobs 4 --retry 3
    - name: Build Jekyll site
      run: bundle exec jekyll build

    - name: Deploy to target repository
      uses: peaceiris/actions-gh-pages@v3
      with:
        personal_token: $ # 생성한 token 정보 설정
        publish_dir: ./_site
        user_name: 'github-actions[bot]'
        user_email: 'github-actions[bot]@users.noreply.github.com'
        publish_branch: master # 대상 repository branch 정보
        external_repository: 'lahuman/lahuman.github.io' # 대상 repository

파일 저장이 완료 되면 아래와 같이 github action이 실행됩니다.

2017년부터 운영 중이던 github 블로그의 빌드와 배포를 github action을 이용해서 처리 했습니다.

알고 있었는데, 시도하는게 어려웠습니다.

오늘은 뒤로 후퇴하는게 아닌 앞으로 한 걸음 내딛었다고 생각되네요.

참고자료

728x90