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

9
.gitignore vendored
View file

@ -11,8 +11,15 @@ obj/
.idea/ .idea/
_ReSharper.Caches/ _ReSharper.Caches/
node_modules/ node_modules/
# NixOS
.direnv/ .direnv/
# Tests and Coverage
coverage coverage
TestResults/ TestResults/
tests/artifacts/ 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)/.. cd $(dirname $0)/..
./scripts/setup.sh || exit 1 ./scripts/setup.sh || exit 1
echo "$(basename $0): building project"
dotnet build dotnet build

View file

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

View file

@ -4,43 +4,48 @@ cd $(dirname $0)/..
./scripts/setup.sh || exit 1 ./scripts/setup.sh || exit 1
# Verify the input. # Verify the input.
if [ "x$NUGET_TOKEN" = "x" ] if [ "x$GITEA_TOKEN" = "x" ]
then then
echo "the environment variable NUGET_TOKEN is not defined" echo "the environment variable GITEA_TOKEN is not defined"
exit 1
fi
if [ "x$NUGET_PUSH_URL" = "x" ]
then
echo "the environment variable NUGET_PUSH_URL is not defined"
exit 1 exit 1
fi fi
# Clean up everything from the previous runs. # Clean up everything from the previous runs.
echo "$(basename $0): cleaning project"
dotnet clean dotnet clean
# Version the file based on the Git repository. # 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)" SEMVER="v$(dotnet gitversion /output json | jq -r .SemVer)"
if [ "x$SEMVER" = "x" ] if [ "x$SEMVER" = "x" ]
then then
echo "cannot figure out the semantic version" echo "$(basename $0): cannot figure out the semantic version"
exit 1 exit 1
fi fi
# Build to pick up the new version. # 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. # Create and publish the NuGet packages.
dotnet pack --include-symbols --include-source echo "$(basename $0): creating NuGet packages"
dotnet nuget push src/*/bin/Debug/*.nupkg --api-key $NUGET_TOKEN --source $NUGET_PUSH_URL 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. # Tag and push, but only if we don't have a tag.
if ! git tag | grep $SEMVER >& /dev/null if ! git tag | grep $SEMVER >& /dev/null
then 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 tag $SEMVER
git push origin $SEMVER git push publish $SEMVER || exit 1
git remote remove publish
else else
echo "not tagging, already exists" echo "$(basename $0): not tagging, already exists"
fi fi

View file

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

View file

@ -1,8 +1,12 @@
#!/usr/bin/env sh #!/usr/bin/env sh
cd $(dirname $0)/.. cd $(dirname $0)/..
if [ -f ./tests/*/*.csproj ]
then
./scripts/setup.sh || exit 1 ./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 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" dotnet tool run reportgenerator -reports:tests/*/TestResults/*/coverage.cobertura.xml -targetdir:./coverage "-reporttypes:Cobertura;TextSummary"
grep "Line coverage" coverage/Summary.txt 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