Skip to content

Commit 1cfe5ef

Browse files
authored
Update GitHub CI Workflows (#805)
* Add devcontainer. * Remove docker test setup. Add global.json. * Update github CI workflows. * Use correct file name. * Use release build for anvil tests. * Add safe directory.
1 parent b60e67e commit 1cfe5ef

File tree

12 files changed

+112
-211
lines changed

12 files changed

+112
-211
lines changed

.devcontainer/devcontainer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "nwn.anvil",
3+
"build": {
4+
"dockerfile": "../dockerfile",
5+
"context": "../"
6+
},
7+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspaces/NWN.Anvil,type=bind",
8+
"workspaceFolder": "/workspaces/NWN.Anvil",
9+
"mounts": [
10+
"source=${localWorkspaceFolder}/test_results,target=/nwn/home/anvil/PluginData/NWN.Anvil.TestRunner,type=bind"
11+
],
12+
"features": {
13+
"ghcr.io/devcontainers/features/dotnet:2": {
14+
"version": "8.0"
15+
},
16+
"ghcr.io/rocker-org/devcontainer-features/apt-packages:1": {
17+
"packages": "curl,unzip,procps,git"
18+
}
19+
},
20+
"appPort": ["5121:5121/udp"],
21+
"containerEnv": {
22+
"NWNX_DOTNET_ASSEMBLY": "/workspaces/NWN.Anvil/NWN.Anvil/bin/Debug/net8.0/NWN.Anvil",
23+
"ANVIL_ADD_PLUGIN_PATHS": "/workspaces/NWN.Anvil/NWN.Anvil.TestRunner/bin/Debug:/workspaces/NWN.Anvil/NWN.Anvil.Tests/bin/Debug"
24+
}
25+
}

.env

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/ci.yml

Lines changed: 63 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -22,86 +22,55 @@ on:
2222

2323
jobs:
2424
compile:
25-
runs-on: ubuntu-20.04
25+
runs-on: ubuntu-latest
2626
if: "!contains(github.event.head_commit.message, 'skip ci')"
2727
permissions:
2828
security-events: write
2929
steps:
3030
- name: Checkout
31-
uses: actions/checkout@v2
31+
uses: actions/checkout@v4
3232
with:
3333
submodules: recursive
3434

35-
- name: Check Line Endings
36-
uses: erclu/check-crlf@v1
35+
- name: Setup .NET
36+
uses: actions/setup-dotnet@v4
3737
with:
38-
path: NWN.Anvil
39-
40-
- name: Setup .NET Core
41-
uses: actions/setup-dotnet@v1.9.0
42-
with:
43-
dotnet-version: '8.0.x'
38+
global-json-file: global.json
4439

4540
- name: Build
4641
run: dotnet build --configuration Debug
4742

48-
- name: Prepare Outputs
49-
id: vars
50-
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
51-
52-
- name: Code Analysis Cache
53-
uses: actions/cache@v2
54-
with:
55-
path: ~/.local/share/JetBrains
56-
key: analysis-cache-${{ steps.vars.outputs.sha_short }}
57-
restore-keys: |
58-
analysis-cache
59-
6043
- name: Code Analysis
61-
uses: JetBrains/ReSharper-InspectCode@v0.3
44+
uses: JetBrains/ReSharper-InspectCode@v0.8
6245
with:
6346
solution: ./NWN.Anvil.sln
64-
tool-version: 2024.1.0
47+
tool-version: 2024.3.0
6548

6649
test:
67-
runs-on: ubuntu-20.04
50+
runs-on: ubuntu-latest
6851
if: "!contains(github.event.head_commit.message, 'skip ci')"
6952
steps:
7053
- name: Checkout
71-
uses: actions/checkout@v2
54+
uses: actions/checkout@v4
7255
with:
7356
submodules: recursive
7457

75-
- name: Setup .NET Core
76-
uses: actions/setup-dotnet@v1.9.0
77-
with:
78-
dotnet-version: '8.0.x'
79-
80-
- name: Build
81-
run: dotnet build --configuration Release
82-
83-
- name: Load Environment Variables
84-
id: env_vars
85-
uses: falti/dotenv-action@v0.2.7
86-
87-
- name: Run Tests
58+
- name: Create Output Directories
8859
run: |
89-
docker compose --project-directory . -f NWN.Anvil.Tests/bin/Release/docker-compose.yml build --build-arg NWNX_VERSION=${{ steps.env_vars.outputs.nwnx_version }} --build-arg BINARY_PATH=NWN.Anvil/bin/Release/net8.0
90-
docker compose --project-directory . -f NWN.Anvil.Tests/bin/Release/docker-compose.yml up
91-
92-
- name: Install NUnit
93-
run: nuget install NUnit.Console -Version 3.12.0
94-
95-
- name: Fetch transform code
96-
run: wget https://raw.githubusercontent.com/nunit/nunit-transforms/master/nunit3-junit/nunit3-junit.xslt
97-
shell: bash
60+
mkdir -p test_results
9861
99-
- name: Transform NUnit3 to JUnit
100-
run: |
101-
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform;
102-
$xslt.Load("nunit3-junit.xslt");
103-
$xslt.Transform("NWN.Anvil.Tests/bin/Release/results/NWN.Anvil.Tests/TestResult.xml", "TestResult.junit.xml");
104-
shell: pwsh
62+
- name: Build and Run Tests
63+
uses: devcontainers/ci@v0.3
64+
with:
65+
push: never
66+
env: |
67+
NWNX_DOTNET_ASSEMBLY=/workspaces/NWN.Anvil/NWN.Anvil/bin/Release/net8.0/NWN.Anvil
68+
ANVIL_ADD_PLUGIN_PATHS=/workspaces/NWN.Anvil/NWN.Anvil.TestRunner/bin/Release:/workspaces/NWN.Anvil/NWN.Anvil.Tests/bin/Release
69+
runCmd: |
70+
git config --global --add safe.directory /workspaces/NWN.Anvil
71+
dotnet build --configuration Release
72+
cd /nwn/data/bin/linux-amd64
73+
/nwn/run-server.sh
10574
10675
- name: Upload Event File
10776
uses: actions/upload-artifact@v4
@@ -115,29 +84,29 @@ jobs:
11584
if: always()
11685
with:
11786
name: Test Results
118-
path: TestResult.junit.xml
87+
path: test_results/NWN.Anvil.Tests/*.xml
11988

12089
build:
121-
runs-on: ubuntu-20.04
90+
runs-on: ubuntu-latest
12291
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
12392
needs: [compile, test]
12493
outputs:
125-
version: ${{ steps.vars.outputs.version }}
126-
tag: ${{ steps.vars.outputs.tag }}
127-
sha_short: ${{ steps.vars.outputs.sha_short }}
128-
image_repository: ${{ steps.vars.outputs.image_repository }}
129-
created: ${{ steps.build.outputs.created }}
94+
version: ${{ steps.vars.outputs.VERSION }}
95+
tag: ${{ steps.vars.outputs.TAG }}
96+
sha_short: ${{ steps.vars.outputs.SHA_SHORT }}
97+
image_repository: ${{ steps.vars.outputs.IMAGE_REPOSITORY }}
98+
created: ${{ steps.build.outputs.CREATED }}
13099
steps:
131100
- name: Checkout
132-
uses: actions/checkout@v2
101+
uses: actions/checkout@v4
133102
with:
134103
fetch-depth: 0
135104
submodules: recursive
136105

137-
- name: Setup .NET Core
138-
uses: actions/setup-dotnet@v1.9.0
106+
- name: Setup .NET
107+
uses: actions/setup-dotnet@v4
139108
with:
140-
dotnet-version: '8.0.x'
109+
global-json-file: global.json
141110

142111
- name: Tag Commit
143112
if: github.event.inputs.tag != ''
@@ -147,24 +116,24 @@ jobs:
147116
id: vars
148117
run: |
149118
if [[ "${{github.base_ref}}" == "main" || "${{github.ref}}" == "refs/heads/main" ]]; then
150-
echo "::set-output name=tag::$(git describe --tags)"
151-
echo "::set-output name=version::$(git describe --tags | sed 's/^v//')"
119+
echo "TAG=$(git describe --tags)" >> "$GITHUB_OUTPUT"
120+
echo "VERSION=$(git describe --tags | sed 's/^v//')" >> "$GITHUB_OUTPUT"
152121
else
153122
DESCRIBE=`git describe --tags --long`
154-
VERSION=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[1]}'`
123+
BASE_VERSION=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[1]}'`
155124
META=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[2]}'`
156125
BUILD=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[3]}'`
157126
COMMIT=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[4]}'`
158-
echo "::set-output name=version::$(echo ${VERSION}-${META}.${BUILD}.r${COMMIT:1} | sed 's/^v//')"
127+
echo "VERSION=$(echo ${BASE_VERSION}-${META}.${BUILD}.r${COMMIT:1} | sed 's/^v//')" >> "$GITHUB_OUTPUT"
159128
fi
160-
echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
161-
echo "::set-output name=image_repository::$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')"
129+
echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
130+
echo "IMAGE_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
162131
163132
- name: Build Release Binaries
164133
id: build
165134
run: |
166-
dotnet build --configuration Release -p:Version=${{ steps.vars.outputs.version }}
167-
echo "::set-output name=created::$(echo date -u +'%Y-%m-%dT%H:%M:%SZ')"
135+
dotnet build --configuration Release -p:Version=${{ steps.vars.outputs.VERSION }}
136+
echo "CREATED=$(echo date -u +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_OUTPUT"
168137
169138
- name: Upload NuGet Artifacts
170139
uses: actions/upload-artifact@v4
@@ -198,10 +167,15 @@ jobs:
198167
if-no-files-found: error
199168

200169
release:
201-
runs-on: ubuntu-20.04
170+
runs-on: ubuntu-latest
202171
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/main'
203172
needs: build
173+
permissions:
174+
contents: write
204175
steps:
176+
- name: Checkout
177+
uses: actions/checkout@v4
178+
205179
- name: Download Release Artifacts
206180
uses: actions/download-artifact@v4
207181
with:
@@ -212,37 +186,25 @@ jobs:
212186
run: zip -r ../NWN.Anvil.zip ./*
213187
working-directory: binaries
214188

215-
- name: Create Release
216-
id: create_release
217-
uses: actions/create-release@v1
218-
env:
219-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
220-
with:
221-
release_name: Release ${{ needs.build.outputs.version }}
222-
draft: false
223-
prerelease: false
224-
tag_name: ${{ needs.build.outputs.tag }}
225-
226189
- name: Upload Release Binaries
227-
id: upload-release-asset
228-
uses: actions/upload-release-asset@v1
229190
env:
230191
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
231-
with:
232-
upload_url: ${{ steps.create_release.outputs.upload_url }}
233-
asset_path: ./NWN.Anvil.zip
234-
asset_name: NWN.Anvil.zip
235-
asset_content_type: application/zip
192+
run: |
193+
gh release create ${{ needs.build.outputs.tag }} --title "Release ${{ needs.build.outputs.version }}" --generate-notes
194+
gh release upload ${{ needs.build.outputs.tag }} NWN.Anvil.zip
236195
237196
nuget:
238-
runs-on: ubuntu-20.04
197+
runs-on: ubuntu-latest
239198
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
240199
needs: build
241200
steps:
242-
- name: Setup .NET Core
243-
uses: actions/setup-dotnet@v1.9.0
201+
- name: Checkout
202+
uses: actions/checkout@v4
203+
204+
- name: Setup .NET
205+
uses: actions/setup-dotnet@v4
244206
with:
245-
dotnet-version: '8.0.x'
207+
global-json-file: global.json
246208

247209
- name: Download Release Artifacts
248210
uses: actions/download-artifact@v4
@@ -257,12 +219,12 @@ jobs:
257219
run: dotnet nuget push 'binaries/**/*.nupkg' --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/nwn-dotnet/index.json
258220

259221
docker:
260-
runs-on: ubuntu-20.04
222+
runs-on: ubuntu-latest
261223
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
262224
needs: build
263225
steps:
264226
- name: Checkout
265-
uses: actions/checkout@v2
227+
uses: actions/checkout@v4
266228
with:
267229
submodules: recursive
268230

@@ -273,31 +235,26 @@ jobs:
273235
path: binaries
274236

275237
- name: Login to DockerHub
276-
uses: docker/login-action@v1
238+
uses: docker/login-action@v3
277239
with:
278240
username: ${{ secrets.DOCKER_HUB_USERNAME }}
279241
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
280242

281243
- name: Login to GitHub Container Registry
282-
uses: docker/login-action@v1
244+
uses: docker/login-action@v3
283245
with:
284246
registry: ghcr.io
285247
username: ${{ github.actor }}
286248
password: ${{ secrets.GITHUB_TOKEN }}
287249

288-
- name: Load Environment Variables
289-
id: env_vars
290-
uses: falti/dotenv-action@v0.2.7
291-
292250
- name: Build and push
293251
id: docker_build
294-
uses: docker/build-push-action@v2
252+
uses: docker/build-push-action@v6
295253
with:
296254
context: ./
297255
file: ./dockerfile
298256
push: true
299257
build-args: |
300-
NWNX_VERSION=${{ steps.env_vars.outputs.nwnx_version }}
301258
BINARY_PATH=/binaries/net8.0
302259
labels: |
303260
org.opencontainers.image.title=Anvil

.github/workflows/docs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- name: Checkout
10-
uses: actions/checkout@v2
10+
uses: actions/checkout@v4
1111

1212
- name: Doxygen Action
13-
uses: mattnotmitt/doxygen-action@v1.3.1
13+
uses: mattnotmitt/doxygen-action@v1
1414
with:
1515
doxyfile-path: "./docs/Doxyfile"
1616
working-directory: "."
1717

1818
- name: Deploy
19-
uses: peaceiris/actions-gh-pages@v3
19+
uses: peaceiris/actions-gh-pages@v4
2020
with:
2121
github_token: ${{ secrets.GITHUB_TOKEN }}
2222
publish_dir: ./docs/html

.github/workflows/test-report.yml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,32 @@ on:
55
workflows: ['Continuous Integration']
66
types:
77
- completed
8+
permissions: {}
89

910
jobs:
1011
test-results:
1112
name: Test Results
12-
runs-on: ubuntu-20.04
13+
runs-on: ubuntu-latest
1314
if: github.event.workflow_run.conclusion != 'skipped'
15+
permissions:
16+
checks: write
17+
pull-requests: write
18+
actions: read
1419

1520
steps:
1621
- name: Download and Extract Artifacts
17-
env:
18-
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
19-
run: |
20-
mkdir -p artifacts && cd artifacts
21-
22-
artifacts_url=${{ github.event.workflow_run.artifacts_url }}
23-
24-
gh api "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact
25-
do
26-
IFS=$'\t' read name url <<< "$artifact"
27-
gh api $url > "$name.zip"
28-
unzip -d "$name" "$name.zip"
29-
done
22+
uses: dawidd6/action-download-artifact@e7466d1a7587ed14867642c2ca74b5bcc1e19a2d
23+
with:
24+
run_id: ${{ github.event.workflow_run.id }}
25+
path: artifacts
3026

3127
- name: Publish Test Results
32-
uses: EnricoMi/publish-unit-test-result-action@v1.25
28+
uses: EnricoMi/publish-unit-test-result-action@v2.18.0
3329
with:
3430
check_name: "Test Results"
3531
comment_title: "Test Results"
3632
report_individual_runs: true
3733
commit: ${{ github.event.workflow_run.head_sha }}
3834
event_file: artifacts/Event File/event.json
3935
event_name: ${{ github.event.workflow_run.event }}
40-
files: "artifacts/Test Results/**/*.xml"
36+
files: "artifacts/Test Results/**/*.xml"

0 commit comments

Comments
 (0)