๐ท CI ๋น๋ ์์ : GitHub Action CICD Discord ์๋ฆผ ๊ธฐ๋ฅ ํ ์คํธ ๋ฐ yml ๊ตฌ๋ถ์ ์ํด PR ์๋ฆผ๋ดโฆ #1
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 with Gradle | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build_and_deploy: | |
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: Secret Prod Env File Download | |
# run: | | |
# mkdir -p ./src/main/resources/properties | |
# echo "${{ secrets.PROD_ENV_FILE }}" > ./src/main/resources/properties/env.properties | |
# | |
# - name: Secret Test Env File Download | |
# run: | | |
# mkdir -p ./src/test/resources/properties | |
# echo "${{ secrets.TEST_ENV_FILE }}" > ./src/test/resources/properties/test-env.properties | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 | |
- name: Build with Gradle Wrapper | |
id: build | |
run: ./gradlew build | |
- name: Login Dokcer | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build with Docker Push | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
file: Dockerfile | |
push: true | |
tags: | | |
${{ secrets.DOCKER_USERNAME }}/jdk-21-spring-boot-3.3.1:${{ github.sha }} | |
${{ secrets.DOCKER_USERNAME }}/jdk-21-spring-boot-3.3.1:latest | |
- name: SSH to Remote Server and Deploy | |
uses: appleboy/ssh-action@v1.0.3 | |
with: | |
host: ${{ secrets.REMOTE_HOST }} | |
username: ${{ secrets.SSH_USERNAME }} | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
port: ${{ secrets.SSH_PORT }} | |
script: | | |
docker-compose -f /home/ubuntu/itzip/docker-compose.yml down | |
docker-compose -f /home/ubuntu/itzip/docker-compose.yml pull | |
docker-compose -f /home/ubuntu/itzip/docker-compose.yml up -d | |
- name: Send Success Discord Notification | |
if: success() | |
run: | | |
curl -H "Content-Type: application/json" \ | |
-d '{"content": "**๋ฐฐํฌ ์ฑ๊ณต!** :rocket: \n๋น๋ ๋ฐ ๋ฐฐํฌ ๊ณผ์ ์ด ์ฑ๊ณต์ ์ผ๋ก ์๋ฃ๋์์ต๋๋ค."}' \ | |
${{ secrets.DISCORD_WEBHOOK_URL }} | |
- name: Send Failure Discord Notification | |
if: failure() | |
run: | | |
outcome_message="" | |
if: steps.build.outcome == 'failure' | |
outcome_message="${{ steps.build.outcome }}: ๋น๋ ๋จ๊ณ์์ ์ค๋ฅ ๋ฐ์" | |
fi | |
if: steps.docker_build.outcome == 'failure' | |
outcome_message="${{ steps.docker_build.outcome }}: Docker ๋น๋ ๋จ๊ณ์์ ์ค๋ฅ ๋ฐ์" | |
fi | |
if: steps.deploy.outcome == 'failure' | |
outcome_message="${{ steps.deploy.outcome }}: ๋ฐฐํฌ ๋จ๊ณ์์ ์ค๋ฅ ๋ฐ์" | |
fi | |
curl -H "Content-Type: application/json" \ | |
-d '{"content": "**๋ฐฐํฌ ์คํจ!** :x: \n๋น๋ ๋ฐ ๋ฐฐํฌ ๊ณผ์ ์์ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ์ค๋ฅ ๋ด์ฉ: '"${outcome_message}"'"}' \ | |
${{ secrets.DISCORD_WEBHOOK_URL }} |