-
Notifications
You must be signed in to change notification settings - Fork 5
334 lines (275 loc) · 10.4 KB
/
build.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
name: NWNX4
on: [push, pull_request]
env:
nwnlibd_version: v1.0.2
jobs:
# --------------------------------------------------
build:
name: Build
runs-on: windows-latest
env:
VCPKG_BINARY_SOURCES: 'clear;nuget,GitHub,readwrite'
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Required for git describe
submodules: recursive
# Setup MSVC
- name: Preparing msvc tools
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x86
# toolset: 14.XX
# Install python & meson
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install Python Dependencies
run: pip install meson ninja
- name: Restore cached VCPKG dependencies
id: vcpkg_cache
uses: actions/cache@v3
with:
path: vcpkg_installed/
key: "vcpkg.json-${{ hashFiles('vcpkg.json') }}"
- name: ↳ Install VCPKG dependencies
if: steps.vcpkg_cache.outputs.cache-hit != 'true'
uses: lukka/run-vcpkg@v10
env:
VCPKG_DEFAULT_TRIPLET: x86-windows-static-md
VCPKG_INSTALLED_DIR: ${{ github.workspace }}/vcpkg_installed
VCPKG_DISABLE_METRICS: 1
with:
runVcpkgInstall: true
doNotCache: true
# Prepare build files
- name: Meson Configure
run: |
meson setup builddir --buildtype=release --optimization=2
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
continue-on-error: true
with:
languages: cpp
source-root: src
# Compile everything
- name: Meson build
run: |
cd builddir
meson compile
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
continue-on-error: true
# Copy nwnx4 files in appropriate directories
- name: Meson install
shell: bash
run: |
cd builddir
meson install --destdir=$PWD/../nwnx4
# Download / restore nwn-lib-d tools
- name: Restore cached nwn-lib-d-tools
id: nwnlibd_cache
uses: actions/cache@v3
with:
path: C:/nwn-lib-d-tools/
key: "nwn-lib-d-tools-${{env.nwnlibd_version}}"
- name: Install nwn-lib-d-tools if not cached
if: steps.nwnlibd_cache.outputs.cache-hit != 'true'
shell: bash
run: |
curl -L 'https://github.com/CromFr/nwn-lib-d/releases/download/${{env.nwnlibd_version}}/nwn-lib-d-tools-windows-x86_64.zip' -o /tmp/nwn-lib-d-tools.zip
unzip -d /c/ /tmp/nwn-lib-d-tools.zip
rm /tmp/nwn-lib-d-tools.zip
- name: Package nwnx4
shell: bash
run: |
rm nwnx4/*.lib nwnx4/plugins/*.lib
/c/nwn-lib-d-tools/nwn-erf create -o nwnx4/nwscript/nwnx.erf nwnx4/nwscript/
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
path: nwnx4/
name: nwnx4-${{ github.sha }}
clang-format:
name: clang-format check
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Install clang-format
run: |
sudo apt install clang-format-14
clang-format --version
- name: Check files format
run: |
git ls-files \*.h \*.cpp \*.c \
| grep -vE '^src/plugins/xp_sqlite/lib/|^src/plugins/xp_bugfix/|^src/NWN2Lib/' \
| xargs -d\\n clang-format --dry-run --Werror
# --------------------------------------------------
test:
name: Run test module
needs: build
runs-on: windows-latest
strategy:
matrix:
sql: ["xp_mysql", "xp_sqlite"]
fail-fast: false
steps:
# ------------- Install dependencies
- uses: shogo82148/actions-setup-mysql@v1
if: matrix.sql == 'xp_mysql'
with:
distribution: mariadb
mysql-version: '10.6'
auto-start: true
- name: "Setup MySQL user and database access"
if: matrix.sql == 'xp_mysql'
run: |
mysql -uroot -hlocalhost -e "
CREATE USER 'nwn'@'localhost' IDENTIFIED BY 'nwn';
CREATE DATABASE nwnx;
GRANT ALL ON nwnx.* TO 'nwn'@'localhost';
"
- name: Install cached nwn-lib-d-tools
id: nwnlibd_cache
uses: actions/cache@v3
with:
path: C:/nwn-lib-d-tools/
key: "nwn-lib-d-tools-${{env.nwnlibd_version}}"
- name: "Download NWN2Server"
shell: bash
run: |
curl -L 'https://raw.githubusercontent.com/wiki/nwn2dev/nwnx4/nwnx4_nwn2server.zip' -o nwnx4_nwn2server.zip
7z x nwnx4_nwn2server.zip -o/c/
rm nwnx4_nwn2server.zip
- name: "Install choco packages"
run: |
choco install directx vcredist2010 procdump
# Note: vcredist2010 is required for xp_ini (msvcr100.dll)
- name: "Enable crash dumps"
run: |
mkdir -p "C:\CrashDumps"
procdump.exe -i "C:\CrashDumps" -ma -k
# Download the repo for installing test module files
- uses: actions/checkout@v3
# Download nwnx4 release zip
- uses: actions/download-artifact@v3
with:
name: nwnx4-${{ github.sha }}
path: C:/nwnx4/
- name: "Copy NWN2 home"
shell: bash
run: |
cp -r test/ /c/nwn2home
- name: "Configure NWNX4"
shell: bash
run: |
mkdir -p /c/nwnx4_user/ /c/nwnx4_user/plugins/
# Install old ini plugin for testing compatibility
cp .github/workflows/xp_ini.dll /c/nwnx4_user/plugins/
cp .github/workflows/test.ini /c/nwnx4_nwn2server/
cd /c/nwnx4_user/
# Install default config for plugins
cp /c/nwnx4/config.example/* .
# Configure nwnx.ini to load the module
sed -i -E '
s|^\s*#?\s*nwn2\s*=.*$|nwn2 = ../nwnx4_nwn2server|g;
s|^\s*#?\s*parameters\s*=.*$|parameters = -moduledir NWNX4UnitTests -home %NWNX4_DIR%/../nwn2home|g;
s|^\s*#?\s*nwn2temp\s*=.*$|nwn2temp = C:/nwn2temp|g;
s|plugin_list\s*=.*$|plugin_list = xp_bugfix,xp_fastboot,xp_funcs,${{matrix.sql}},xp_objectattributes,xp_pickpocket,xp_profiler,xp_srvadmin,xp_time,xp_example_cplugin,xp_ini|g;
s|^restartDelay\s*=.*$|restartDelay = 600|g;
s|^gamespyInterval\s*=.*$|gamespyInterval = 1|g;
s|^gamespyDelay\s*=.*$|gamespyDelay = 10|g;
' nwnx.ini
echo "======================================== nwnx.ini"
cat nwnx.ini
echo "========================================"
# - name: "Disable windows defender"
# run: |
# Add-MpPreference -ExclusionProcess "NWNX4_Controller.exe"
# Add-MpPreference -ExclusionProcess "nwn2server.exe"
- name: "Start server and wait for test success"
shell: bash
run: |
set -o pipefail
# Start procdump and let it trigger on nwn2server crash
procdump -ma -e -w nwn2server.exe "/c/CrashDumps" > /dev/null &
cd /c/nwnx4_user/
echo "> $(date --rfc-3339=seconds --utc) Start NWNX4"
# Start NWNX4_Controller.exe with admin privileges
powershell -Command "Start-Process ../nwnx4/NWNX4_Controller.exe -ArgumentList '-verbose','-interactive' -Verb RunAs"
sleep 20
echo "> $(date --rfc-3339=seconds --utc) Check NWNX4"
# Check if nwn2server is online
RUN_MOD=$(/c/nwn-lib-d-tools/nwn-srv bnxi 127.0.0.1 -f json 2> /dev/null | jq -r .modName || echo "Unknown")
if tasklist | grep -qi "NWNX4_Controller.exe" \
&& tasklist | grep -qi "nwn2server.exe" \
&& [[ "$RUN_MOD" == "NWNX4UnitTests" ]]; then
echo "> NWN2Server is still running, tests succeeded"
RES=0
else
echo "> NWN2Server is not running as expected:"
tasklist | grep -qi "NWNX4_Controller.exe" || echo "> Missing NWNX4_Controller.exe process"
tasklist | grep -qi "nwn2server.exe" || echo "> Missing nwn2server.exe process"
/c/nwn-lib-d-tools/nwn-srv ping 127.0.0.1 >&/dev/null || echo "> Not responding to UDP pings"
[[ "$RUN_MOD" == "NWNX4UnitTests" ]] || echo "> Loaded module: $RUN_MOD"
RES=1
fi
# Stop processes if still running
taskkill //IM nwn2server.exe //IM NWNX4_Controller.exe //F ||true
exit $RES
- name: Check for warnings and errors in logs
if: always()
shell: bash
run: |
! grep -E "ERROR:|WARN: " /c/nwnx4_user/*.txt /c/nwn2temp/NWN2/LOGS.0/*.txt
- name: "Upload nwn2server logs"
if: always()
uses: actions/upload-artifact@v3
with:
path: |
C:/nwn2temp/NWN2/LOGS.0/*.txt
C:/nwnx4_user/*.txt
name: "test-${{matrix.sql}}-logs"
- name: "Upload nwn2server crash dump if any"
if: always()
uses: actions/upload-artifact@v3
with:
path: C:/CrashDumps/*
name: "test-${{matrix.sql}}-crash-dumps"
if-no-files-found: ignore
# --------------------------------------------------
release:
name: Create release if tagged
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs: test
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: nwnx4-${{ github.sha }}
path: nwnx4/
- name: Compress release
run: |
zip -r nwnx4.zip nwnx4/
- name: Extract release info
shell: bash
id: rel_info
run: |
TAG=$(echo '${{ github.ref }}' | grep -oE '\bv[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$' || true)
echo "tag=$TAG" >> $GITHUB_STATE
[[ "$TAG" =~ -rc[0-9]+$ ]] && PRERELEASE=true || PRERELEASE=false
echo "prerelease=$PRERELEASE" >> $GITHUB_STATE
if [[ "$TAG" != "" ]]; then
echo "Deploying $TAG (prerelease=$PRERELEASE)"
else
echo "Not a tagged release"
fi
- name: Create draft release with artifact
uses: softprops/action-gh-release@v1
with:
name: ${{ steps.rel_info.outputs.tag }}
prerelease: ${{ steps.rel_info.outputs.prerelease }}
files: nwnx4.zip
draft: true