Skip to content

Merge pull request #36 from UMC-HKT-Team-R/feat/29 #46

Merge pull request #36 from UMC-HKT-Team-R/feat/29

Merge pull request #36 from UMC-HKT-Team-R/feat/29 #46

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [ main ] # main 브랜치에 push가 일어날 때 실행
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permission for gradlew
run: chmod +x ./Midnight-Snacker/gradlew
- name: Build with Gradle Wrapper
working-directory: ./Midnight-Snacker # Gradle 빌드 파일이 있는 디렉토리로 이동
run: |
./gradlew --stop && ./gradlew clean --refresh-dependencies
./gradlew clean build
ls -l build/libs
- name: SSH to EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_SSH_KEY }}
port: 22
script: |
whoami
ls -al
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: cicdsample
path: ./Midnight-Snacker/build/libs/*.jar
- name: Copy jar file to remote
uses: appleboy/[email protected]
with:
username: ubuntu
host: ${{ secrets.EC2_HOST }}
key: ${{ secrets.EC2_SSH_KEY }}
source: "./Midnight-Snacker/build/libs/*.jar"
target: "/home/ubuntu/cicd"
debug: true
###
# - name: Copy jar file to remote
# uses: appleboy/scp-action@master
# with:
# username: ubuntu
# host: ${{ secrets.HOST }}
# key: ${{ secrets.PRIVATE_KEY }}
# source: "./build/libs/bookmark-0.0.1-SNAPSHOT.jar"
# target: "/home/ubuntu/cicd"
# strip_components: 2
###
- name: Execute deploy script
uses: appleboy/ssh-action@master
with:
username: ubuntu
host: ${{ secrets.EC2_HOST }}
key: ${{ secrets.EC2_SSH_KEY }}
script_stop: true
script: |
if [ ! -f /home/ubuntu/cicd/deploy.sh ]; then
echo "Error: deploy.sh not found on remote server!"
exit 1
fi
chmod +x /home/ubuntu/cicd/deploy.sh
sh /home/ubuntu/cicd/deploy.sh
# NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html).
# If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version.
#
# - name: Setup Gradle
# uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
# with:
# gradle-version: '8.9'
#
# - name: Build with Gradle 8.9
# run: gradle build
# dependency-submission:
# runs-on: ubuntu-latest
# permissions:
# contents: write
# steps:
# - uses: actions/checkout@v4
# - name: Set up JDK 17
# uses: actions/setup-java@v4
# with:
# java-version: '17'
# distribution: 'temurin'
# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
# - name: Generate and submit dependency graph
# uses: gradle/actions/dependency-submission@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0