build: preparing project layout

This commit is contained in:
D. Moonfire 2022-09-05 23:03:00 -05:00
parent 87cbba225e
commit 3943eb002c
10 changed files with 65 additions and 82 deletions

View File

@ -15,4 +15,4 @@
]
}
}
}
}

9
.gitignore vendored
View File

@ -11,8 +11,15 @@ obj/
.idea/
_ReSharper.Caches/
node_modules/
# NixOS
.direnv/
# Tests and Coverage
coverage
TestResults/
tests/artifacts/
.lefthook*
# Lefthook
.lefthook-local/
lefthook-local.yml

View File

@ -1,46 +0,0 @@
include:
- template: Security/SAST.gitlab-ci.yml
stages:
- build
- test
- release
default:
image: registry.gitlab.com/dmoonfire/nix-flake-docker:latest
build:
stage: build
script:
- nix develop --command scripts/build.sh
rules:
- if: $CI_COMMIT_BRANCH
test:
stage: test
script:
- nix develop --command scripts/test.sh
artifacts:
when: always
paths:
- ./**/*test-result.xml
- ./coverage/Cobertura.xml
- ./coverage/Summary.*
- ./**/*.nupkg
reports:
coverage_report:
coverage_format: cobertura
path: ./coverage/Cobertura.xml
junit:
- ./**/*test-result.xml
publish:
stage: release
before_script:
# Set it up so we can push the tag
- project_url=$(echo $CI_PROJECT_URL | sed 's/https:\/\///')
- git remote set-url origin https://oauth2:$GITLAB_TOKEN@$project_url
script:
- nix develop --command scripts/release.sh
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

16
NuGet.Config Normal file
View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="mfgames.com" value="https://src.mfgames.com/api/packages/mfgames-cil/nuget/index.json" protocolVersion="3" />
</packageSources>
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
<packageSource key="mfgames.com">
<package pattern="MfGames.*" />
</packageSource>
</packageSourceMapping>
</configuration>

View File

@ -3,4 +3,5 @@
cd $(dirname $0)/..
./scripts/setup.sh || exit 1
echo "$(basename $0): building project"
dotnet build

View File

@ -1,14 +1,4 @@
#!/usr/bin/env sh
# Normalize our environment.
cd $(dirname $0)/..
./scripts/setup.sh || exit 1
# Format the .NET code
dotnet format || exit 1
# Format using Prettier.
prettier . --write --loglevel warn
# Format the Flake.
nixfmt flake.nix
lefthook run pre-commit

View File

@ -4,43 +4,48 @@ cd $(dirname $0)/..
./scripts/setup.sh || exit 1
# Verify the input.
if [ "x$NUGET_TOKEN" = "x" ]
if [ "x$GITEA_TOKEN" = "x" ]
then
echo "the environment variable NUGET_TOKEN is not defined"
exit 1
fi
if [ "x$NUGET_PUSH_URL" = "x" ]
then
echo "the environment variable NUGET_PUSH_URL is not defined"
echo "the environment variable GITEA_TOKEN is not defined"
exit 1
fi
# Clean up everything from the previous runs.
echo "$(basename $0): cleaning project"
dotnet clean
# Version the file based on the Git repository.
echo "$(basename $0): setting project version"
(cd src && dotnet dotnet-gitversion /updateprojectfiles)
SEMVER="v$(dotnet gitversion /output json | jq -r .SemVer)"
if [ "x$SEMVER" = "x" ]
then
echo "cannot figure out the semantic version"
echo "$(basename $0): cannot figure out the semantic version"
exit 1
fi
# Build to pick up the new version.
dotnet build
echo "$(basename $0): building project $SEMVER"
dotnet build || exit 1
# Create and publish the NuGet packages.
dotnet pack --include-symbols --include-source
dotnet nuget push src/*/bin/Debug/*.nupkg --api-key $NUGET_TOKEN --source $NUGET_PUSH_URL
echo "$(basename $0): creating NuGet packages"
dotnet pack -p:IncludeSymbols=true -p:SymbolPackageFormat=snupkg || exit 1
echo "$(basename $0): publishing NuGet package"
dotnet nuget remove source mfgames.com >& /dev/null
dotnet nuget add source --name mfgames.com --username dmoonfire --password $GITEA_TOKEN https://src.mfgames.com/api/packages/mfgames-cil/nuget/index.json --store-password-in-clear-text || exit 1
dotnet nuget push --skip-duplicate --source mfgames.com src/*/bin/Debug/*.nupkg || exit 1
# Tag and push, but only if we don't have a tag.
if ! git tag | grep $SEMVER >& /dev/null
then
echo "tagging and pushing"
echo "$(basename $0): tagging and pushing"
git remote add publish https://dmoonfire:$GITEA_TOKEN@src.mfgames.com/mfgames-cil/$(basename $(git config --get remote.origin.url))
git tag $SEMVER
git push origin $SEMVER
git push publish $SEMVER || exit 1
git remote remove publish
else
echo "not tagging, already exists"
echo "$(basename $0): not tagging, already exists"
fi

View File

@ -14,13 +14,15 @@ do
done
# Make sure we have lefthook is installed.
lefthook install
if [ ! -f .git/hooks/pre-commit ]
then
echo "$(basename $0): installing lefthook"
lefthook install
fi
# Make sure our tools are installed.
echo "$(basename $0): install .NET tools"
dotnet tool restore
# Make sure everything is the right version.
dotnet gitversion /updateprojectfiles
# Everything is good.
exit 0

View File

@ -1,8 +1,12 @@
#!/usr/bin/env sh
cd $(dirname $0)/..
./scripts/setup.sh || exit 1
dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=../artifacts/{assembly}-test-result.xml;MethodFormat=Default;FailureBodyFormat=Verbose" --collect:"XPlat Code Coverage"
dotnet tool run reportgenerator -reports:tests/*/TestResults/*/coverage.cobertura.xml -targetdir:./coverage "-reporttypes:Cobertura;TextSummary"
grep "Line coverage" coverage/Summary.txt
if [ -f ./tests/*/*.csproj ]
then
./scripts/setup.sh || exit 1
dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=../artifacts/{assembly}-test-result.xml;MethodFormat=Default;FailureBodyFormat=Verbose" --collect:"XPlat Code Coverage"
dotnet tool run reportgenerator -reports:tests/*/TestResults/*/coverage.cobertura.xml -targetdir:./coverage "-reporttypes:Cobertura;TextSummary"
grep "Line coverage" coverage/Summary.txt
fi

4
scripts/update-template.sh Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env sh
cd $(dirname $0)/..
git pull template main --no-rebase