Skip to content

Chore : Update gradle.yml #41

Chore : Update gradle.yml

Chore : Update gradle.yml #41

Workflow file for this run

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: Java CI with Gradle
on:
push:
branches: [ "CHAT-63-DevOps-ToolChain" ]
pull_request:
branches: [ "CHAT-63-DevOps-ToolChain" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle
run: ./gradlew --warning-mode all build -i
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v3 # Checkout ์•ก์…˜ ๋ฒ„์ „์„ v3์œผ๋กœ ์ผ์น˜
- name: Set up SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.HOST }} >> ~/.ssh/known_hosts
- name: Check if JAR file exists
run: |
if [ -f "./build/libs/chatdiary-0.0.1-SNAPSHOT-plain.jar" ]; then
echo "JAR file exists"
else
echo "JAR file does not exist"
fi
- name: Copy jar file to remote
uses: appleboy/scp-action@master
with:
username: ec2-user
host: ${{ secrets.HOST }}
key: ${{ secrets.PRIVATE_KEY }}
source: "./build/libs/chatdiary-0.0.1-SNAPSHOT-plain.jar"
target: "/home/ec2-user/cicd"
- name: Check deploy script exists
run: |
if [ -f deploy.sh ]; then
echo "deploy.sh exists"
else
echo "deploy.sh does not exist"
exit 1
fi
- name: Copy deploy script file to remote
uses: appleboy/scp-action@master
with:
username: ec2-user
host: ${{ secrets.HOST }}
key: ${{ secrets.PRIVATE_KEY }}
source: "deploy.sh"
target: "/home/ec2-user/cicd"
- name: Set up Environment Variables
env:
DEPLOY_SERVER: ${{ secrets.HOST }}
DEPLOY_USER: ${{ secrets.USERNAME }}
DEPLOY_KEY: ${{ secrets.PRIVATE_KEY }}
DEPLOY_TARGET_DIR: /home/ec2-user/app
run: |
# You can add any necessary environment setup here
echo "Setting up environment variables..."
echo "DEPLOY_SERVER=$DEPLOY_SERVER"
echo "DEPLOY_USER=$DEPLOY_USER"
echo "DEPLOY_KEY=$DEPLOY_KEY"
echo "DEPLOY_TARGET_DIR=$DEPLOY_TARGET_DIR"
- name: Execute deploy script
uses: appleboy/ssh-action@master
with:
username: ec2-user
host: ${{ secrets.HOST }}
key: ${{ secrets.PRIVATE_KEY }}
script: |
chmod +x /home/ec2-user/cicd/deploy.sh
sh /home/ec2-user/cicd/deploy.sh