-
-
Notifications
You must be signed in to change notification settings - Fork 75
261 lines (231 loc) · 10.1 KB
/
deploy.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
name: Deploy
on:
repository_dispatch:
types: [deploy]
workflow_dispatch:
inputs:
action:
description: 'Action'
required: true
type: choice
options:
- 'deploy'
- 'restart'
- 'stop'
default: 'restart'
branch:
description: 'Branch, meaning server instance'
required: true
type: choice
options:
- 'sweetpie'
- 'indev'
default: 'indev'
delay:
description: 'Delay before action in hours (decimal works too, e.g. 0.5)'
required: false
type: number
default: 0
env:
BUILD_TYPE: RelWithDebInfo
GAMEMODE_GITHUB_TOKEN: ${{secrets.GAMEMODE_GITHUB_TOKEN}}
jobs:
check-if-sleep-needed:
runs-on: ubuntu-latest
outputs:
should_sleep: ${{ steps.check_sleep.outputs.should_sleep }}
steps:
- name: Set up workflow_dispatch inputs
if: github.event_name == 'workflow_dispatch'
run: |
echo "DELAY=${{ github.event.inputs.delay }}" >> $GITHUB_ENV
- name: Set up repository_dispatch inputs
if: github.event_name == 'repository_dispatch'
run: |
echo "Received Payload:"
echo "${{ github.event.client_payload.inputs.delay }}"
echo "DELAY=${{ github.event.client_payload.inputs.delay }}" >> $GITHUB_ENV
- name: Check if sleep is needed
id: check_sleep
uses: actions/github-script@v7
with:
script: |
const delay = parseFloat(process.env.DELAY || '0'); // Default to 0 if DELAY is not set
const shouldSleep = delay > 0;
console.log(`Delay is ${delay} hours. Should sleep: ${shouldSleep}`);
core.setOutput("should_sleep", shouldSleep);
sleep:
# This is our self-hosted runner label to run the sleep job on
runs-on: sleepy-runner
if: needs.check-if-sleep-needed.outputs.should_sleep == 'true'
needs: check-if-sleep-needed
steps:
- name: Set up workflow_dispatch inputs
if: github.event_name == 'workflow_dispatch'
run: |
echo "DELAY=${{ github.event.inputs.delay }}" >> $GITHUB_ENV
- name: Set up repository_dispatch inputs
if: github.event_name == 'repository_dispatch'
run: |
echo "Received Payload:"
echo "${{ github.event.client_payload.inputs.delay }}"
echo "DELAY=${{ github.event.client_payload.inputs.delay }}" >> $GITHUB_ENV
- name: Sleep
uses: actions/github-script@v6
with:
script: |
const delay = process.env.DELAY || 0; // default to 0 if DELAY is not specified
console.log(`Sleeping for ${delay} hours`);
let totalSeconds = parseFloat(delay) * 3600;
const interval = 30;
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms * 1000));
(async () => {
while (totalSeconds > 0) {
const hours = Math.floor(totalSeconds / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = Math.floor(totalSeconds % 60);
console.log(`Time remaining: ${hours}h ${minutes}m ${seconds}s`);
await sleep(interval);
totalSeconds -= interval;
}
console.log("Done sleeping");
})();
deploy:
needs: [check-if-sleep-needed, sleep]
if: needs.check-if-sleep-needed.outputs.should_sleep == 'false' || always()
runs-on: ubuntu-latest
steps:
- name: Set up workflow_dispatch inputs
if: github.event_name == 'workflow_dispatch'
run: |
echo "DEPLOY_BRANCH=${{ github.event.inputs.branch }}" >> $GITHUB_ENV
echo "DEPLOY_ACTION=${{ github.event.inputs.action }}" >> $GITHUB_ENV
- name: Set up repository_dispatch inputs
if: github.event_name == 'repository_dispatch'
run: |
echo "Received Payload:"
echo "${{ github.event.client_payload.inputs.branch }}"
echo "${{ github.event.client_payload.inputs.action }}"
echo "DEPLOY_BRANCH=${{ github.event.client_payload.inputs.branch }}" >> $GITHUB_ENV
echo "DEPLOY_ACTION=${{ github.event.client_payload.inputs.action }}" >> $GITHUB_ENV
- name: Checkout (full)
if: ${{env.DEPLOY_ACTION == 'deploy'}}
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Checkout (last commit)
if: ${{env.DEPLOY_ACTION != 'deploy'}}
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Gather PRs
if: ${{env.DEPLOY_ACTION == 'deploy'}}
uses: Pospelove/auto-merge-action@main
with:
path: ${{github.workspace}}
repositories: |
[
{
"owner": "skyrim-multiplayer",
"repo": "skymp",
"labels": ["merge-to:${{env.DEPLOY_BRANCH}}"]
},
{
"owner": "skyrim-multiplayer",
"repo": "skymp5-patches",
"labels": ["merge-to:${{env.DEPLOY_BRANCH}}"],
"token": "${{secrets.SKYMP5_PATCHES_PAT}}"
}
]
- name: Calculate diff being deployed
if: ${{env.DEPLOY_ACTION == 'deploy'}}
run: |
echo ""
echo "=== Full diff being deployed:"
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git add .
git commit -m "Temporary commit for diff"
git diff HEAD~1 | tee deploy_git_diff
- name: Upload diff artifact
if: ${{env.DEPLOY_ACTION == 'deploy'}}
uses: actions/upload-artifact@v4
with:
name: patches
path: |
deploy_git_diff
- name: Post a link in Discord
if: ${{env.DEPLOY_ACTION == 'deploy'}}
env:
DEPLOY_STATUS_WEBHOOK: ${{secrets.DEPLOY_STATUS_WEBHOOK}}
run: |
link="${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}"
./misc/deploy/call_webhook.sh "Started build. " \
"You can follow the process at <$link>. " \
"Once build is finished, further progress will be reported here."
- name: Get image to build upon
run: |
cat ${{github.workspace}}/misc/github_env_linux >> "$GITHUB_ENV"
- name: Prepare for build
if: ${{env.DEPLOY_ACTION == 'deploy'}}
uses: addnab/docker-run-action@v3
with:
image: ${{ env.SKYMP_VCPKG_DEPS_IMAGE }}
options: |
-v ${{github.workspace}}:/src
run: |
chown -R skymp:skymp /src
- name: CMake Configure
if: ${{env.DEPLOY_ACTION == 'deploy'}}
uses: addnab/docker-run-action@v3
with:
image: ${{ env.SKYMP_VCPKG_DEPS_IMAGE }}
options: |
-v ${{github.workspace}}:/src
-u skymp
-e CI=true
-e DEPLOY_BRANCH=${{ env.DEPLOY_BRANCH }}
run: |
cd /src \
&& ./build.sh --configure \
-DBUILD_UNIT_TESTS=OFF \
-DBUILD_GAMEMODE=ON \
-DOFFLINE_MODE=OFF \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-DGITHUB_TOKEN=${{env.GAMEMODE_GITHUB_TOKEN}}
- name: Upload compile_commands.json
uses: actions/upload-artifact@v4
with:
name: compile_commands.json
path: ${{github.workspace}}/build/compile_commands.json
- name: Build
if: ${{env.DEPLOY_ACTION == 'deploy'}}
uses: addnab/docker-run-action@v3
with:
image: ${{ env.SKYMP_VCPKG_DEPS_IMAGE }}
options: |
-v ${{github.workspace}}:/src
-u skymp
run: |
cd /src \
&& ./build.sh --build
- name: Deploy
env:
DEPLOY_STATUS_WEBHOOK: ${{secrets.DEPLOY_STATUS_WEBHOOK}}
DEPLOY_TARGET_HOST: ${{secrets.DEPLOY_TARGET_HOST_06_2024}}
DEPLOY_TARGET_USER: ${{secrets.DEPLOY_TARGET_USER_06_2024}}
DEPLOY_SSH_PRIVATE_KEY: ${{secrets.DEPLOY_SSH_PRIVATE_KEY_06_2024}}
DEPLOY_SSH_KNOWN_HOSTS: ${{secrets.DEPLOY_SSH_KNOWN_HOSTS_06_2024}}
run: |
./misc/deploy/push_branch_to_server.sh
- name: Notify failure
env:
DEPLOY_STATUS_WEBHOOK: ${{secrets.DEPLOY_STATUS_WEBHOOK}}
if: '!success()'
run: |
link="${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}"
./misc/deploy/call_webhook.sh \
"Build or deploy failed or was cancelled. " \
"Check out the logs at <$link> to find out why."