-
Notifications
You must be signed in to change notification settings - Fork 2
91 lines (79 loc) · 3.28 KB
/
Copy pathbackend-cd-develop.yml
File metadata and controls
91 lines (79 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
name: KOIN_API_V2 CD (develop)
on:
push:
branches:
- develop
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Record start time
run: echo "START_TIME=$(date +%s)" >> $GITHUB_ENV
- name: Notify Slack - Deploy Start
env:
ACTIONS_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
COMMIT_MSG=$(git log -1 --pretty=%s HEAD)
curl -X POST ${{ secrets.SLACK_DEPLOY_WEBHOOK_URL }} \
-H 'Content-Type: application/json' \
-d "{
\"text\": \":rocket: *[Develop] 배포 시작*\n• Repo: ${{ github.repository }}\n• Branch: develop\n• Author: @${{ github.actor }}\n• Commit: ${COMMIT_MSG}\n• <${ACTIONS_URL}|Actions 보기>\"
}"
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
cache-read-only: false
cache-encryption-key: ${{ secrets.GRADLE_CACHE_ENCRYPTION_KEY }}
- name: Create Firebase Admin SDK JSON
run: echo '${{ secrets.FCM_ADMIN_SDK_JSON_DEVELOP }}' > src/main/resources/koin-firebase-adminsdk.json
- name: Build JAR
run: |
set -a
source .env.example
set +a
./gradlew clean build -x test -Dspring.profiles.active=dev
- name: SCP JAR to develop server
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.DEVELOP_SERVER_HOST }}
username: ${{ secrets.DEVELOP_SERVER_USER }}
key: ${{ secrets.DEVELOP_SSH_PRIVATE_KEY }}
port: ${{ secrets.DEVELOP_SERVER_PORT }}
source: ${{ secrets.SOURCE_JAR_PATH }}
target: ${{ secrets.DEVELOP_SERVER_JAR_PATH }}
strip_components: 2
- name: Run deploy script on develop server
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.DEVELOP_SERVER_HOST }}
username: ${{ secrets.DEVELOP_SERVER_USER }}
key: ${{ secrets.DEVELOP_SSH_PRIVATE_KEY }}
port: ${{ secrets.DEVELOP_SERVER_PORT }}
script: ${{ secrets.DEVELOP_DEPLOY_SCRIPT_PATH }}
- name: Notify Slack - Deploy Result
if: always()
env:
ACTIONS_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
COMMIT_MSG=$(git log -1 --pretty=%s HEAD)
DURATION_SEC=$(( $(date +%s) - START_TIME ))
DURATION="${DURATION_SEC}초 (약 $(( DURATION_SEC / 60 ))분)"
if [ "${{ job.status }}" = "success" ]; then
ICON=":white_check_mark:"
STATUS="배포 성공"
else
ICON=":x:"
STATUS="배포 실패"
fi
curl -X POST ${{ secrets.SLACK_DEPLOY_WEBHOOK_URL }} \
-H 'Content-Type: application/json' \
-d "{
\"text\": \"${ICON} *[Develop] ${STATUS}*\n• Repo: ${{ github.repository }}\n• Branch: develop\n• Author: @${{ github.actor }}\n• Commit: ${COMMIT_MSG}\n• Duration: ${DURATION}\n• <${ACTIONS_URL}|Actions 보기>\"
}"