-
Notifications
You must be signed in to change notification settings - Fork 10
275 lines (242 loc) · 9.04 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
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-latest
if: "!contains(github.event.head_commit.message, 'skip ci')"
permissions:
security-events: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Build
run: dotnet build --configuration Debug
- name: Code Analysis
uses: JetBrains/ReSharper-InspectCode@v0.8
with:
solution: ./NWN.Anvil.sln
tool-version: 2024.3.0
test:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'skip ci')"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Create Output Directories
run: |
mkdir -p test_results
- name: Build and Run Tests
uses: devcontainers/ci@v0.3
with:
push: never
env: |
ANVIL_ADD_PLUGIN_PATHS=/workspaces/NWN.Anvil/NWN.Anvil.TestRunner/bin/Release:/workspaces/NWN.Anvil/NWN.Anvil.Tests/bin/Release
runCmd: |
dotnet build --configuration Release
cd /nwn/data/bin/linux-amd64
/nwn/run-server.sh
- name: Upload Event File
uses: actions/upload-artifact@v4
if: always()
with:
name: Event File
path: ${{ github.event_path }}
- name: Upload Results
uses: actions/upload-artifact@v4
if: always()
with:
name: Test Results
path: test_results/NWN.Anvil.Tests/*.xml
build:
runs-on: ubuntu-latest
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@v4
with:
fetch-depth: 0
submodules: recursive
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- 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 "TAG=$(git describe --tags)" >> "$GITHUB_OUTPUT"
echo "VERSION=$(git describe --tags | sed 's/^v//')" >> "$GITHUB_OUTPUT"
else
DESCRIBE=`git describe --tags --long`
BASE_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 "VERSION=$(echo ${BASE_VERSION}-${META}.${BUILD}.r${COMMIT:1} | sed 's/^v//')" >> "$GITHUB_OUTPUT"
fi
echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
echo "IMAGE_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
- name: Build Release Binaries
id: build
run: |
dotnet build --configuration Release -p:Version=${{ steps.vars.outputs.VERSION }}
echo "CREATED=$(echo date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
- name: Upload NuGet Artifacts
uses: actions/upload-artifact@v4
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@v4
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@v4
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-latest
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main'
needs: build
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download Release Artifacts
uses: actions/download-artifact@v4
with:
name: Binaries
path: binaries
- name: Zip Binaries
run: zip -r ../NWN.Anvil.zip ./*
working-directory: binaries
- name: Upload Release Binaries
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create ${{ needs.build.outputs.tag }} --title "Release ${{ needs.build.outputs.version }}" --generate-notes
gh release upload ${{ needs.build.outputs.tag }} NWN.Anvil.zip
nuget:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Download Release Artifacts
uses: actions/download-artifact@v4
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-latest
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
needs: build
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Download Release Artifacts
uses: actions/download-artifact@v4
with:
name: Binaries
path: binaries
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v6
with:
context: ./
file: ./dockerfile
push: true
build-args: |
BINARY_PATH=/binaries/net8.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 }}