-
Notifications
You must be signed in to change notification settings - Fork 9
325 lines (282 loc) · 10.7 KB
/
ci.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
name: Continuous Integration
on:
push:
branches:
- main
- development
paths-ignore:
- '**.md'
- 'docs/**'
pull_request:
branches:
- main
- development
paths-ignore:
- '**.md'
- 'docs/**'
workflow_dispatch:
inputs:
tag:
description: 'Commit Tag'
jobs:
compile:
runs-on: ubuntu-20.04
if: "!contains(github.event.head_commit.message, 'skip ci')"
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Check Line Endings
uses: erclu/check-crlf@v1
with:
path: NWN.Anvil
- name: Setup .NET Core
uses: actions/[email protected]
with:
dotnet-version: '7.0.x'
- name: Build
run: dotnet build --configuration Debug
- name: Prepare Outputs
id: vars
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
- name: Code Analysis Cache
uses: actions/cache@v2
with:
path: ~/.local/share/JetBrains
key: analysis-cache-${{ steps.vars.outputs.sha_short }}
restore-keys: |
analysis-cache
- name: Code Analysis
run: dotnet tool install -g JetBrains.ReSharper.GlobalTools && jb inspectcode NWN.Anvil.sln -o=results.xml && cat results.xml
- name: Parse Analysis Results
uses: glassechidna/resharper-action@master
with:
report: results.xml
- name: Analysis Result
run: |
! grep "<Issue TypeId=" results.xml
test:
runs-on: ubuntu-20.04
if: "!contains(github.event.head_commit.message, 'skip ci')"
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Setup .NET Core
uses: actions/[email protected]
with:
dotnet-version: '7.0.x'
- name: Build
run: dotnet build --configuration Release
- name: Load Environment Variables
id: env_vars
uses: falti/[email protected]
- name: Run Tests
run: |
docker-compose build --build-arg NWNX_VERSION=${{ steps.env_vars.outputs.nwnx_version }} --build-arg BINARY_PATH=NWN.Anvil/bin/Release/net7.0
docker-compose up
working-directory: NWN.Anvil.Tests/bin/Release/
- name: Install NUnit
run: nuget install NUnit.Console -Version 3.12.0
- name: Fetch transform code
run: wget https://raw.githubusercontent.com/nunit/nunit-transforms/master/nunit3-junit/nunit3-junit.xslt
shell: bash
- name: Transform NUnit3 to JUnit
run: |
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform;
$xslt.Load("nunit3-junit.xslt");
$xslt.Transform("NWN.Anvil.Tests/bin/Release/results/NWN.Anvil.Tests/TestResult.xml", "TestResult.junit.xml");
shell: pwsh
- name: Upload Event File
uses: actions/upload-artifact@v2
if: always()
with:
name: Event File
path: ${{ github.event_path }}
- name: Upload Results
uses: actions/upload-artifact@v2
if: always()
with:
name: Test Results
path: TestResult.junit.xml
build:
runs-on: ubuntu-20.04
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
needs: [compile, test]
outputs:
version: ${{ steps.vars.outputs.version }}
tag: ${{ steps.vars.outputs.tag }}
sha_short: ${{ steps.vars.outputs.sha_short }}
image_repository: ${{ steps.vars.outputs.image_repository }}
created: ${{ steps.build.outputs.created }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
submodules: recursive
- name: Setup .NET Core
uses: actions/[email protected]
with:
dotnet-version: '7.0.x'
- name: Tag Commit
if: github.event.inputs.tag != ''
run: git tag ${{ github.event.inputs.tag }} && git push origin ${{ github.event.inputs.tag }}
- name: Prepare Outputs
id: vars
run: |
if [[ "${{github.base_ref}}" == "main" || "${{github.ref}}" == "refs/heads/main" ]]; then
echo "::set-output name=tag::$(git describe --tags)"
echo "::set-output name=version::$(git describe --tags | sed 's/^v//')"
else
DESCRIBE=`git describe --tags --long`
VERSION=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[1]}'`
META=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[2]}'`
BUILD=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[3]}'`
COMMIT=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[4]}'`
echo "::set-output name=version::$(echo ${VERSION}-${META}.${BUILD}.r${COMMIT:1} | sed 's/^v//')"
fi
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
echo "::set-output name=image_repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')"
- name: Build Release Binaries
id: build
run: |
dotnet build --configuration Release -p:Version=${{ steps.vars.outputs.version }}
echo "::set-output name=created::$(echo date -u +'%Y-%m-%dT%H:%M:%SZ')"
- name: Upload NuGet Artifacts
uses: actions/upload-artifact@v2
with:
name: NuGet Packages
path: |
NWN.Anvil/bin/Release/*.nupkg
NWN.Anvil/bin/Release/*.snupkg
NWN.Anvil.TestRunner/bin/Release/NWN.Anvil.TestRunner/*.nupkg
NWN.Anvil.TestRunner/bin/Release/NWN.Anvil.TestRunner/*.snupkg
if-no-files-found: error
- name: Upload Build Artifacts (Anvil)
uses: actions/upload-artifact@v2
with:
name: Binaries
path: |
NWN.Anvil/bin/Release/
!NWN.Anvil/bin/Release/*.nupkg
!NWN.Anvil/bin/Release/*.snupkg
if-no-files-found: error
- name: Upload Build Artifacts (Test Runner)
uses: actions/upload-artifact@v2
with:
name: Binaries (Test Runner)
path: |
NWN.Anvil.TestRunner/bin/Release/
!NWN.Anvil.TestRunner/bin/Release/NWN.Anvil.TestRunner/*.nupkg
!NWN.Anvil.TestRunner/bin/Release/NWN.Anvil.TestRunner/*.snupkg
if-no-files-found: error
release:
runs-on: ubuntu-20.04
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main'
needs: build
steps:
- name: Download Release Artifacts
uses: actions/download-artifact@v2
with:
name: Binaries
path: binaries
- name: Zip Binaries
run: zip -r ../NWN.Anvil.zip ./*
working-directory: binaries
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_name: Release ${{ needs.build.outputs.version }}
draft: false
prerelease: false
tag_name: ${{ needs.build.outputs.tag }}
- name: Upload Release Binaries
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./NWN.Anvil.zip
asset_name: NWN.Anvil.zip
asset_content_type: application/zip
nuget:
runs-on: ubuntu-20.04
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
needs: build
steps:
- name: Setup .NET Core
uses: actions/[email protected]
with:
dotnet-version: '7.0.x'
- name: Download Release Artifacts
uses: actions/download-artifact@v2
with:
name: NuGet Packages
path: binaries
- name: NuGet Publish
run: dotnet nuget push 'binaries/**/*.nupkg' --api-key ${{ secrets.NUGET_KEY }} --source https://api.nuget.org/v3/index.json
- name: GitHub Publish
run: dotnet nuget push 'binaries/**/*.nupkg' --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/nwn-dotnet/index.json
docker:
runs-on: ubuntu-20.04
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
needs: build
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: recursive
- name: Download Release Artifacts
uses: actions/download-artifact@v2
with:
name: Binaries
path: binaries
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Load Environment Variables
id: env_vars
uses: falti/[email protected]
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./
file: ./dockerfile
push: true
build-args: |
NWNX_VERSION=${{ steps.env_vars.outputs.nwnx_version }}
BINARY_PATH=/binaries/net7.0
labels: |
org.opencontainers.image.title=Anvil
org.opencontainers.image.description=Anvil is a C# library that attempts to wrap Neverwinter Script with C# niceties and contexts, instead of a collection of functions. This image contains a NWNX server configured to use Anvil.
org.opencontainers.image.author=NWN DotNET
org.opencontainers.image.vendor=NWN DotNET
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.created=${{ needs.build.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.documentation=https://nwn-dotnet.github.io/Anvil
tags: |
nwndotnet/anvil:latest
nwndotnet/anvil:${{ needs.build.outputs.version }}
nwndotnet/anvil:${{ needs.build.outputs.sha_short }}
ghcr.io/${{ needs.build.outputs.image_repository }}:latest
ghcr.io/${{ needs.build.outputs.image_repository }}:${{ needs.build.outputs.version }}
ghcr.io/${{ needs.build.outputs.image_repository }}:${{ needs.build.outputs.sha_short }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}