Use official Jetbrains InspectCode Github Action (#762) #2037
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-20.04 | |
if: "!contains(github.event.head_commit.message, 'skip ci')" | |
permissions: | |
security-events: write | |
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 | |
uses: JetBrains/[email protected] | |
with: | |
solution: ./NWN.Anvil.sln | |
tool-version: 2024.1.0 | |
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 }} |