Github action 정리

2021-05-21
  • DevOps
  • Git

Github action을 통한 Spring boot 자동 deploy

# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle

name: Gradle Package

# 1)
on:
  release:
    types: [created]

# 2)
jobs:
  build:

    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

    steps:
    # 3)
    - uses: actions/checkout@v2
    - name: Set up JDK 11
      uses: actions/setup-java@v2
      with:
        java-version: '11'
        distribution: 'adopt'
        server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
        settings-path: ${{ github.workspace }} # location for the settings.xml file

    - name: Build with Gradle
      run: gradle build

    # The USERNAME and TOKEN need to correspond to the credentials environment variables used in
    # the publishing section of your build.gradle
    - name: Publish to GitHub Packages
      run: gradle publish
      env:
        USERNAME: ${{ github.actor }}
        TOKEN: ${{ secrets.GITHUB_TOKEN }}

1) on

1-1) 특정 브랜치에 push가 진행되면 실행

on:
  push:
    branches:
    - main
    - release/*

1-2) PR이 실행되면 실행

on:
    pull_request:
     branches:
     - main

1-3) 특정 시점에 cron으로 실행

on:
  schedule:
    branches:
    - cron: "0 0 * * * *"

1-4) 수동으로 실행

on:
  workflow_dispatch:

2) jobs

job은 같은 runner(workflow)위에서 실행되는 일련의 과정들이다. 기본적으로 여러 job들이 있는 workflow는 병렬로 job을 실행한다. 하지만 필요하다면 job을 순차적으로 실행하도록 설정할 수 있는데, 빌드테스트, 순차적인 job 두개로 구성된 workflow가 있다고 가정했을 때, 테스트 job은 빌드 job 상태에 의존한다. 만약에 빌드에 실패하면 테스트 역시 run 되지 않는 것이다.

3) uses: actions/checkout@v2

git checkout 실행

출처

Profile picture

2yeseul

트리플에서 백엔드 개발을 맡고 있습니다. 무한 삽질을 기록합니다. ⚒️