Merge pull request #52 from EcoMarket-CUK/feature/#51 #18
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 CI/CD with Gradle | |
on: | |
push: | |
branches: [ "release" ] | |
jobs: | |
Deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout GitHub Repository Code | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: temurin | |
java-version: 17 | |
- name: Checkout SubModule Repository | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.ACTION_TOKEN }} | |
submodules: true | |
- name: Git Submodule Update | |
run: | | |
git submodule update --remote --recursive | |
- name: Make gradlew executable | |
run: chmod +x ./gradlew | |
- name: Build With Test | |
run: ./gradlew clean build | |
- name: Change Build File Name | |
run: mv ./build/libs/*SNAPSHOT.jar ./project.jar | |
- name: Send Build File To EC2 With SCP | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
source: project.jar | |
target: /home/ubuntu/Jaebichuri-Backend/tobe | |
- name: SSH To EC2 | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_PRIVATE_KEY }} | |
script_stop: true | |
script: | | |
rm -rf /home/ubuntu/Jaebichuri-Backend/current | |
mkdir /home/ubuntu/Jaebichuri-Backend/current | |
mv /home/ubuntu/Jaebichuri-Backend/tobe/project.jar /home/ubuntu/Jaebichuri-Backend/current/project.jar | |
cd /home/ubuntu/Jaebichuri-Backend/current | |
sudo fuser -k -n tcp 8080 || true | |
nohup java -jar project.jar --spring.profiles.active=dev > ./output.log 2>&1 & | |
rm -rf /home/ubuntu/Jaebichuri-Backend/tobe |