refactor(github) : build 단계랑 deploy 단계로 분리 #4
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: Java CD with Gradle | |
on: | |
push: | |
branches: [ "master" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '21' | |
distribution: 'temurin' | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 | |
- name: Build with Gradle Wrapper | |
run: ./gradlew clean build -x test | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Deploy to server | |
uses: appleboy/scp-action@v0.1.7 | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_NAME }} | |
password: ${{ secrets.SERVER_PASSWORD }} | |
source: ${{ secrets.SOURCE_PATH }} | |
target: ${{ secrets.DIST_PATH }} | |
- name: Execute jar file | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SERVER_HOST }} | |
username: ${{ secrets.SERVER_NAME }} | |
password: ${{ secrets.SERVER_PASSWORD }} | |
script: | | |
PID=$(lsof -ti:8080) | |
if [ -n "$PID" ]; then | |
kill $PID | |
nohup java -jar $${{ secrets.JAR_FILE }} |