GitHub Actions는 CI/CD(지속적인 통합 및 지속적인 배포)를 구현할 수 있는 GitHub의 기능으로, 자동화된 빌드, 테스트, 배포 작업을 처리할 수 있다
워크플로우는 자동화 작업을 정의한 YAML 파일이다.
.github/workflows/ 디렉터리 아래에 파일로 저장된다.
CI/CD 분리하는 방식
name: test every pr
on:
workflow_dispatch: # 수동 트리거 (GitHub에서 수동으로 실행 가능)
pull_request: # Pull Request 이벤트 발생 시 자동으로 실행
permissions:
contents: read # 저장소 내용을 읽을 수 있는 권한
pull-requests: read # PR에 대한 정보 읽을 수 있는 권한
jobs:
deploy:
runs-on: ubuntu-latest # 실행할 환경
steps:
- name: Checkout # 1. 코드 체크아웃
uses: actions/checkout@v3 # GitHub에서 코드 가져오기
- name: setup jdk # 2. JDK 설정
uses: actions/setup-java@v3 # JDK 설치 (여기선 Java 17 사용)
with:
java-version: '17'
distribution: 'temurin' # OpenJDK 17 선택
cache: gradle # Gradle 캐시 설정
- name: Grant execute permission for gradlew # 3. Gradle 실행 권한 부여
run: chmod +x ./gradlew # `gradlew` 실행 권한 설정
- name: gradlew test # 4. Gradle을 이용해 테스트 실행
run: ./gradlew test # Gradle 테스트 실행
name: Deploy to cloudtype
on:
push:
branches:
- master # master 브랜치에 push 될 때마다 실행
jobs:
deploy:
runs-on: ubuntu-latest # 실행할 환경
steps:
- name: Checkout # 1. 코드 체크 아웃
uses: actions/checkout@v3 # GitHub에서 코드 가져오기
- name: Connect deploy key # 2. 배포 키 연결
uses: cloudtype-github-actions/connect@v1
with:
token: ${{ secrets.CLOUDTYPE_TOKEN }} # Cloudtype 인증 토큰
ghtoken: ${{ secrets.GHP_TOKEN }} # GitHub 인증 토큰
- name: Deploy # 3. Cloudtype에 배포
uses: cloudtype-github-actions/deploy@v1
with:
token: ${{ secrets.CLOUDTYPE_TOKEN }} # Cloudtype 인증 토큰
project: your-cloudtype-project # Cloudtype 프로젝트 이름 (예: `nbc.docker/cicd`)
stage: main # 배포할 스테이지 (예: `main`)
yaml: |
name: cicd # 프로젝트 이름
app: java@17 # Java 17을 사용한 앱
options:
ports: 8080 # 포트 설정
context:
git:
url: git@github.com:${{ github.repository }}.git # GitHub URL
ref: ${{ github.ref }} # Git 참조 (브랜치명 등)
preset: java-springboot # 템플릿 설정 (Spring Boot)