-
Notifications
You must be signed in to change notification settings - Fork 5
153 lines (138 loc) · 5.08 KB
/
cd.yml
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# 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 package using Gradle and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle
name: CD
on:
workflow_dispatch:
pull_request:
types: [ closed ]
branches: [ 'main' ]
paths:
- 'backend/**'
jobs:
BE_CD:
if: ${{ github.event.pull_request.merged == true }}
runs-on: self-hosted
permissions:
contents: read
packages: write
actions: write
outputs:
build: ${{ steps.build_result.outputs.result }}
deploy: ${{ steps.deploy_result.outputs.result }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '21'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
- name: Setup Gradle
run: chmod +x ./backend/gradlew
- name: Build with Gradle
continue-on-error: true
id: build
run: |
cd backend
./gradlew build
- name: Save Build Result
continue-on-error: true
id: build_result
run: |
echo "result=${{steps.build.outcome}}" >> $GITHUB_OUTPUT
- name: Stop server
continue-on-error: true
id: stop_server
run: |
PID=$(sudo lsof -t -i:80 || true)
if [ -n "$PID" ]; then
sudo kill -15 "$PID"
echo "Server has been stopped. PID: $PID"
else
echo "No server is running."
fi
- name: Deploy
continue-on-error: true
id: deploy
run: |
JAR_NAME="develup-0.0.1-SNAPSHOT"
JAR_FILE=$(sudo find -name "$JAR_NAME.jar" -print -quit)
if [ -n "$JAR_FILE" ]; then
sudo nohup java -jar /home/ubuntu/"$JAR_NAME".jar --server.port=80 &
echo "Deployed $JAR_NAME"
else
echo "No JAR file found to deploy."
fi
- name: Save Deploy Result
continue-on-error: true
id: deploy_result
run: |
echo "result=${{steps.deploy.outcome}}" >> $GITHUB_OUTPUT
BE_SLACK_MESSAGE:
runs-on: ubuntu-latest
needs: [ BE_CD ]
steps:
- name: Slack mention when build success
if: ${{needs.BE_CD.outputs.build == 'success' && needs.BE_CD.outputs.deploy == 'success'}}
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.ISSUE_CHANNEL }}
payload: |
{
"text": "pr 머지",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<!channel> pr이 main에 머지되었습니다. 배포가 성공했습니다! \n • PR 링크: <${{ github.event.pull_request.html_url }}|${{ github.event.pull_request.title }}>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
- name: Slack mention when build fail
if: ${{needs.BE_CD.outputs.build == 'failure' && needs.BE_CD.outputs.deploy == 'failure'}}
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.ISSUE_CHANNEL }}
payload: |
{
"text": "pr 머지",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<!channel> pr이 main에 머지되었습니다. 🚨그러나 빌드가 실패합니다!!!🚨 \n • PR 링크: <${{ github.event.pull_request.html_url }}|${{ github.event.pull_request.title }}>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
- name: Slack mention when build fail
if: ${{needs.BE_CD.outputs.build == 'success' && needs.BE_CD.outputs.deploy == 'failure'}}
uses: slackapi/[email protected]
with:
channel-id: ${{ secrets.ISSUE_CHANNEL }}
payload: |
{
"text": "pr 머지",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<!channel> pr이 main에 머지되었습니다. ⚠️그러나 배포에 실패했습니다!⚠️ \n • PR 링크: <${{ github.event.pull_request.html_url }}|${{ github.event.pull_request.title }}>"
}
}
]
}
env:
SLACK_BOT_TOKEN: ${{ secrets.BOT_TOKEN }}