Update GitHub CI Workflows #2171
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |