-
Notifications
You must be signed in to change notification settings - Fork 1
307 lines (254 loc) · 9.98 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
name: nwn-lib-d
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
with:
fetch-depth: 0
- name: Dub cache
uses: actions/cache@v2
with:
path: ~/.dub
key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.json') }}
restore-keys: |
${{ runner.os }}-dub-
# Setup
- name: Install requirements
run: |
sudo apt update && 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 "================================"
# Testing
- name: Run unit tests
if: matrix.platform == 'linux-gnu' && matrix.arch == 'x86_64'
run: |
source ~/dlang/activate
dub test --compiler=ldc2 --arch=${{ matrix.arch }}-${{ matrix.platform }} -b unittest-cov
cat source/nwn/ver.d
for MOD in tools/nwn-*; do
cd "$MOD"
dub test --compiler=ldc2 --arch=${{ matrix.arch }}-${{ matrix.platform }} -b unittest-cov
cd -
done
- name: "Upload coverage info"
if: matrix.platform == 'linux-gnu' && matrix.arch == 'x86_64'
run: |
bash <(curl -s https://codecov.io/bash)
# Tooling
- name: Build nwn-lib-d tools
run: |
source ~/dlang/activate
[[ "${{ matrix.platform }}" == windows-* ]] && BIN_SUFFIX=".exe" || BIN_SUFFIX=""
mkdir -p bin/
for MOD in tools/nwn-*; do
cd "$MOD"
dub build --compiler=ldc2 --arch=${{ matrix.arch }}-${{ matrix.platform }} -b release
mv "$(basename "$MOD")$BIN_SUFFIX" ../../bin/
cd -
done
- name: Upload bin artifacts
uses: actions/upload-artifact@v2
with:
name: "nwn-lib-d-tools-${{ matrix.platform }}-${{ matrix.arch }}"
path: bin
# Documentation
- name: "Generate documentation"
if: matrix.platform == 'linux-gnu' && matrix.arch == 'x86_64'
run: |
source ~/dlang/activate
dub build --build=ddox
rm docs/nwn/nwscript/constants/* #
mkdir public/
mv docs docs.json public/
cp .github/index.html public/
tar cfJ documentation.tar.xz public/
- name: Upload documentation artifacts
if: matrix.platform == 'linux-gnu' && matrix.arch == 'x86_64'
uses: actions/upload-artifact@v2
with:
name: "documentation.tar.xz"
path: documentation.tar.xz
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
- uses: actions/checkout@v2
if: steps.rel_info.outputs.tag != ''
with:
fetch-depth: 0
- name: Generate changelog
if: steps.rel_info.outputs.tag != ''
id: changelog
run: |
CHANGELOG=$(.github/workflows/gen-changelog.sh)
echo "$CHANGELOG"
CHANGELOG="${CHANGELOG//'%'/'%25'}"
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
echo "::set-output name=log::$CHANGELOG"
- 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
${{ steps.changelog.log }}
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@v2
with:
name: "nwn-lib-d-tools-${{ matrix.platform }}-${{ matrix.arch }}"
path: "nwn-lib-d-tools"
- name: Package artifacts
if: steps.rel_info.outputs.tag != ''
id: create_pkg
run: |
BASENAME="nwn-lib-d-tools-$(echo "${{ matrix.platform }}" | cut -d '-' -f 1)-${{ matrix.arch }}"
ARTIFACTS="nwn-lib-d-tools"
if [[ "${{ matrix.platform }}" == windows-* ]]; then
PKG="$BASENAME.zip"
zip -9 -r "$PKG" "$ARTIFACTS"
echo "::set-output name=mime_type::application/zip"
else
PKG="$BASENAME.tar.xz"
tar cfJ "$PKG" "$ARTIFACTS"
echo "::set-output name=mime_type::application/x-xz"
fi
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 }}
# GH pages
- name: Download documentation artifact
if: steps.rel_info.outputs.tag != '' && matrix.platform == 'linux-gnu' && matrix.arch == 'x86_64'
uses: actions/download-artifact@v2
with:
name: "documentation.tar.xz"
- name: Extract documentation
if: steps.rel_info.outputs.tag != '' && matrix.platform == 'linux-gnu' && matrix.arch == 'x86_64'
run: |
tar xf documentation.tar.xz
- name: Deploy documentation
if: steps.rel_info.outputs.tag != '' && matrix.platform == 'linux-gnu' && matrix.arch == 'x86_64'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public