From 3943eb002cfee6a18742dbe7d072f77bbb319d94 Mon Sep 17 00:00:00 2001 From: "D. Moonfire" Date: Mon, 5 Sep 2022 23:03:00 -0500 Subject: [PATCH] build: preparing project layout --- .config/dotnet-tools.json | 2 +- .gitignore | 9 +++++++- .gitlab-ci.yml | 46 -------------------------------------- NuGet.Config | 16 +++++++++++++ scripts/build.sh | 1 + scripts/format.sh | 12 +--------- scripts/release.sh | 35 ++++++++++++++++------------- scripts/setup.sh | 10 +++++---- scripts/test.sh | 12 ++++++---- scripts/update-template.sh | 4 ++++ 10 files changed, 65 insertions(+), 82 deletions(-) delete mode 100644 .gitlab-ci.yml create mode 100644 NuGet.Config create mode 100755 scripts/update-template.sh diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 2f38f36..7720a5a 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -15,4 +15,4 @@ ] } } -} +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index f7ff559..53987a3 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index e4623ab..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -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 diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 0000000..ff47af7 --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/scripts/build.sh b/scripts/build.sh index 0cda922..66f32c5 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -3,4 +3,5 @@ cd $(dirname $0)/.. ./scripts/setup.sh || exit 1 +echo "$(basename $0): building project" dotnet build diff --git a/scripts/format.sh b/scripts/format.sh index fd015be..7b31af0 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -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 diff --git a/scripts/release.sh b/scripts/release.sh index 8e51251..94ed900 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -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 diff --git a/scripts/setup.sh b/scripts/setup.sh index 83081f9..3ee77ae 100755 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -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 diff --git a/scripts/test.sh b/scripts/test.sh index bb106ee..7587fb1 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -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 diff --git a/scripts/update-template.sh b/scripts/update-template.sh new file mode 100755 index 0000000..2d80710 --- /dev/null +++ b/scripts/update-template.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh + +cd $(dirname $0)/.. +git pull template main --no-rebase