Feature/6 ci docker integration #10
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI Pipeline | |
on: | |
push: | |
branches: | |
[ main ] | |
pull_request: | |
branches: | |
[ main ] | |
types: | |
[opened, synchronize, reopened] | |
jobs: | |
Continuous-Integration: | |
runs-on: ubuntu-latest | |
env: | |
DB_URL: ${{ secrets.DB_URL }} | |
DB_USERNAME: ${{ secrets.DB_USERNAME }} | |
DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
steps: | |
- name: Github Repository 파일 불러오기 | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: JDK 21 버전 설치 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: temurin | |
java-version: 21 | |
- name: Gradle 캐싱 | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: SonarCloud 패키지 캐싱 | |
uses: actions/cache@v4 | |
with: | |
path: ~/.sonar/cache | |
key: ${{ runner.os }}-sonar | |
restore-keys: ${{ runner.os }}-sonar | |
- name: 빌드 권한 부여 | |
run: chmod +x ./gradlew | |
shell: bash | |
- name: 빌드 및 테스트 | |
run: ./gradlew build | |
- name: Close PR, if build fail | |
if: ${{ failure() }} | |
uses: actions/github-script@v6 | |
with: # actions(uses)의 파라미터 역할 | |
github-token: ${{ github.TOKEN }} | |
script: | | |
const pull_number = ${{ github.event.pull_request.number }} | |
const updated_title = `[BUILD FAIL] ${{ github.event.pull_request.title }}` | |
await github.rest.pulls.createReview({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: pull_number, | |
body: '빌드에 실패했습니다.', | |
event: 'REQUEST_CHANGES' | |
}) | |
await github.rest.pulls.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: pull_number, | |
title: updated_title, | |
state: 'closed' | |
}) | |
- name: 도커 허브 로그인 | |
run: | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_ACCESS_TOKEN }} | |
- name: 도커 빌드및 Push | |
run: | | |
docker build -t 7zrv/somemore:${GITHUB_SHA::7} -t 7zrv/somemore:latest . | |
docker push 7zrv/somemore:${GITHUB_SHA::7} | |
docker push 7zrv/somemore:latest | |
- name: SonarCloud 빌드및 분석 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
run: ./gradlew build sonar --info |