๐ ๊ฐ๊ฒฉ์ ์ ๋ ฌ ์๋จ ์ค๋ฅ (#116) #86
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: cd with Gradle | |
on: | |
push: | |
branches: | |
- main # main ๋ธ๋์น์ push๋ ๋ | |
permissions: write-all # ํ ์คํธ ๊ฒฐ๊ณผ ์์ฑ์ ์ํด ์ฐ๊ธฐ๊ถํ ์ถ๊ฐ | |
jobs: | |
build: | |
if: github.event.pull_request.merged == true || github.event_name == 'push' # PR merge ๋๋ push์ผ ๋ ์คํ | |
runs-on: ubuntu-latest # ํ๊ฒฝ | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 # ์ฝ๋ ์ฒดํฌ์์ = ๊ฐ์ํ๊ฒฝ ๋ณต์ฌ | |
- name: Set up JDK 21 | |
uses: actions/setup-java@v3 #jdk ์ปดํ์ผ๋ฌ | |
with: | |
java-version: '21' | |
distribution: 'temurin' # ์๋ฐ ๊ฐ๋ฐ ํคํธ ๋ฐฐํฌํ | |
- name: Gradle Caching | |
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: Grant execute permission for Gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew build -x test #๋น๋ | |
- name: Ensure target directory exists | |
uses: appleboy/ssh-action@master # SSH๋ฅผ ํตํด ๋์ ๋๋ ํ ๋ฆฌ ์์ฑ | |
with: | |
username: ubuntu | |
host: ${{ secrets.SSH_HOST }} | |
key: ${{ secrets.SSH_KEY }} | |
script: | | |
mkdir -p /home/ubuntu/gather_back_end | |
- name: List build directory | |
run: ls -la build/libs | |
- name: Transfer Build File using SCP | |
uses: appleboy/scp-action@master # .jar ํ์ผ ์๊ฒฉ ์๋ฒ๋ก ๋ณต์ฌ | |
with: | |
username: ubuntu | |
host: ${{ secrets.SSH_HOST }} | |
key: ${{ secrets.SSH_KEY }} | |
source: | | |
build/libs/gather_back_end-0.0.1-SNAPSHOT.jar | |
target: "/home/ubuntu/gather_back_end" | |
- name: Deploy using Docker Compose via SSH(Prod) | |
if: github.ref == 'refs/heads/main' | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.SSH_HOST }} | |
username: ubuntu | |
key: ${{ secrets.SSH_KEY }} | |
script_stop: true | |
script: | | |
cd /home/ubuntu/gather_back_end || exit 1 # ๊ฒฝ๋ก ๋ณ๊ฒฝ ์คํจ ์ ์ข ๋ฃ | |
sudo docker compose down | |
sudo docker compose up --build -d |