-
Notifications
You must be signed in to change notification settings - Fork 2
279 lines (230 loc) · 9.67 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
name: nwn2-tools
on:
push:
schedule:
- cron: '0 0 * * 6'
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
platform: ["linux-gnu", "windows-msvc"]
arch: ["i686", "x86_64"]
steps:
- uses: actions/checkout@v2
- name: Install requirements
run: |
sudo apt install -q -y p7zip libxml2-dev make gcc-multilib mingw-w64
echo "========= Install latest LDC ========="
wget -q https://dlang.org/install.sh -O /tmp/install.sh
bash /tmp/install.sh install ldc
echo "========= Create LDC activation symlink ========="
ln -s "$(bash /tmp/install.sh install ldc -a)" ~/dlang/activate
source ~/dlang/activate
echo "========= Install LDC windows libs for cross compiling ========="
cd ~/dlang/
LDC_VERSION=$(ldc2 --version | head -n1 | grep -oE '[0-9]+(\.[0-9]+){2}')
wget -q "https://github.com/ldc-developers/ldc/releases/download/v$LDC_VERSION/ldc2-$LDC_VERSION-windows-multilib.7z"
7zr x "ldc2-$LDC_VERSION-windows-multilib.7z" -bd
echo "========= Configure LDC for cross compiling for windows targets ========="
cat >> ~/dlang/ldc-$LDC_VERSION/etc/ldc2.conf << EOF
"i686-.*-windows-msvc":
{
switches = [
"-defaultlib=phobos2-ldc,druntime-ldc",
"-link-defaultlib-shared=false",
];
lib-dirs = [
"$HOME/dlang/ldc2-$LDC_VERSION-windows-multilib/lib32",
];
};
"x86_64-.*-windows-msvc":
{
switches = [
"-defaultlib=phobos2-ldc,druntime-ldc",
"-link-defaultlib-shared=false",
];
lib-dirs = [
"$HOME/dlang/ldc2-$LDC_VERSION-windows-multilib/lib64",
];
};
EOF
cd -
# Print ldc compiler version
echo "================================"
ldc2 --version | head -n6
echo "================================"
- name: Create bin output dir
run: mkdir -p bin/
- name: Build nwn2-moduleinstaller
run: |
source ~/dlang/activate
[[ "${{ matrix.platform }}" == windows-* ]] && BIN_SUFFIX=".exe" || BIN_SUFFIX=""
cd moduleinstaller
dub build --compiler=ldc2 --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release
mv nwn2-moduleinstaller$BIN_SUFFIX ../bin/
- name: Build nwn2-stagingtool
run: |
source ~/dlang/activate
[[ "${{ matrix.platform }}" == windows-* ]] && BIN_SUFFIX=".exe" || BIN_SUFFIX=""
# Mingw is not able to generate i686 windows binaries with SEH (exception handling)
# However ldc2 requires SEH-enabled object files (/SAFESEH)
# See http://mingw-w64.org/doku.php/contribute#seh_for_32bits
if [[ "${{ matrix.arch }}-${{ matrix.platform }}" == "i686-windows-msvc" ]]; then
echo "Skipping Windows 32-bit staging tool"
exit 0
fi
cd stagingtool
if [[ "${{ matrix.platform }}" == windows-* ]]; then
make mingw-${{ matrix.arch }}
else
if [[ "${{ matrix.arch }}" == "i686" ]]; then
make CFLAGS="-m32" LDFLAGS="-melf_i386"
else
make CFLAGS="-m64"
fi
fi
dub build --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release
mv nwn2-stagingtool$BIN_SUFFIX ../bin/
- name: Build nwn2-itemupdater
run: |
source ~/dlang/activate
[[ "${{ matrix.platform }}" == windows-* ]] && BIN_SUFFIX=".exe" || BIN_SUFFIX=""
cd itemupdater
dub build --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release
mv nwn2-itemupdater$BIN_SUFFIX ../bin/
- name: Build nwn2-camtosql
run: |
source ~/dlang/activate
[[ "${{ matrix.platform }}" == windows-* ]] && BIN_SUFFIX=".exe" || BIN_SUFFIX=""
cd camtosql
dub build --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release
dub build --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release :upgrade-scripts
mv nwn2-camtosql$BIN_SUFFIX nwn2-camtosql-upgrade-scripts$BIN_SUFFIX ../bin/
- name: Build nwn2-adjust-item-prices
run: |
source ~/dlang/activate
[[ "${{ matrix.platform }}" == windows-* ]] && BIN_SUFFIX=".exe" || BIN_SUFFIX=""
cd adjust-item-prices
dub build --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release
mv nwn2-adjust-item-prices$BIN_SUFFIX ../bin/
- name: Build nwn2-update-module-arealist
run: |
source ~/dlang/activate
[[ "${{ matrix.platform }}" == windows-* ]] && BIN_SUFFIX=".exe" || BIN_SUFFIX=""
cd update-module-arealist
dub build --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release
mv nwn2-update-module-arealist$BIN_SUFFIX ../bin/
- name: Upload artifacts
uses: actions/upload-artifact@v1
with:
name: "nwn2-tools-${{ matrix.arch }}-${{ matrix.platform }}"
path: bin
create_release:
name: Create release if tagged
needs: build
runs-on: ubuntu-latest
steps:
- name: Get release info
id: rel_info
run: |
TAG=$(echo '${{ github.ref }}' | grep -oE '\bv[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$' || true)
echo "::set-output name=tag::$TAG"
[[ "$TAG" =~ '-rc[0-9]+$' ]] && PRERELEASE=true || PRERELEASE=false
echo "::set-output name=prerelease::$PRERELEASE"
if [[ "$TAG" != "" ]]; then
echo "Deploying $TAG (prerelease=$PRERELEASE)"
else
echo "Not a tagged release"
fi
- name: Delete any existing release
if: steps.rel_info.outputs.tag != ''
run: |
RELEASE_JSON=$(
curl -sL --header "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.rel_info.outputs.tag }}"
)
RELEASE_ID=$(echo "$RELEASE_JSON" | jq -r .id)
if [[ "$RELEASE_ID" != "null" ]]; then
echo "Removing existing release ID=$RELEASE_ID"
curl -sL --header "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-XDELETE "https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID"
fi
- name: Create Release
if: steps.rel_info.outputs.tag != ''
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.rel_info.outputs.tag }}
release_name: ${{ steps.rel_info.outputs.tag }}
prerelease: ${{ steps.rel_info.outputs.prerelease }}
body: |
Automated release with GitHub Actions
> The windows-i686 package does not provide the nwn2-stagingtool executable.
release:
name: Release if tagged
runs-on: ubuntu-latest
needs: create_release
strategy:
matrix:
platform: ["linux-gnu", "windows-msvc"]
arch: ["i686", "x86_64"]
steps:
- name: Get release info
id: rel_info
run: |
TAG=$(echo '${{ github.ref }}' | grep -oE '\bv[0-9]+\.[0-9]+\.[0-9]+(-rc[0-9]+)?$' || true)
echo "::set-output name=tag::$TAG"
[[ "$TAG" =~ '-rc[0-9]+$' ]] && PRERELEASE=true || PRERELEASE=false
echo "::set-output name=prerelease::$PRERELEASE"
if [[ "$TAG" != "" ]]; then
echo "Deploying $TAG (prerelease=$PRERELEASE)"
else
echo "Not a tagged release"
fi
- name: Install requirements & setup env
if: steps.rel_info.outputs.tag != ''
run: sudo apt install -q -y xz-utils zip
- name: Download artifacts
if: steps.rel_info.outputs.tag != ''
uses: actions/download-artifact@v1
with:
name: "nwn2-tools-${{ matrix.arch }}-${{ matrix.platform }}"
- name: Package artifacts
if: steps.rel_info.outputs.tag != ''
id: create_pkg
run: |
BASENAME="nwn2-tools-$(echo "${{ matrix.platform }}" | cut -d '-' -f 1)-${{ matrix.arch }}"
cd "nwn2-tools-${{ matrix.arch }}-${{ matrix.platform }}"
if [[ "${{ matrix.platform }}" == windows-* ]]; then
PKG="$BASENAME.zip"
zip -9 ../$PKG *
echo "::set-output name=mime_type::application/zip"
else
PKG="$BASENAME.tar.xz"
tar cfJ ../$PKG *
echo "::set-output name=mime_type::application/x-xz"
fi
cd -
echo "::set-output name=file::$PKG"
- name: Get release upload URL
if: steps.rel_info.outputs.tag != ''
id: get_release_url
run: |
RELEASE_JSON=$(
curl -sL --header "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ steps.rel_info.outputs.tag }}"
)
echo "::set-output name=upload_url::$(echo "$RELEASE_JSON" | jq -er .upload_url)"
- name: Upload Release Assets
if: steps.rel_info.outputs.tag != ''
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release_url.outputs.upload_url }}
asset_path: ${{ steps.create_pkg.outputs.file }}
asset_name: ${{ steps.create_pkg.outputs.file }}
asset_content_type: ${{ steps.create_pkg.outputs.mime_type }}